diff options
| author | Raul Alimbekov <[email protected]> | 2025-12-16 09:05:22 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-16 09:05:22 +0300 |
| commit | c9a04b4b732b7a3b696eb8223664c1a7942b1875 (patch) | |
| tree | 6dbe5c02e66eed8d8762f13f95afd24f8db2b38c /embassy-stm32-wpan/src/mac/driver.rs | |
| parent | cde24a3ef1117653ba5ed4184102b33f745782fb (diff) | |
| parent | 5ae6e060ec1c90561719aabdc29d5b6e7b8b0a82 (diff) | |
Merge branch 'main' into main
Diffstat (limited to 'embassy-stm32-wpan/src/mac/driver.rs')
| -rw-r--r-- | embassy-stm32-wpan/src/mac/driver.rs | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/embassy-stm32-wpan/src/mac/driver.rs b/embassy-stm32-wpan/src/mac/driver.rs deleted file mode 100644 index 41cca09e3..000000000 --- a/embassy-stm32-wpan/src/mac/driver.rs +++ /dev/null | |||
| @@ -1,120 +0,0 @@ | |||
| 1 | #![deny(unused_must_use)] | ||
| 2 | |||
| 3 | use core::task::Context; | ||
| 4 | |||
| 5 | use embassy_net_driver::{Capabilities, HardwareAddress, LinkState}; | ||
| 6 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | ||
| 7 | use embassy_sync::channel::Channel; | ||
| 8 | |||
| 9 | use crate::mac::event::MacEvent; | ||
| 10 | use crate::mac::runner::Runner; | ||
| 11 | use crate::mac::MTU; | ||
| 12 | |||
| 13 | pub struct Driver<'d> { | ||
| 14 | runner: &'d Runner<'d>, | ||
| 15 | } | ||
| 16 | |||
| 17 | impl<'d> Driver<'d> { | ||
| 18 | pub(crate) fn new(runner: &'d Runner<'d>) -> Self { | ||
| 19 | Self { runner: runner } | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | impl<'d> embassy_net_driver::Driver for Driver<'d> { | ||
| 24 | // type RxToken<'a> = RxToken<'a, 'd> where Self: 'a; | ||
| 25 | // type TxToken<'a> = TxToken<'a, 'd> where Self: 'a; | ||
| 26 | type RxToken<'a> | ||
| 27 | = RxToken<'d> | ||
| 28 | where | ||
| 29 | Self: 'a; | ||
| 30 | type TxToken<'a> | ||
| 31 | = TxToken<'d> | ||
| 32 | where | ||
| 33 | Self: 'a; | ||
| 34 | |||
| 35 | fn receive(&mut self, cx: &mut Context) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { | ||
| 36 | if self.runner.rx_channel.poll_ready_to_receive(cx).is_ready() | ||
| 37 | && self.runner.tx_buf_channel.poll_ready_to_receive(cx).is_ready() | ||
| 38 | { | ||
| 39 | Some(( | ||
| 40 | RxToken { | ||
| 41 | rx: &self.runner.rx_channel, | ||
| 42 | }, | ||
| 43 | TxToken { | ||
| 44 | tx: &self.runner.tx_channel, | ||
| 45 | tx_buf: &self.runner.tx_buf_channel, | ||
| 46 | }, | ||
| 47 | )) | ||
| 48 | } else { | ||
| 49 | None | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | fn transmit(&mut self, cx: &mut Context) -> Option<Self::TxToken<'_>> { | ||
| 54 | if self.runner.tx_buf_channel.poll_ready_to_receive(cx).is_ready() { | ||
| 55 | Some(TxToken { | ||
| 56 | tx: &self.runner.tx_channel, | ||
| 57 | tx_buf: &self.runner.tx_buf_channel, | ||
| 58 | }) | ||
| 59 | } else { | ||
| 60 | None | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | fn capabilities(&self) -> Capabilities { | ||
| 65 | let mut caps = Capabilities::default(); | ||
| 66 | caps.max_transmission_unit = MTU; | ||
| 67 | // caps.max_burst_size = Some(self.tx.len()); | ||
| 68 | caps | ||
| 69 | } | ||
| 70 | |||
| 71 | fn link_state(&mut self, _cx: &mut Context) -> LinkState { | ||
| 72 | LinkState::Down | ||
| 73 | } | ||
| 74 | |||
| 75 | fn hardware_address(&self) -> HardwareAddress { | ||
| 76 | // self.mac_addr | ||
| 77 | HardwareAddress::Ieee802154([0; 8]) | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | pub struct RxToken<'d> { | ||
| 82 | rx: &'d Channel<CriticalSectionRawMutex, MacEvent<'d>, 1>, | ||
| 83 | } | ||
| 84 | |||
| 85 | impl<'d> embassy_net_driver::RxToken for RxToken<'d> { | ||
| 86 | fn consume<R, F>(self, f: F) -> R | ||
| 87 | where | ||
| 88 | F: FnOnce(&mut [u8]) -> R, | ||
| 89 | { | ||
| 90 | // Only valid data events should be put into the queue | ||
| 91 | |||
| 92 | let data_event = match self.rx.try_receive().unwrap() { | ||
| 93 | MacEvent::McpsDataInd(data_event) => data_event, | ||
| 94 | _ => unreachable!(), | ||
| 95 | }; | ||
| 96 | |||
| 97 | f(&mut data_event.payload()) | ||
| 98 | } | ||
| 99 | } | ||
| 100 | |||
| 101 | pub struct TxToken<'d> { | ||
| 102 | tx: &'d Channel<CriticalSectionRawMutex, (&'d mut [u8; MTU], usize), 5>, | ||
| 103 | tx_buf: &'d Channel<CriticalSectionRawMutex, &'d mut [u8; MTU], 5>, | ||
| 104 | } | ||
| 105 | |||
| 106 | impl<'d> embassy_net_driver::TxToken for TxToken<'d> { | ||
| 107 | fn consume<R, F>(self, len: usize, f: F) -> R | ||
| 108 | where | ||
| 109 | F: FnOnce(&mut [u8]) -> R, | ||
| 110 | { | ||
| 111 | // Only valid tx buffers should be put into the queue | ||
| 112 | let buf = self.tx_buf.try_receive().unwrap(); | ||
| 113 | let r = f(&mut buf[..len]); | ||
| 114 | |||
| 115 | // The tx channel should always be of equal capacity to the tx_buf channel | ||
| 116 | self.tx.try_send((buf, len)).unwrap(); | ||
| 117 | |||
| 118 | r | ||
| 119 | } | ||
| 120 | } | ||
