Skip to content

Commit

Permalink
Merge pull request tock#4289 from tyler-potyondy/dev/15.4-enable
Browse files Browse the repository at this point in the history
802.15.4 Add radio enable syscall to standard driver
  • Loading branch information
lschuermann authored Jan 4, 2025
2 parents 585d360 + db9e95b commit 05c535c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions capsules/extra/src/ieee802154/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ pub trait MacDevice<'a> {
/// Returns if the MAC device is currently on.
fn is_on(&self) -> bool;

/// Start the radio.
///
/// This serves as a passthrough to the underlying radio's `start` method.
///
/// ## Return
///
/// `Ok(())` on success. On `Err()`, valid errors are:
///
/// - `ErrorCode::FAIL`: Internal error occurred.
fn start(&self) -> Result<(), ErrorCode>;

/// Prepares a mutable buffer slice as an 802.15.4 frame by writing the appropriate
/// header bytes into the buffer. This needs to be done before adding the
/// payload because the length of the header is not fixed.
Expand Down
2 changes: 2 additions & 0 deletions capsules/extra/src/ieee802154/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ impl<'a, M: device::MacDevice<'a>> SyscallDriver for RadioDriver<'a, M> {
/// parameters to encrypt, form headers, and transmit the frame.
/// - `28`: Set long address.
/// - `29`: Get the long MAC address.
/// - `30`: Turn the radio on.
fn command(
&self,
command_number: usize,
Expand Down Expand Up @@ -967,6 +968,7 @@ impl<'a, M: device::MacDevice<'a>> SyscallDriver for RadioDriver<'a, M> {
let addr = u64::from_be_bytes(self.mac.get_address_long());
CommandReturn::success_u64(addr)
}
30 => self.mac.start().into(),
_ => CommandReturn::failure(ErrorCode::NOSUPPORT),
}
}
Expand Down
4 changes: 4 additions & 0 deletions capsules/extra/src/ieee802154/framer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,10 @@ impl<'a, M: Mac<'a>, A: AES128CCM<'a>> MacDevice<'a> for Framer<'a, M, A> {
self.mac.is_on()
}

fn start(&self) -> Result<(), ErrorCode> {
self.mac.start()
}

fn prepare_data_frame(
&self,
buf: &'static mut [u8],
Expand Down
15 changes: 15 additions & 0 deletions capsules/extra/src/ieee802154/mac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ pub trait Mac<'a> {
/// Indicates whether or not the MAC protocol is active and can send frames
fn is_on(&self) -> bool;

/// Start the radio.
///
/// This serves as a passthrough to the underlying radio's `start` method.
///
/// ## Return
///
/// `Ok(())` on success. On `Err()`, valid errors are:
///
/// - `ErrorCode::FAIL`: Internal error occurred.
fn start(&self) -> Result<(), ErrorCode>;

/// Transmits complete MAC frames, which must be prepared by an ieee802154::device::MacDevice
/// before being passed to the Mac layer. Returns the frame buffer in case of an error.
fn transmit(
Expand Down Expand Up @@ -98,6 +109,10 @@ impl<'a, R: radio::Radio<'a>> Mac<'a> for AwakeMac<'a, R> {
self.radio.is_on()
}

fn start(&self) -> Result<(), ErrorCode> {
self.radio.start()
}

fn set_config_client(&self, client: &'a dyn radio::ConfigClient) {
self.radio.set_config_client(client)
}
Expand Down
4 changes: 4 additions & 0 deletions capsules/extra/src/ieee802154/virtual_mac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ impl<'a, M: device::MacDevice<'a>> device::MacDevice<'a> for MacUser<'a, M> {
self.mux.mac.is_on()
}

fn start(&self) -> Result<(), ErrorCode> {
self.mux.mac.start()
}

fn prepare_data_frame(
&self,
buf: &'static mut [u8],
Expand Down
5 changes: 5 additions & 0 deletions capsules/extra/src/ieee802154/xmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ impl<'a, R: radio::Radio<'a>, A: Alarm<'a>> Mac<'a> for XMac<'a, R, A> {
self.radio.is_on()
}

fn start(&self) -> Result<(), ErrorCode> {
self.state.set(XMacState::STARTUP);
self.radio.start()
}

fn set_config_client(&self, client: &'a dyn radio::ConfigClient) {
self.radio.set_config_client(client)
}
Expand Down

0 comments on commit 05c535c

Please sign in to comment.