diff --git a/cpu/nrf5x_common/radio/nrfble/nrfble.c b/cpu/nrf5x_common/radio/nrfble/nrfble.c index f66f52c4f6..ba08feeb0f 100644 --- a/cpu/nrf5x_common/radio/nrfble/nrfble.c +++ b/cpu/nrf5x_common/radio/nrfble/nrfble.c @@ -120,6 +120,16 @@ static const uint8_t _ble_chan_map[40] = { [39] = 80, }; +/** + * @brief Enable the radio + */ +static void _enable(void) +{ + clock_hfxo_request(); + NRF_RADIO->EVENTS_DISABLED = 0; + NRF_RADIO->INTENSET = INT_EN; +} + /** * @brief Set radio into idle (DISABLED) state */ @@ -131,6 +141,7 @@ static void _go_idle(void) NRF_RADIO->EVENTS_DISABLED = 0; NRF_RADIO->TASKS_DISABLE = 1; while (NRF_RADIO->EVENTS_DISABLED == 0) {} + clock_hfxo_release(); _state = STATE_IDLE; } } @@ -239,12 +250,8 @@ static int _nrfble_init(netdev_t *dev) (void)dev; assert(_nrfble_dev.driver && _nrfble_dev.event_callback); - /* the radio need the external HF clock source to be enabled */ - /* @todo add proper handling to release the clock whenever the radio is - * idle */ - clock_hfxo_request(); - - /* power on the NRFs radio */ + /* power cycle the radio to reset it */ + NRF_RADIO->POWER = 0; NRF_RADIO->POWER = 1; /* configure variable parameters to default values */ NRF_RADIO->TXPOWER = NRFBLE_TXPOWER_DEFAULT; @@ -286,8 +293,7 @@ static int _nrfble_send(netdev_t *dev, const iolist_t *data) /* in case no trx sequence is active, we start a new one now */ if (_state == STATE_IDLE) { _state = STATE_TX; - NRF_RADIO->EVENTS_DISABLED = 0; - NRF_RADIO->INTENSET = INT_EN; + _enable(); NRF_RADIO->TASKS_TXEN = 1; } @@ -307,8 +313,7 @@ static int _nrfble_recv(netdev_t *dev, void *buf, size_t len, void *info) /* in case no trx sequence is active, we start a new one now */ if (_state == STATE_IDLE) { _state = STATE_RX; - NRF_RADIO->EVENTS_DISABLED = 0; - NRF_RADIO->INTENSET = INT_EN; + _enable(); NRF_RADIO->TASKS_RXEN = 1; }