radio/nrf802154: fix set_cca_threshold range

This commit fixes the CCA threshold range for set_cca_threshold.
Without this commit the threshold overflows when using values below
the receiver sensitivity.
This commit is contained in:
Jose Alamos 2020-12-15 13:32:07 +01:00 committed by Jose Alamos
parent 2bf10413d0
commit f2fa3ca12f
No known key found for this signature in database
GPG Key ID: F483EB800EF89DD9

View File

@ -279,15 +279,6 @@ static int _request_cca(ieee802154_dev_t *dev)
return 0;
}
/**
* @brief Set CCA threshold value in internal represetion
*/
static void _set_cca_thresh(uint8_t thresh)
{
NRF_RADIO->CCACTRL &= ~RADIO_CCACTRL_CCAEDTHRES_Msk;
NRF_RADIO->CCACTRL |= thresh << RADIO_CCACTRL_CCAEDTHRES_Pos;
}
/**
* @brief Convert from dBm to the internal representation, when the
* radio operates as a IEEE802.15.4 transceiver.
@ -300,7 +291,15 @@ static inline uint8_t _dbm_to_ieee802154_hwval(int8_t dbm)
static int set_cca_threshold(ieee802154_dev_t *dev, int8_t threshold)
{
(void) dev;
_set_cca_thresh(_dbm_to_ieee802154_hwval(threshold));
if (threshold < ED_RSSIOFFS) {
return -EINVAL;
}
uint8_t hw_val = _dbm_to_ieee802154_hwval(threshold);
NRF_RADIO->CCACTRL &= ~RADIO_CCACTRL_CCAEDTHRES_Msk;
NRF_RADIO->CCACTRL |= hw_val << RADIO_CCACTRL_CCAEDTHRES_Pos;
return 0;
}