diff options
Diffstat (limited to 'embassy-stm32-wpan/src/mac/runner.rs')
| -rw-r--r-- | embassy-stm32-wpan/src/mac/runner.rs | 109 |
1 files changed, 0 insertions, 109 deletions
diff --git a/embassy-stm32-wpan/src/mac/runner.rs b/embassy-stm32-wpan/src/mac/runner.rs deleted file mode 100644 index d3099b6b7..000000000 --- a/embassy-stm32-wpan/src/mac/runner.rs +++ /dev/null | |||
| @@ -1,109 +0,0 @@ | |||
| 1 | use core::cell::RefCell; | ||
| 2 | |||
| 3 | use embassy_futures::join; | ||
| 4 | use embassy_sync::blocking_mutex; | ||
| 5 | use embassy_sync::blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}; | ||
| 6 | use embassy_sync::channel::Channel; | ||
| 7 | use embassy_sync::mutex::Mutex; | ||
| 8 | use embassy_sync::signal::Signal; | ||
| 9 | |||
| 10 | use crate::mac::commands::DataRequest; | ||
| 11 | use crate::mac::event::MacEvent; | ||
| 12 | use crate::mac::typedefs::{AddressMode, MacAddress, PanId, SecurityLevel}; | ||
| 13 | use crate::mac::MTU; | ||
| 14 | use crate::sub::mac::Mac; | ||
| 15 | |||
| 16 | type ZeroCopyPubSub<M, T> = blocking_mutex::Mutex<M, RefCell<Option<Signal<NoopRawMutex, T>>>>; | ||
| 17 | |||
| 18 | pub struct Runner<'a> { | ||
| 19 | pub(crate) mac_subsystem: Mac, | ||
| 20 | // rx event backpressure is already provided through the MacEvent drop mechanism | ||
| 21 | // therefore, we don't need to worry about overwriting events | ||
| 22 | pub(crate) rx_event_channel: ZeroCopyPubSub<CriticalSectionRawMutex, MacEvent<'a>>, | ||
| 23 | pub(crate) read_mutex: Mutex<CriticalSectionRawMutex, ()>, | ||
| 24 | pub(crate) write_mutex: Mutex<CriticalSectionRawMutex, ()>, | ||
| 25 | pub(crate) rx_channel: Channel<CriticalSectionRawMutex, MacEvent<'a>, 1>, | ||
| 26 | pub(crate) tx_channel: Channel<CriticalSectionRawMutex, (&'a mut [u8; MTU], usize), 5>, | ||
| 27 | pub(crate) tx_buf_channel: Channel<CriticalSectionRawMutex, &'a mut [u8; MTU], 5>, | ||
| 28 | } | ||
| 29 | |||
| 30 | impl<'a> Runner<'a> { | ||
| 31 | pub fn new(mac: Mac, tx_buf_queue: [&'a mut [u8; MTU]; 5]) -> Self { | ||
| 32 | let this = Self { | ||
| 33 | mac_subsystem: mac, | ||
| 34 | rx_event_channel: blocking_mutex::Mutex::new(RefCell::new(None)), | ||
| 35 | read_mutex: Mutex::new(()), | ||
| 36 | write_mutex: Mutex::new(()), | ||
| 37 | rx_channel: Channel::new(), | ||
| 38 | tx_channel: Channel::new(), | ||
| 39 | tx_buf_channel: Channel::new(), | ||
| 40 | }; | ||
| 41 | |||
| 42 | for buf in tx_buf_queue { | ||
| 43 | this.tx_buf_channel.try_send(buf).unwrap(); | ||
| 44 | } | ||
| 45 | |||
| 46 | this | ||
| 47 | } | ||
| 48 | |||
| 49 | pub async fn run(&'a self) -> ! { | ||
| 50 | join::join( | ||
| 51 | async { | ||
| 52 | loop { | ||
| 53 | if let Ok(mac_event) = self.mac_subsystem.read().await { | ||
| 54 | match mac_event { | ||
| 55 | MacEvent::McpsDataInd(_) => { | ||
| 56 | self.rx_channel.send(mac_event).await; | ||
| 57 | } | ||
| 58 | _ => { | ||
| 59 | self.rx_event_channel.lock(|s| { | ||
| 60 | match &*s.borrow() { | ||
| 61 | Some(signal) => { | ||
| 62 | signal.signal(mac_event); | ||
| 63 | } | ||
| 64 | None => {} | ||
| 65 | }; | ||
| 66 | }); | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | } | ||
| 71 | }, | ||
| 72 | async { | ||
| 73 | let mut msdu_handle = 0x02; | ||
| 74 | |||
| 75 | loop { | ||
| 76 | let (buf, len) = self.tx_channel.receive().await; | ||
| 77 | let _wm = self.write_mutex.lock().await; | ||
| 78 | |||
| 79 | // The mutex should be dropped on the next loop iteration | ||
| 80 | self.mac_subsystem | ||
| 81 | .send_command( | ||
| 82 | DataRequest { | ||
| 83 | src_addr_mode: AddressMode::Short, | ||
| 84 | dst_addr_mode: AddressMode::Short, | ||
| 85 | dst_pan_id: PanId([0x1A, 0xAA]), | ||
| 86 | dst_address: MacAddress::BROADCAST, | ||
| 87 | msdu_handle: msdu_handle, | ||
| 88 | ack_tx: 0x00, | ||
| 89 | gts_tx: false, | ||
| 90 | security_level: SecurityLevel::Unsecure, | ||
| 91 | ..Default::default() | ||
| 92 | } | ||
| 93 | .set_buffer(&buf[..len]), | ||
| 94 | ) | ||
| 95 | .await | ||
| 96 | .unwrap(); | ||
| 97 | |||
| 98 | msdu_handle = msdu_handle.wrapping_add(1); | ||
| 99 | |||
| 100 | // The tx channel should always be of equal capacity to the tx_buf channel | ||
| 101 | self.tx_buf_channel.try_send(buf).unwrap(); | ||
| 102 | } | ||
| 103 | }, | ||
| 104 | ) | ||
| 105 | .await; | ||
| 106 | |||
| 107 | loop {} | ||
| 108 | } | ||
| 109 | } | ||
