Add platform API to check state of the radio. (#1413)

This commit is contained in:
Hubert Miś
2017-03-08 05:17:06 -08:00
committed by Jonathan Hui
parent 1eb61a40f7
commit 6eaacdd4a4
4 changed files with 84 additions and 1 deletions
+28
View File
@@ -188,6 +188,34 @@ void nrf5RadioInit(void)
nrf_drv_radio802154_init();
}
PhyState otPlatRadioGetState(otInstance *aInstance)
{
(void) aInstance;
if (sDisabled)
{
return kStateDisabled;
}
switch (nrf_drv_radio802154_state_get())
{
case NRF_DRV_RADIO802154_STATE_SLEEP:
return kStateSleep;
case NRF_DRV_RADIO802154_STATE_RECEIVE:
case NRF_DRV_RADIO802154_STATE_ENERGY_DETECTION:
return kStateReceive;
case NRF_DRV_RADIO802154_STATE_TRANSMIT:
return kStateTransmit;
default:
assert(false); // Make sure driver returned valid state.
}
return kStateReceive; // It is the default state. Return it in case of unknown.
}
ThreadError otPlatRadioEnable(otInstance *aInstance)
{
(void) aInstance;
+13
View File
@@ -200,6 +200,19 @@ void otPlatRadioSetShortAddress(otInstance *aInstance, uint16_t aShortAddress);
*
*/
/**
* Get current state of the radio.
*
* This function is not required by OpenThread. It may be used for debugging and/or application-specific purposes.
*
* @note This function may be not implemented. It does not affect OpenThread.
*
* @param[in] aInstance The OpenThread instance structure.
*
* @return Current state of the radio.
*/
PhyState otPlatRadioGetState(otInstance *aInstance);
/**
* Enable the radio.
*
@@ -915,6 +915,31 @@ void nrf_drv_radio802154_init(void)
irq_init();
}
nrf_drv_radio802154_state_t nrf_drv_radio802154_state_get(void)
{
switch (m_state)
{
case RADIO_STATE_SLEEP:
return NRF_DRV_RADIO802154_STATE_SLEEP;
case RADIO_STATE_WAITING_RX_FRAME:
case RADIO_STATE_RX_HEADER:
case RADIO_STATE_RX_FRAME:
case RADIO_STATE_TX_ACK:
return NRF_DRV_RADIO802154_STATE_RECEIVE;
case RADIO_STATE_CCA:
case RADIO_STATE_TX_FRAME:
case RADIO_STATE_RX_ACK:
return NRF_DRV_RADIO802154_STATE_TRANSMIT;
case RADIO_STATE_ED:
return NRF_DRV_RADIO802154_STATE_ENERGY_DETECTION;
}
return NRF_DRV_RADIO802154_STATE_INVALID;
}
bool nrf_drv_radio802154_sleep(void)
{
bool result = true;
@@ -43,6 +43,18 @@
extern "C" {
#endif
/**
* @brief States of the driver.
*/
typedef enum
{
NRF_DRV_RADIO802154_STATE_INVALID,
NRF_DRV_RADIO802154_STATE_SLEEP,
NRF_DRV_RADIO802154_STATE_RECEIVE,
NRF_DRV_RADIO802154_STATE_TRANSMIT,
NRF_DRV_RADIO802154_STATE_ENERGY_DETECTION,
} nrf_drv_radio802154_state_t;
/**
* @brief Initialize 802.15.4 driver.
*
@@ -90,7 +102,7 @@ void nrf_drv_radio802154_short_address_set(const uint8_t *p_short_address);
/**
* @section Functions to request FSM transitions.
* @section Functions to request FSM transitions and check current state.
*
* receive() transmit()
* --------> -------->
@@ -103,6 +115,11 @@ void nrf_drv_radio802154_short_address_set(const uint8_t *p_short_address);
* Energy detection
*/
/**
* @brief Get current state of the radio.
*/
nrf_drv_radio802154_state_t nrf_drv_radio802154_state_get(void);
/**
* @brief Change radio state to Sleep.
*