Skip to content

Commit 812e47c

Browse files
committed
Add sleep mode blocking to avoid going into EM2 during RTOS idle handler
1 parent 76fd28c commit 812e47c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

features/nanostack/FEATURE_NANOSTACK/targets/TARGET_SL_RAIL/NanostackRfPhyEfr32.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "platform/arm_hal_interrupt.h"
2323
#include "nanostack/platform/arm_hal_phy.h"
2424
#include "mbed_toolchain.h"
25+
#include "sleepmodes.h"
2526

2627
#include "mbed-trace/mbed_trace.h"
2728
#define TRACE_GROUP "SLRF"
@@ -227,6 +228,7 @@ static const RAIL_IEEE802154_Config_t config = {
227228
};
228229

229230
static volatile siliconlabs_modem_state_t radio_state = RADIO_UNINIT;
231+
static volatile bool sleep_blocked = false;
230232
static volatile int8_t channel = -1;
231233
static volatile uint8_t current_tx_handle = 0;
232234
static volatile uint8_t current_tx_sequence = 0;
@@ -255,7 +257,7 @@ static RAIL_Config_t railCfg = { // Must never be const
255257

256258
static void rf_thread_loop(const void *arg)
257259
{
258-
SL_DEBUG_PRINT("rf_thread_loop: starting (id: %d)\n", rf_thread_id);
260+
SL_DEBUG_PRINT("rf_thread_loop: starting (id: %d)\n", (int)rf_thread_id);
259261
for (;;) {
260262
osEvent event = osSignalWait(0, osWaitForever);
261263

@@ -321,7 +323,7 @@ static void rf_thread_loop(const void *arg)
321323
} else if(event.value.signals & SL_QUEUE_FULL) {
322324
SL_DEBUG_PRINT("rf_thread_loop: SL_QUEUE_FULL signal received (packet dropped)\n");
323325
} else {
324-
SL_DEBUG_PRINT("rf_thread_loop unhandled event status: %d value: %d\n", event.status, event.value.signals);
326+
SL_DEBUG_PRINT("rf_thread_loop unhandled event status: %d value: %d\n", event.status, (int)event.value.signals);
325327
}
326328

327329
platform_exit_critical();
@@ -479,6 +481,10 @@ static int8_t rf_device_register(void)
479481
static void rf_device_unregister(void)
480482
{
481483
arm_net_phy_unregister(rf_radio_driver_id);
484+
if(sleep_blocked) {
485+
unblockSleepMode(EM1);
486+
sleep_blocked = false;
487+
}
482488
}
483489

484490
/*
@@ -573,11 +579,19 @@ static int8_t rf_interface_state_control(phy_interface_state_e new_state, uint8_
573579
case PHY_INTERFACE_RESET:
574580
RAIL_Idle(gRailHandle, RAIL_IDLE_FORCE_SHUTDOWN_CLEAR_FLAGS, true);
575581
radio_state = RADIO_IDLE;
582+
if(sleep_blocked) {
583+
unblockSleepMode(EM1);
584+
sleep_blocked = false;
585+
}
576586
break;
577587
/* Disable PHY Interface driver */
578588
case PHY_INTERFACE_DOWN:
579589
RAIL_Idle(gRailHandle, RAIL_IDLE_FORCE_SHUTDOWN_CLEAR_FLAGS, true);
580590
radio_state = RADIO_IDLE;
591+
if(sleep_blocked) {
592+
unblockSleepMode(EM1);
593+
sleep_blocked = false;
594+
}
581595
break;
582596
/* Enable RX */
583597
case PHY_INTERFACE_UP:
@@ -586,6 +600,11 @@ static int8_t rf_interface_state_control(phy_interface_state_e new_state, uint8_
586600
RAIL_IEEE802154_SetPromiscuousMode(gRailHandle, false);
587601
RAIL_StartRx(gRailHandle, channel, NULL);
588602
radio_state = RADIO_RX;
603+
if(!sleep_blocked) {
604+
/* RX can only happen in EM0/1*/
605+
blockSleepMode(EM1);
606+
sleep_blocked = true;
607+
}
589608
} else {
590609
ret_val = -1;
591610
}
@@ -602,6 +621,11 @@ static int8_t rf_interface_state_control(phy_interface_state_e new_state, uint8_
602621
RAIL_IEEE802154_SetPromiscuousMode(gRailHandle, true);
603622
RAIL_StartRx(gRailHandle, channel, NULL);
604623
radio_state = RADIO_RX;
624+
if(!sleep_blocked) {
625+
/* RX can only happen in EM0/1*/
626+
blockSleepMode(EM1);
627+
sleep_blocked = true;
628+
}
605629
} else {
606630
ret_val = -1;
607631
}

0 commit comments

Comments
 (0)