aboutsummaryrefslogtreecommitdiff
path: root/embassy-net-esp-hosted/src
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2025-12-02 13:54:42 +0100
committerUlf Lilleengen <[email protected]>2025-12-02 13:54:42 +0100
commit220e8b5973efe0562f5d96cdd92b87badd313f00 (patch)
treea9be9a66096c01efad268c9e4a6eede1c938a33b /embassy-net-esp-hosted/src
parent4e69d44d184f4920f2f167a6ba9411cea0759dab (diff)
chore: unify ota and init states
Diffstat (limited to 'embassy-net-esp-hosted/src')
-rw-r--r--embassy-net-esp-hosted/src/control.rs1
-rw-r--r--embassy-net-esp-hosted/src/ioctl.rs29
-rw-r--r--embassy-net-esp-hosted/src/lib.rs7
3 files changed, 19 insertions, 18 deletions
diff --git a/embassy-net-esp-hosted/src/control.rs b/embassy-net-esp-hosted/src/control.rs
index 227db0d09..eb79593f6 100644
--- a/embassy-net-esp-hosted/src/control.rs
+++ b/embassy-net-esp-hosted/src/control.rs
@@ -177,7 +177,6 @@ impl<'a> Control<'a> {
177 pub async fn ota_end(&mut self) -> Result<(), Error> { 177 pub async fn ota_end(&mut self) -> Result<(), Error> {
178 let req = proto::CtrlMsg_Req_OTAEnd {}; 178 let req = proto::CtrlMsg_Req_OTAEnd {};
179 ioctl!(self, ReqOtaEnd, RespOtaEnd, req, resp); 179 ioctl!(self, ReqOtaEnd, RespOtaEnd, req, resp);
180 // Ensures that run loop awaits reset
181 self.shared.ota_done(); 180 self.shared.ota_done();
182 // Wait for re-init 181 // Wait for re-init
183 self.init().await?; 182 self.init().await?;
diff --git a/embassy-net-esp-hosted/src/ioctl.rs b/embassy-net-esp-hosted/src/ioctl.rs
index 8b9d582be..de0f867e8 100644
--- a/embassy-net-esp-hosted/src/ioctl.rs
+++ b/embassy-net-esp-hosted/src/ioctl.rs
@@ -23,18 +23,23 @@ pub struct Shared(RefCell<SharedInner>);
23 23
24struct SharedInner { 24struct SharedInner {
25 ioctl: IoctlState, 25 ioctl: IoctlState,
26 is_init: bool, 26 state: ControlState,
27 is_ota: bool,
28 control_waker: WakerRegistration, 27 control_waker: WakerRegistration,
29 runner_waker: WakerRegistration, 28 runner_waker: WakerRegistration,
30} 29}
31 30
31#[derive(Clone, Copy)]
32pub(crate) enum ControlState {
33 Init,
34 Reboot,
35 Ready,
36}
37
32impl Shared { 38impl Shared {
33 pub fn new() -> Self { 39 pub fn new() -> Self {
34 Self(RefCell::new(SharedInner { 40 Self(RefCell::new(SharedInner {
35 ioctl: IoctlState::Done { resp_len: 0 }, 41 ioctl: IoctlState::Done { resp_len: 0 },
36 is_init: false, 42 state: ControlState::Init,
37 is_ota: false,
38 control_waker: WakerRegistration::new(), 43 control_waker: WakerRegistration::new(),
39 runner_waker: WakerRegistration::new(), 44 runner_waker: WakerRegistration::new(),
40 })) 45 }))
@@ -104,29 +109,27 @@ impl Shared {
104 // ota 109 // ota
105 pub fn ota_done(&self) { 110 pub fn ota_done(&self) {
106 let mut this = self.0.borrow_mut(); 111 let mut this = self.0.borrow_mut();
107 this.is_ota = true; 112 this.state = ControlState::Reboot;
108 this.is_init = false;
109 } 113 }
110 114
115 // // // // // // // // // // // // // // // // // // // //
116 //
111 // check if ota is in progress 117 // check if ota is in progress
112 pub fn is_ota(&self) -> bool { 118 pub(crate) fn state(&self) -> ControlState {
113 let this = self.0.borrow(); 119 let this = self.0.borrow();
114 this.is_ota 120 this.state
115 } 121 }
116 122
117 // // // // // // // // // // // // // // // // // // // //
118
119 pub fn init_done(&self) { 123 pub fn init_done(&self) {
120 let mut this = self.0.borrow_mut(); 124 let mut this = self.0.borrow_mut();
121 this.is_init = true; 125 this.state = ControlState::Ready;
122 this.is_ota = false;
123 this.control_waker.wake(); 126 this.control_waker.wake();
124 } 127 }
125 128
126 pub fn init_wait(&self) -> impl Future<Output = ()> + '_ { 129 pub fn init_wait(&self) -> impl Future<Output = ()> + '_ {
127 poll_fn(|cx| { 130 poll_fn(|cx| {
128 let mut this = self.0.borrow_mut(); 131 let mut this = self.0.borrow_mut();
129 if this.is_init { 132 if let ControlState::Ready = this.state {
130 Poll::Ready(()) 133 Poll::Ready(())
131 } else { 134 } else {
132 this.control_waker.register(cx.waker()); 135 this.control_waker.register(cx.waker());
diff --git a/embassy-net-esp-hosted/src/lib.rs b/embassy-net-esp-hosted/src/lib.rs
index f0cf04d04..2c7377281 100644
--- a/embassy-net-esp-hosted/src/lib.rs
+++ b/embassy-net-esp-hosted/src/lib.rs
@@ -234,13 +234,12 @@ where
234 tx_buf[..PayloadHeader::SIZE].fill(0); 234 tx_buf[..PayloadHeader::SIZE].fill(0);
235 } 235 }
236 Either4::Fourth(()) => { 236 Either4::Fourth(()) => {
237 // Extend the deadline if OTA 237 // Extend the deadline if initializing
238 if self.shared.is_ota() { 238 if let ioctl::ControlState::Reboot = self.shared.state() {
239 self.heartbeat_deadline = Instant::now() + HEARTBEAT_MAX_GAP; 239 self.heartbeat_deadline = Instant::now() + HEARTBEAT_MAX_GAP;
240 continue; 240 continue;
241 } else {
242 panic!("heartbeat from esp32 stopped")
243 } 241 }
242 panic!("heartbeat from esp32 stopped")
244 } 243 }
245 } 244 }
246 245