diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-06-21 19:05:20 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-06-22 21:12:10 +0200 |
| commit | 764b43e82c7b61c21621c1fd9f5fd2f6a3dc419c (patch) | |
| tree | 231c49c4b16fceff27f15f954967a75f1c5074e0 /embassy-net-esp-hosted | |
| parent | 082f1ab494587e02d405cad8f186d48943acf16d (diff) | |
esp-hosted: wait for esp firmware init.
Diffstat (limited to 'embassy-net-esp-hosted')
| -rw-r--r-- | embassy-net-esp-hosted/src/control.rs | 3 | ||||
| -rw-r--r-- | embassy-net-esp-hosted/src/ioctl.rs | 23 | ||||
| -rw-r--r-- | embassy-net-esp-hosted/src/lib.rs | 11 |
3 files changed, 37 insertions, 0 deletions
diff --git a/embassy-net-esp-hosted/src/control.rs b/embassy-net-esp-hosted/src/control.rs index c98d0ebf4..a2a65bc31 100644 --- a/embassy-net-esp-hosted/src/control.rs +++ b/embassy-net-esp-hosted/src/control.rs | |||
| @@ -29,6 +29,9 @@ impl<'a> Control<'a> { | |||
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | pub async fn init(&mut self) { | 31 | pub async fn init(&mut self) { |
| 32 | debug!("wait for init event..."); | ||
| 33 | self.shared.init_wait().await; | ||
| 34 | |||
| 32 | debug!("set wifi mode"); | 35 | debug!("set wifi mode"); |
| 33 | self.set_wifi_mode(WifiMode::Sta as _).await; | 36 | self.set_wifi_mode(WifiMode::Sta as _).await; |
| 34 | let mac_addr = self.get_mac_addr().await; | 37 | let mac_addr = self.get_mac_addr().await; |
diff --git a/embassy-net-esp-hosted/src/ioctl.rs b/embassy-net-esp-hosted/src/ioctl.rs index 7cbe80b2a..607b7b627 100644 --- a/embassy-net-esp-hosted/src/ioctl.rs +++ b/embassy-net-esp-hosted/src/ioctl.rs | |||
| @@ -23,6 +23,7 @@ pub struct Shared(RefCell<SharedInner>); | |||
| 23 | 23 | ||
| 24 | struct SharedInner { | 24 | struct SharedInner { |
| 25 | ioctl: IoctlState, | 25 | ioctl: IoctlState, |
| 26 | is_init: bool, | ||
| 26 | control_waker: WakerRegistration, | 27 | control_waker: WakerRegistration, |
| 27 | runner_waker: WakerRegistration, | 28 | runner_waker: WakerRegistration, |
| 28 | } | 29 | } |
| @@ -31,6 +32,7 @@ impl Shared { | |||
| 31 | pub fn new() -> Self { | 32 | pub fn new() -> Self { |
| 32 | Self(RefCell::new(SharedInner { | 33 | Self(RefCell::new(SharedInner { |
| 33 | ioctl: IoctlState::Done { resp_len: 0 }, | 34 | ioctl: IoctlState::Done { resp_len: 0 }, |
| 35 | is_init: false, | ||
| 34 | control_waker: WakerRegistration::new(), | 36 | control_waker: WakerRegistration::new(), |
| 35 | runner_waker: WakerRegistration::new(), | 37 | runner_waker: WakerRegistration::new(), |
| 36 | })) | 38 | })) |
| @@ -97,4 +99,25 @@ impl Shared { | |||
| 97 | warn!("IOCTL Response but no pending Ioctl"); | 99 | warn!("IOCTL Response but no pending Ioctl"); |
| 98 | } | 100 | } |
| 99 | } | 101 | } |
| 102 | |||
| 103 | // // // // // // // // // // // // // // // // // // // // | ||
| 104 | |||
| 105 | pub fn init_done(&self) { | ||
| 106 | let mut this = self.0.borrow_mut(); | ||
| 107 | this.is_init = true; | ||
| 108 | this.control_waker.wake(); | ||
| 109 | } | ||
| 110 | |||
| 111 | pub async fn init_wait(&self) { | ||
| 112 | poll_fn(|cx| { | ||
| 113 | let mut this = self.0.borrow_mut(); | ||
| 114 | if this.is_init { | ||
| 115 | Poll::Ready(()) | ||
| 116 | } else { | ||
| 117 | this.control_waker.register(cx.waker()); | ||
| 118 | Poll::Pending | ||
| 119 | } | ||
| 120 | }) | ||
| 121 | .await | ||
| 122 | } | ||
| 100 | } | 123 | } |
diff --git a/embassy-net-esp-hosted/src/lib.rs b/embassy-net-esp-hosted/src/lib.rs index 700a5221c..ff7bed2b7 100644 --- a/embassy-net-esp-hosted/src/lib.rs +++ b/embassy-net-esp-hosted/src/lib.rs | |||
| @@ -11,6 +11,7 @@ use ioctl::Shared; | |||
| 11 | use proto::CtrlMsg; | 11 | use proto::CtrlMsg; |
| 12 | 12 | ||
| 13 | use crate::ioctl::PendingIoctl; | 13 | use crate::ioctl::PendingIoctl; |
| 14 | use crate::proto::CtrlMsgPayload; | ||
| 14 | 15 | ||
| 15 | mod proto; | 16 | mod proto; |
| 16 | 17 | ||
| @@ -308,6 +309,16 @@ where | |||
| 308 | }; | 309 | }; |
| 309 | 310 | ||
| 310 | debug!("event: {:?}", &event); | 311 | debug!("event: {:?}", &event); |
| 312 | |||
| 313 | let Some(payload) = &event.payload else { | ||
| 314 | warn!("event without payload?"); | ||
| 315 | return | ||
| 316 | }; | ||
| 317 | |||
| 318 | match payload { | ||
| 319 | CtrlMsgPayload::EventEspInit(_) => self.shared.init_done(), | ||
| 320 | _ => {} | ||
| 321 | } | ||
| 311 | } | 322 | } |
| 312 | } | 323 | } |
| 313 | 324 | ||
