Expose IEEE802.15.4 address in Driver
This commit is contained in:
parent
d752a3f980
commit
c52d1d11f9
2 changed files with 21 additions and 0 deletions
|
@ -43,6 +43,7 @@ struct Shared {
|
|||
link_state: LinkState,
|
||||
waker: WakerRegistration,
|
||||
ethernet_address: [u8; 6],
|
||||
ieee802154_address: [u8; 8],
|
||||
}
|
||||
|
||||
pub struct Runner<'d, const MTU: usize> {
|
||||
|
@ -93,6 +94,14 @@ impl<'d, const MTU: usize> Runner<'d, MTU> {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn set_ieee802154_address(&mut self, address: [u8; 8]) {
|
||||
self.shared.lock(|s| {
|
||||
let s = &mut *s.borrow_mut();
|
||||
s.ieee802154_address = address;
|
||||
s.waker.wake();
|
||||
});
|
||||
}
|
||||
|
||||
pub async fn rx_buf(&mut self) -> &mut [u8] {
|
||||
let p = self.rx_chan.send().await;
|
||||
&mut p.buf
|
||||
|
@ -207,6 +216,7 @@ impl<'d, const MTU: usize> TxRunner<'d, MTU> {
|
|||
pub fn new<'d, const MTU: usize, const N_RX: usize, const N_TX: usize>(
|
||||
state: &'d mut State<MTU, N_RX, N_TX>,
|
||||
ethernet_address: [u8; 6],
|
||||
ieee802154_address: [u8; 8],
|
||||
) -> (Runner<'d, MTU>, Device<'d, MTU>) {
|
||||
let mut caps = Capabilities::default();
|
||||
caps.max_transmission_unit = MTU;
|
||||
|
@ -223,6 +233,7 @@ pub fn new<'d, const MTU: usize, const N_RX: usize, const N_TX: usize>(
|
|||
shared: Mutex::new(RefCell::new(Shared {
|
||||
link_state: LinkState::Down,
|
||||
ethernet_address,
|
||||
ieee802154_address,
|
||||
waker: WakerRegistration::new(),
|
||||
})),
|
||||
});
|
||||
|
@ -293,6 +304,10 @@ impl<'d, const MTU: usize> embassy_net_driver::Driver for Device<'d, MTU> {
|
|||
self.shared.lock(|s| s.borrow().ethernet_address)
|
||||
}
|
||||
|
||||
fn ieee802154_address(&self) -> [u8; 8] {
|
||||
self.shared.lock(|s| s.borrow().ieee802154_address)
|
||||
}
|
||||
|
||||
fn link_state(&mut self, cx: &mut Context) -> LinkState {
|
||||
self.shared.lock(|s| {
|
||||
let s = &mut *s.borrow_mut();
|
||||
|
|
|
@ -53,6 +53,9 @@ pub trait Driver {
|
|||
|
||||
/// Get the device's Ethernet address.
|
||||
fn ethernet_address(&self) -> [u8; 6];
|
||||
|
||||
/// Get the device's IEEE 802.15.4 address.
|
||||
fn ieee802154_address(&self) -> [u8; 8];
|
||||
}
|
||||
|
||||
impl<T: ?Sized + Driver> Driver for &mut T {
|
||||
|
@ -78,6 +81,9 @@ impl<T: ?Sized + Driver> Driver for &mut T {
|
|||
fn ethernet_address(&self) -> [u8; 6] {
|
||||
T::ethernet_address(self)
|
||||
}
|
||||
fn ieee802154_address(&self) -> [u8; 8] {
|
||||
T::ieee802154_address(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// A token to receive a single network packet.
|
||||
|
|
Loading…
Reference in a new issue