drivers: ieee802154_nrf5: Implement energy scan function of the nrf5 driver
Implement function and necessary callbacks to handle Energy Scan feature of the nRF radio driver needed by some radio stacks. Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
This commit is contained in:
parent
5c57f382de
commit
4ca9b42fbe
2 changed files with 54 additions and 1 deletions
|
@ -145,7 +145,8 @@ drop:
|
|||
static enum ieee802154_hw_caps nrf5_get_capabilities(struct device *dev)
|
||||
{
|
||||
return IEEE802154_HW_FCS | IEEE802154_HW_2_4_GHZ |
|
||||
IEEE802154_HW_TX_RX_ACK | IEEE802154_HW_FILTER;
|
||||
IEEE802154_HW_TX_RX_ACK | IEEE802154_HW_FILTER |
|
||||
IEEE802154_HW_ENERGY_SCAN;
|
||||
}
|
||||
|
||||
|
||||
|
@ -183,6 +184,28 @@ static int nrf5_set_channel(struct device *dev, u16_t channel)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int nrf5_energy_scan_start(struct device *dev,
|
||||
u16_t duration,
|
||||
energy_scan_done_cb_t done_cb)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
ARG_UNUSED(dev);
|
||||
|
||||
if (nrf5_data.energy_scan_done == NULL) {
|
||||
nrf5_data.energy_scan_done = done_cb;
|
||||
|
||||
if (nrf_802154_energy_detection(duration * 1000) == false) {
|
||||
nrf5_data.energy_scan_done = NULL;
|
||||
err = -EPERM;
|
||||
}
|
||||
} else {
|
||||
err = -EALREADY;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int nrf5_set_pan_id(struct device *dev, u16_t pan_id)
|
||||
{
|
||||
u8_t pan_id_le[2];
|
||||
|
@ -541,6 +564,28 @@ void nrf_802154_cca_failed(nrf_802154_cca_error_t error)
|
|||
k_sem_give(&nrf5_data.cca_wait);
|
||||
}
|
||||
|
||||
void nrf_802154_energy_detected(uint8_t result)
|
||||
{
|
||||
if (nrf5_data.energy_scan_done != NULL) {
|
||||
s16_t dbm;
|
||||
energy_scan_done_cb_t callback = nrf5_data.energy_scan_done;
|
||||
|
||||
nrf5_data.energy_scan_done = NULL;
|
||||
dbm = nrf_802154_dbm_from_energy_level_calculate(result);
|
||||
callback(net_if_get_device(nrf5_data.iface), dbm);
|
||||
}
|
||||
}
|
||||
|
||||
void nrf_802154_energy_detection_failed(nrf_802154_ed_error_t error)
|
||||
{
|
||||
if (nrf5_data.energy_scan_done != NULL) {
|
||||
energy_scan_done_cb_t callback = nrf5_data.energy_scan_done;
|
||||
|
||||
nrf5_data.energy_scan_done = NULL;
|
||||
callback(net_if_get_device(nrf5_data.iface), SHRT_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
static const struct nrf5_802154_config nrf5_radio_cfg = {
|
||||
.irq_config_func = nrf5_irq_config,
|
||||
};
|
||||
|
@ -556,6 +601,9 @@ static struct ieee802154_radio_api nrf5_radio_api = {
|
|||
.start = nrf5_start,
|
||||
.stop = nrf5_stop,
|
||||
.tx = nrf5_tx,
|
||||
#ifdef CONFIG_NET_L2_OPENTHREAD
|
||||
.ed_scan = nrf5_energy_scan_start,
|
||||
#endif /* CONFIG_NET_L2_OPENTHREAD */
|
||||
.configure = nrf5_configure,
|
||||
};
|
||||
|
||||
|
|
|
@ -65,6 +65,11 @@ struct nrf5_802154_data {
|
|||
* ACK was requested/received.
|
||||
*/
|
||||
struct nrf5_802154_rx_frame ack_frame;
|
||||
|
||||
/* Callback handler of the currently ongoing energy scan.
|
||||
* It shall be NULL if energy scan is not in progress.
|
||||
*/
|
||||
energy_scan_done_cb_t energy_scan_done;
|
||||
};
|
||||
|
||||
#endif /* ZEPHYR_DRIVERS_IEEE802154_IEEE802154_NRF5_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue