CC26xx IEEE mode: introduce and use LIMITED_BUSYWAIT macro; avoids watchdog reboots in cases when the radio fails to turn off

This commit is contained in:
Atis Elsts 2017-03-14 18:42:09 +00:00
parent 3b090d97c7
commit c850bae186

View File

@ -163,6 +163,18 @@ static uint8_t rf_stats[16] = { 0 };
/* How long to wait for the RF to enter RX in rf_cmd_ieee_rx */ /* How long to wait for the RF to enter RX in rf_cmd_ieee_rx */
#define ENTER_RX_WAIT_TIMEOUT (RTIMER_SECOND >> 10) #define ENTER_RX_WAIT_TIMEOUT (RTIMER_SECOND >> 10)
/* How long to wait for the RF to react on CMD_ABORT: around 1 msec */
#define RF_TURN_OFF_WAIT_TIMEOUT (RTIMER_SECOND >> 10)
#define LIMITED_BUSYWAIT(cond, timeout) do { \
rtimer_clock_t end_time = RTIMER_NOW() + timeout; \
while(cond) { \
if(!RTIMER_CLOCK_LT(RTIMER_NOW(), end_time)) { \
break; \
} \
} \
} while(0)
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* TX Power dBm lookup table - values from SmartRF Studio */ /* TX Power dBm lookup table - values from SmartRF Studio */
typedef struct output_config { typedef struct output_config {
@ -511,7 +523,6 @@ static uint8_t
rf_cmd_ieee_rx() rf_cmd_ieee_rx()
{ {
uint32_t cmd_status; uint32_t cmd_status;
rtimer_clock_t t0;
int ret; int ret;
ret = rf_core_send_cmd((uint32_t)cmd_ieee_rx_buf, &cmd_status); ret = rf_core_send_cmd((uint32_t)cmd_ieee_rx_buf, &cmd_status);
@ -522,10 +533,8 @@ rf_cmd_ieee_rx()
return RF_CORE_CMD_ERROR; return RF_CORE_CMD_ERROR;
} }
t0 = RTIMER_NOW(); LIMITED_BUSYWAIT(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) != RF_CORE_RADIO_OP_STATUS_ACTIVE,
ENTER_RX_WAIT_TIMEOUT);
while(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) != RF_CORE_RADIO_OP_STATUS_ACTIVE &&
(RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + ENTER_RX_WAIT_TIMEOUT)));
/* Wait to enter RX */ /* Wait to enter RX */
if(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) != RF_CORE_RADIO_OP_STATUS_ACTIVE) { if(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) != RF_CORE_RADIO_OP_STATUS_ACTIVE) {
@ -688,7 +697,7 @@ rx_off(void)
/* Continue nonetheless */ /* Continue nonetheless */
} }
while(rf_is_on()); LIMITED_BUSYWAIT(rf_is_on(), RF_TURN_OFF_WAIT_TIMEOUT);
if(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) == IEEE_DONE_STOPPED || if(RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) == IEEE_DONE_STOPPED ||
RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) == IEEE_DONE_ABORT) { RF_RADIO_OP_GET_STATUS(cmd_ieee_rx_buf) == IEEE_DONE_ABORT) {
@ -739,8 +748,8 @@ soft_off(void)
return; return;
} }
while((cmd->status & RF_CORE_RADIO_OP_MASKED_STATUS) == LIMITED_BUSYWAIT((cmd->status & RF_CORE_RADIO_OP_MASKED_STATUS) ==
RF_CORE_RADIO_OP_MASKED_STATUS_RUNNING); RF_CORE_RADIO_OP_MASKED_STATUS_RUNNING, RF_TURN_OFF_WAIT_TIMEOUT);
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static uint8_t static uint8_t