Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions openthread/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ use sys::{
otOperationalDataset, otOperationalDatasetTlvs, otPlatAlarmMilliFired, otPlatRadioReceiveDone,
otPlatRadioTxDone, otPlatRadioTxStarted, otRadioCaps, otRadioFrame, otSetStateChangedCallback,
otTaskletsArePending, otTaskletsProcess, otThreadGetDeviceRole, otThreadGetExtendedPanId,
otThreadSetEnabled, OT_RADIO_CAPS_ACK_TIMEOUT, OT_RADIO_FRAME_MAX_SIZE,
otThreadGetLinkMode, otThreadSetEnabled, OT_RADIO_CAPS_ACK_TIMEOUT, OT_RADIO_FRAME_MAX_SIZE,
};

/// A newtype wrapper over the native OpenThread error type (`otError`).
Expand Down Expand Up @@ -1394,7 +1394,13 @@ impl<'a> OtContext<'a> {

fn plat_changed(&mut self, _flags: u32) {
trace!("Plat changed callback");
self.state().ot.changes.signal(());

let state = self.state();

let rx_on_when_idle = unsafe { otThreadGetLinkMode(state.ot.instance) }.mRxOnWhenIdle();
Self::update_rx_when_idle(state, rx_on_when_idle);

state.ot.changes.signal(());
}

fn plat_now(&mut self) -> u32 {
Expand Down Expand Up @@ -1506,6 +1512,25 @@ impl<'a> OtContext<'a> {
}
}

fn plat_radio_set_rx_on_when_idle(&mut self, rx_on_when_idle: bool) {
info!(
"Plat radio set rx_on_when_idle callback, rx_on_when_idle: {}",
rx_on_when_idle
);

Self::update_rx_when_idle(self.state(), rx_on_when_idle);
}

fn update_rx_when_idle(state: &mut OtActiveState<'_>, rx_on_when_idle: bool) {
if state.ot.radio_conf.rx_when_idle != rx_on_when_idle {
info!(
"Updating rx_when_idle: {} -> {}",
state.ot.radio_conf.rx_when_idle, rx_on_when_idle
);
state.ot.radio_conf.rx_when_idle = rx_on_when_idle;
}
}

fn plat_radio_set_extended_address(&mut self, address: u64) {
info!(
"Plat radio set extended address callback, addr: 0x{:08x}",
Expand Down
5 changes: 5 additions & 0 deletions openthread/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ extern "C" fn otPlatRadioSetPromiscuous(instance: *const otInstance, enable: boo
OtContext::callback(instance).plat_radio_set_promiscuous(enable)
}

#[no_mangle]
extern "C" fn otPlatRadioSetRxOnWhenIdle(instance: *mut otInstance, enable: bool) {
OtContext::callback(instance).plat_radio_set_rx_on_when_idle(enable)
}

#[no_mangle]
extern "C" fn otPlatRadioGetRssi(instance: *const otInstance) -> i8 {
OtContext::callback(instance).plat_radio_get_rssi()
Expand Down