Skip to content

Commit 36e0fa7

Browse files
ankunsrlubos
authored andcommitted
[nrf noup] drivers: ieee802154_nrf5: add timeout for energy detection
The energy detection is guarded by additional timer. The callback timeout is duration+CONFIG_IEEE802154_NRF5_CALLOUT_TIMEOUT_MS Signed-off-by: Andrzej Kuros <[email protected]>
1 parent 4acb098 commit 36e0fa7

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

drivers/ieee802154/ieee802154_nrf5.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,15 @@ FUNC_NORETURN static void nrf5_callback_timeout(void)
246246
CODE_UNREACHABLE;
247247
}
248248

249+
#if (CONFIG_IEEE802154_NRF5_CALLOUT_TIMEOUT_MS != 0)
250+
static void ed_timer_expired(struct k_timer *timer)
251+
{
252+
ARG_UNUSED(timer);
253+
254+
nrf5_callback_timeout();
255+
}
256+
#endif /* CONFIG_IEEE802154_NRF5_CALLOUT_TIMEOUT_MS != 0 */
257+
249258
static void nrf5_callback_sem_take(struct k_sem *sem, uint32_t additional_ms)
250259
{
251260
if (CONFIG_IEEE802154_NRF5_CALLOUT_TIMEOUT_MS == 0) {
@@ -306,6 +315,14 @@ static int nrf5_energy_scan_start(const struct device *dev,
306315
if (nrf_802154_energy_detection(duration * 1000) == false) {
307316
nrf5_data.energy_scan_done = NULL;
308317
err = -EPERM;
318+
} else {
319+
#if (CONFIG_IEEE802154_NRF5_CALLOUT_TIMEOUT_MS != 0)
320+
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
321+
322+
k_timer_start(&nrf5_radio->ed_timer,
323+
K_MSEC(duration + CONFIG_IEEE802154_NRF5_CALLOUT_TIMEOUT_MS),
324+
K_NO_WAIT);
325+
#endif
309326
}
310327
} else {
311328
err = -EALREADY;
@@ -807,6 +824,10 @@ static int nrf5_init(const struct device *dev)
807824
k_sem_init(&nrf5_radio->tx_wait, 0, 1);
808825
k_sem_init(&nrf5_radio->cca_wait, 0, 1);
809826

827+
#if (CONFIG_IEEE802154_NRF5_CALLOUT_TIMEOUT_MS != 0)
828+
k_timer_init(&nrf5_radio->ed_timer, ed_timer_expired, NULL);
829+
#endif
830+
810831
nrf_802154_init();
811832

812833
nrf5_get_capabilities_at_boot();
@@ -1168,6 +1189,10 @@ void nrf_802154_energy_detected(uint8_t result)
11681189
int16_t dbm;
11691190
energy_scan_done_cb_t callback = nrf5_data.energy_scan_done;
11701191

1192+
#if (CONFIG_IEEE802154_NRF5_CALLOUT_TIMEOUT_MS != 0)
1193+
k_timer_stop(&nrf5_data.ed_timer);
1194+
#endif
1195+
11711196
nrf5_data.energy_scan_done = NULL;
11721197
dbm = nrf_802154_dbm_from_energy_level_calculate(result);
11731198
callback(net_if_get_device(nrf5_data.iface), dbm);
@@ -1179,6 +1204,10 @@ void nrf_802154_energy_detection_failed(nrf_802154_ed_error_t error)
11791204
if (nrf5_data.energy_scan_done != NULL) {
11801205
energy_scan_done_cb_t callback = nrf5_data.energy_scan_done;
11811206

1207+
#if (CONFIG_IEEE802154_NRF5_CALLOUT_TIMEOUT_MS != 0)
1208+
k_timer_stop(&nrf5_data.ed_timer);
1209+
#endif
1210+
11821211
nrf5_data.energy_scan_done = NULL;
11831212
callback(net_if_get_device(nrf5_data.iface), SHRT_MAX);
11841213
}

drivers/ieee802154/ieee802154_nrf5.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ struct nrf5_802154_data {
7676
*/
7777
energy_scan_done_cb_t energy_scan_done;
7878

79+
#if (CONFIG_IEEE802154_NRF5_CALLOUT_TIMEOUT_MS != 0)
80+
/* Timer allowing to detect timeout of energy scan operation */
81+
struct k_timer ed_timer;
82+
#endif
83+
7984
/* Callback handler to notify of any important radio events.
8085
* Can be NULL if event notification is not needed.
8186
*/

0 commit comments

Comments
 (0)