Skip to content

Commit

Permalink
capsules: ieee802154: remove buffer from mac::init
Browse files Browse the repository at this point in the history
Buffer should just be passed to the object when it is created, not on
initialization.
  • Loading branch information
bradjc committed May 16, 2024
1 parent e028953 commit 6289b6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
7 changes: 3 additions & 4 deletions capsules/extra/src/ieee802154/mac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ use kernel::utilities::cells::OptionalCell;
use kernel::ErrorCode;

pub trait Mac<'a> {
/// Initializes the layer; may require a buffer to temporarily retaining frames to be
/// transmitted
fn initialize(&self, mac_buf: &'static mut [u8]) -> Result<(), ErrorCode>;
/// Initializes the layer.
fn initialize(&self) -> Result<(), ErrorCode>;

/// Sets the notified client for configuration changes
fn set_config_client(&self, client: &'a dyn radio::ConfigClient);
Expand Down Expand Up @@ -88,7 +87,7 @@ impl<'a, R: radio::Radio<'a>> AwakeMac<'a, R> {
}

impl<'a, R: radio::Radio<'a>> Mac<'a> for AwakeMac<'a, R> {
fn initialize(&self, _mac_buf: &'static mut [u8]) -> Result<(), ErrorCode> {
fn initialize(&self) -> Result<(), ErrorCode> {
// do nothing, extra buffer unnecessary
Ok(())
}
Expand Down
16 changes: 10 additions & 6 deletions capsules/extra/src/ieee802154/xmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
//! // radio for transmitting preamble packets
//! static mut MAC_BUF: [u8; radio::MAX_BUF_SIZE] = [0x00; radio::MAX_BUF_SIZE];
//! // ...
//! let xmac: &XMacDevice = static_init!(XMacDevice, xmac::XMac::new(rf233, alarm, rng));
//! let xmac: &XMacDevice = static_init!(XMacDevice, xmac::XMac::new(rf233, alarm, rng, &mut MAC_BUF));
//! rng.set_client(xmac);
//! alarm.set_client(xmac);
//!
Expand All @@ -60,7 +60,7 @@
//! rf233.set_receive_client(xmac, &mut RF233_RX_BUF);
//! rf233.set_power_client(xmac);
//!
//! xmac.initialize(&mut MAC_BUF);
//! xmac.initialize();
//!
//! // We can now use the XMac driver to instantiate a MacDevice like a Framer
//! let mac_device = static_init!(
Expand Down Expand Up @@ -169,7 +169,12 @@ pub struct XMac<'a, R: radio::Radio<'a>, A: Alarm<'a>> {
}

impl<'a, R: radio::Radio<'a>, A: Alarm<'a>> XMac<'a, R, A> {
pub fn new(radio: &'a R, alarm: &'a A, rng: &'a dyn Rng<'a>) -> XMac<'a, R, A> {
pub fn new(
radio: &'a R,
alarm: &'a A,
rng: &'a dyn Rng<'a>,
mac_buf: &'static mut [u8],
) -> XMac<'a, R, A> {
XMac {
radio: radio,
alarm: alarm,
Expand All @@ -183,7 +188,7 @@ impl<'a, R: radio::Radio<'a>, A: Alarm<'a>> XMac<'a, R, A> {
tx_len: Cell::new(0),
tx_preamble_pending: Cell::new(false),
tx_preamble_seq_num: Cell::new(0),
tx_preamble_buf: TakeCell::empty(),
tx_preamble_buf: TakeCell::new(mac_buf),
rx_pending: Cell::new(false),
}
}
Expand Down Expand Up @@ -350,8 +355,7 @@ impl<'a, R: radio::Radio<'a>, A: Alarm<'a>> rng::Client for XMac<'a, R, A> {

// The vast majority of these calls pass through to the underlying radio driver.
impl<'a, R: radio::Radio<'a>, A: Alarm<'a>> Mac<'a> for XMac<'a, R, A> {
fn initialize(&self, mac_buf: &'static mut [u8]) -> Result<(), ErrorCode> {
self.tx_preamble_buf.replace(mac_buf);
fn initialize(&self) -> Result<(), ErrorCode> {
self.state.set(XMacState::STARTUP);
Ok(())
}
Expand Down

0 comments on commit 6289b6c

Please sign in to comment.