Skip to content

Commit cf7594e

Browse files
ppryga-nordicrlubos
authored andcommitted
bluetooth: host_extension: RTCx time diff may be negative
Radio notification callback host extension checks the offset between system clock and second RTC instance. The implementation assumes given order of RTCx startup. To remove the constraint use singed integer to store time difference. Also an assert that enforces the time difference to be larger or equal to zero. Signed-off-by: Piotr Pryga <[email protected]>
1 parent 30bd02b commit cf7594e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

subsys/bluetooth/host_extensions/radio_notification_conn_cb.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
#if defined(CONFIG_SOC_COMPATIBLE_NRF52X) || defined(CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET)
1414
#include <hal/nrf_rtc.h>
15-
static uint32_t sys_clock_start_to_bt_clk_start_us;
15+
/* Use signed integer to allow to get time difference no matter of order in which RTCx instances
16+
* are started.
17+
*/
18+
static int32_t sys_clock_start_to_bt_clk_start_us;
1619
#endif
1720

1821
static uint32_t configured_prepare_distance_us;
@@ -91,7 +94,7 @@ static bool on_vs_evt(struct net_buf_simple *buf)
9194

9295
#if defined(CONFIG_SOC_COMPATIBLE_NRF52X) || defined(CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET)
9396
timer_trigger_us -= sys_clock_start_to_bt_clk_start_us;
94-
#endif
97+
#endif /* CONFIG_SOC_COMPATIBLE_NRF52X || CONFIG_SOC_COMPATIBLE_NRF5340_CPUNET */
9598

9699
/* Start/Restart a timer triggering every conn_interval_us from the last anchor point. */
97100
k_timer_start(&timers[conn_index], K_TIMEOUT_ABS_US(timer_trigger_us),
@@ -168,12 +171,10 @@ static int set_sys_clock_start_to_bt_clk_start_us(void)
168171
}
169172
}
170173

171-
const uint64_t rtc_ticks_in_femto_units = 30517578125UL;
172-
173-
__ASSERT_NO_MSG(ticks_difference >= 0);
174+
const int64_t rtc_ticks_in_femto_units = 30517578125L;
174175

175176
sys_clock_start_to_bt_clk_start_us =
176-
((ticks_difference * rtc_ticks_in_femto_units) / 1000000000UL);
177+
((ticks_difference * rtc_ticks_in_femto_units) / 1000000000L);
177178
return 0;
178179
}
179180

0 commit comments

Comments
 (0)