diff options
| author | kbleeke <[email protected]> | 2023-03-02 15:34:08 +0100 |
|---|---|---|
| committer | kbleeke <[email protected]> | 2023-03-27 11:48:58 +0200 |
| commit | 6f547cf05ddd1a27c8ec4e107ac227f7f9520ba6 (patch) | |
| tree | e6e374b2b67ef4a1be8fa2a7cedbaf29d2c9cc9c /src/control.rs | |
| parent | 5da6108bec0c977841df21ae4140c4ac61a5369f (diff) | |
asyncify outgoing events
Diffstat (limited to 'src/control.rs')
| -rw-r--r-- | src/control.rs | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/src/control.rs b/src/control.rs index 8bfa033ba..98f678fbc 100644 --- a/src/control.rs +++ b/src/control.rs | |||
| @@ -1,8 +1,6 @@ | |||
| 1 | use core::cell::Cell; | ||
| 2 | use core::cmp::{max, min}; | 1 | use core::cmp::{max, min}; |
| 3 | 2 | ||
| 4 | use ch::driver::LinkState; | 3 | use ch::driver::LinkState; |
| 5 | use embassy_futures::yield_now; | ||
| 6 | use embassy_net_driver_channel as ch; | 4 | use embassy_net_driver_channel as ch; |
| 7 | use embassy_time::{Duration, Timer}; | 5 | use embassy_time::{Duration, Timer}; |
| 8 | 6 | ||
| @@ -10,21 +8,18 @@ pub use crate::bus::SpiBusCyw43; | |||
| 10 | use crate::consts::*; | 8 | use crate::consts::*; |
| 11 | use crate::events::{Event, EventQueue}; | 9 | use crate::events::{Event, EventQueue}; |
| 12 | use crate::fmt::Bytes; | 10 | use crate::fmt::Bytes; |
| 11 | use crate::ioctl::{IoctlState, IoctlType}; | ||
| 13 | use crate::structs::*; | 12 | use crate::structs::*; |
| 14 | use crate::{countries, IoctlState, IoctlType, PowerManagementMode}; | 13 | use crate::{countries, PowerManagementMode}; |
| 15 | 14 | ||
| 16 | pub struct Control<'a> { | 15 | pub struct Control<'a> { |
| 17 | state_ch: ch::StateRunner<'a>, | 16 | state_ch: ch::StateRunner<'a>, |
| 18 | event_sub: &'a EventQueue, | 17 | event_sub: &'a EventQueue, |
| 19 | ioctl_state: &'a Cell<IoctlState>, | 18 | ioctl_state: &'a IoctlState, |
| 20 | } | 19 | } |
| 21 | 20 | ||
| 22 | impl<'a> Control<'a> { | 21 | impl<'a> Control<'a> { |
| 23 | pub(crate) fn new( | 22 | pub(crate) fn new(state_ch: ch::StateRunner<'a>, event_sub: &'a EventQueue, ioctl_state: &'a IoctlState) -> Self { |
| 24 | state_ch: ch::StateRunner<'a>, | ||
| 25 | event_sub: &'a EventQueue, | ||
| 26 | ioctl_state: &'a Cell<IoctlState>, | ||
| 27 | ) -> Self { | ||
| 28 | Self { | 23 | Self { |
| 29 | state_ch, | 24 | state_ch, |
| 30 | event_sub, | 25 | event_sub, |
| @@ -278,23 +273,8 @@ impl<'a> Control<'a> { | |||
| 278 | } | 273 | } |
| 279 | 274 | ||
| 280 | async fn ioctl(&mut self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { | 275 | async fn ioctl(&mut self, kind: IoctlType, cmd: u32, iface: u32, buf: &mut [u8]) -> usize { |
| 281 | // TODO cancel ioctl on future drop. | 276 | self.ioctl_state.do_ioctl(kind, cmd, iface, buf).await; |
| 282 | 277 | let resp_len = self.ioctl_state.wait_complete().await; | |
| 283 | while !matches!(self.ioctl_state.get(), IoctlState::Idle) { | ||
| 284 | yield_now().await; | ||
| 285 | } | ||
| 286 | |||
| 287 | self.ioctl_state.set(IoctlState::Pending { kind, cmd, iface, buf }); | ||
| 288 | |||
| 289 | let resp_len = loop { | ||
| 290 | if let IoctlState::Done { resp_len } = self.ioctl_state.get() { | ||
| 291 | break resp_len; | ||
| 292 | } | ||
| 293 | yield_now().await; | ||
| 294 | }; | ||
| 295 | |||
| 296 | self.ioctl_state.set(IoctlState::Idle); | ||
| 297 | |||
| 298 | resp_len | 278 | resp_len |
| 299 | } | 279 | } |
| 300 | } | 280 | } |
