embassy/embassy-stm32-wpan/src/mac/driver.rs

115 lines
2.9 KiB
Rust
Raw Normal View History

2023-07-16 02:15:01 +02:00
#![allow(incomplete_features)]
#![deny(unused_must_use)]
2023-07-18 02:26:58 +02:00
use core::task::Context;
2023-07-16 02:15:01 +02:00
2023-07-18 02:26:58 +02:00
use embassy_net_driver::{Capabilities, LinkState, Medium};
2023-07-16 02:15:01 +02:00
2023-07-18 02:26:58 +02:00
use crate::mac::runner::Runner;
use crate::mac::MTU;
2023-07-16 02:15:01 +02:00
2023-07-18 02:26:58 +02:00
pub struct Driver<'d> {
runner: &'d Runner,
2023-07-16 02:15:01 +02:00
}
2023-07-18 02:26:58 +02:00
impl<'d> Driver<'d> {
pub(crate) fn new(runner: &'d Runner) -> Self {
Self { runner: runner }
2023-07-16 02:15:01 +02:00
}
}
2023-07-18 02:26:58 +02:00
impl<'d> embassy_net_driver::Driver for Driver<'d> {
// type RxToken<'a> = RxToken<'a, 'd> where Self: 'a;
// type TxToken<'a> = TxToken<'a, 'd> where Self: 'a;
type RxToken<'a> = RxToken where Self: 'a;
type TxToken<'a> = TxToken where Self: 'a;
fn receive(&mut self, cx: &mut Context) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> {
self.runner.rx_waker.register(cx.waker());
2023-07-18 02:26:58 +02:00
// WAKER.register(cx.waker());
// if self.rx.available().is_some() && self.tx.available().is_some() {
// Some((RxToken { rx: &mut self.rx }, TxToken { tx: &mut self.tx }))
// } else {
// None
// }
None
}
fn transmit(&mut self, cx: &mut Context) -> Option<Self::TxToken<'_>> {
self.runner.tx_waker.register(cx.waker());
2023-07-18 02:26:58 +02:00
// WAKER.register(cx.waker());
// / if self.tx.available().is_some() {
// / Some(TxToken { tx: &mut self.tx })
// / } else {
// / None
// / }
2023-07-16 02:15:01 +02:00
2023-07-18 02:26:58 +02:00
None
}
2023-07-16 02:15:01 +02:00
2023-07-18 02:26:58 +02:00
fn capabilities(&self) -> Capabilities {
let mut caps = Capabilities::default();
caps.max_transmission_unit = MTU;
// caps.max_burst_size = Some(self.tx.len());
2023-07-16 02:15:01 +02:00
2023-07-18 02:26:58 +02:00
caps.medium = Medium::Ieee802154;
caps
}
2023-07-16 02:15:01 +02:00
2023-07-18 02:26:58 +02:00
fn link_state(&mut self, cx: &mut Context) -> LinkState {
// if self.phy.poll_link(&mut self.station_management, cx) {
// LinkState::Up
// } else {
// LinkState::Down
// }
2023-07-16 02:15:01 +02:00
2023-07-18 02:26:58 +02:00
LinkState::Down
}
fn ethernet_address(&self) -> [u8; 6] {
// self.mac_addr
2023-07-16 02:15:01 +02:00
2023-07-18 02:26:58 +02:00
[0; 6]
2023-07-16 02:15:01 +02:00
}
}
2023-07-18 02:26:58 +02:00
pub struct RxToken {
// rx: &'a mut RDesRing<'d>,
}
impl embassy_net_driver::RxToken for RxToken {
fn consume<R, F>(self, f: F) -> R
where
F: FnOnce(&mut [u8]) -> R,
{
// NOTE(unwrap): we checked the queue wasn't full when creating the token.
// let pkt = unwrap!(self.rx.available());
let pkt = &mut [];
2023-07-18 02:26:58 +02:00
let r = f(&mut pkt[0..]);
// self.rx.pop_packet();
r
}
2023-07-16 02:15:01 +02:00
}
2023-07-18 02:26:58 +02:00
pub struct TxToken {
// tx: &'a mut TDesRing<'d>,
2023-07-16 02:15:01 +02:00
}
2023-07-18 02:26:58 +02:00
impl embassy_net_driver::TxToken for TxToken {
fn consume<R, F>(self, len: usize, f: F) -> R
where
F: FnOnce(&mut [u8]) -> R,
{
// NOTE(unwrap): we checked the queue wasn't full when creating the token.
// let pkt = unwrap!(self.tx.available());
let pkt = &mut [];
2023-07-18 02:26:58 +02:00
let r = f(&mut pkt[..len]);
// self.tx.transmit(len);
r
}
2023-07-16 02:15:01 +02:00
}