diff --git a/examples/twr_aloha/control.c b/examples/twr_aloha/control.c index 822dbe4669..2553cb613c 100644 --- a/examples/twr_aloha/control.c +++ b/examples/twr_aloha/control.c @@ -289,3 +289,9 @@ void uwb_core_rng_init(void) uwb_sleep_config(_udev); uwb_enter_sleep(_udev); } + +uint32_t uwb_core_rng_req_remaining(void) +{ + /* doesn't matter if its not atomic */ + return _rng_request_event.periodic.count; +} diff --git a/examples/twr_aloha/control.h b/examples/twr_aloha/control.h index 50859f3880..f533b23f15 100644 --- a/examples/twr_aloha/control.h +++ b/examples/twr_aloha/control.h @@ -100,6 +100,11 @@ void uwb_core_rng_listen_disable(void); void uwb_core_rng_start(uint16_t addr, twr_protocol_t proto, uint32_t interval, uint32_t count); +/** + * @brief Returns remaining rng requests + */ +uint32_t uwb_core_rng_req_remaining(void); + #ifdef __cplusplus } #endif diff --git a/examples/twr_aloha/twr_shell.c b/examples/twr_aloha/twr_shell.c index edceb07caf..438fbd3e52 100644 --- a/examples/twr_aloha/twr_shell.c +++ b/examples/twr_aloha/twr_shell.c @@ -181,7 +181,11 @@ int _twr_handler(int argc, char **argv) puts("[twr]: start ranging"); uwb_core_rng_start(short_addr, proto, interval_ms, count); if (IS_ACTIVE(CONFIG_TWR_SHELL_BLOCKING)) { - ztimer_sleep(ZTIMER_MSEC, interval_ms * (count + 1)); + while (uwb_core_rng_req_remaining()) { + ztimer_sleep(ZTIMER_MSEC, interval_ms); + } + /* some time to finish up */ + ztimer_sleep(ZTIMER_MSEC, 100 + interval_ms); } return 0; }