Skip to content

Commit 3298145

Browse files
committed
bluetooth: fast_pair: fmdn: add uptime workaround to the clock module
Added the kernel uptime workaround to the clock module in the FMDN extension that is part of the Fast Pair library. Applied the workaround for the kernel uptime persistence after a system reset. The FMDN clock module assumes that the kernel uptime starts from zero after the system reboot. Activated the workaround only for devices from the nRF54L series that use the GRTC timer as the system clock source (the default configuration). For this configuration, the kernel uptime persists after a system reset if the reset reason is of a specific type, such as a software reset (for example, triggered by the sys_reboot API). Ref: NCSDK-32268 Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
1 parent 4be6ae8 commit 3298145

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

subsys/bluetooth/services/fast_pair/fmdn/Kconfig

+14
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,20 @@ config BT_FAST_PAIR_FMDN_CLOCK_NVM_UPDATE_RETRY_TIME
237237
determine the next storage attempt in case of a storage operation
238238
failure.
239239

240+
config BT_FAST_PAIR_FMDN_CLOCK_UPTIME_PERSISTENCE
241+
bool
242+
default y if NRF_GRTC_TIMER && SOC_SERIES_NRF54LX
243+
help
244+
Apply the workaround for the kernel uptime persistence after a system reset.
245+
The FMDN clock module assumes that the kernel uptime starts from zero after
246+
the system reboot.
247+
248+
Activate the workaround only for devices from the nRF54L series that use the
249+
GRTC timer as the system clock source (the default configuration). For this
250+
configuration, the kernel uptime persists after a system reset if the reset
251+
reason is of a specific type, such as a software reset (for example, triggered
252+
by the sys_reboot API).
253+
240254
endif # BT_FAST_PAIR_FMDN_CLOCK
241255

242256
config BT_FAST_PAIR_FMDN_DULT

subsys/bluetooth/services/fast_pair/fmdn/clock.c

+26
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ LOG_MODULE_REGISTER(fp_fmdn_clock, CONFIG_BT_FAST_PAIR_LOG_LEVEL);
1616
#include "fp_fmdn_clock.h"
1717
#include "fp_storage_clock.h"
1818

19+
/* Priority level for initializing the workaround for persistence of the kernel uptime.
20+
* Used only when the CONFIG_BT_FAST_PAIR_FMDN_CLOCK_UPTIME_PERSISTENCE Kconfig is enabled.
21+
*/
22+
#define CONFIG_BT_FAST_PAIR_FMDN_CLOCK_UPTIME_PERSISTENCE_WORKAROUND_INIT_PRIORITY 0
23+
1924
static uint32_t storage_clock_boot_checkpoint;
25+
static int64_t uptime_persistence_init_clock;
2026

2127
static void fmdn_clock_storage_work_handle(struct k_work *work);
2228

@@ -33,6 +39,14 @@ static uint32_t fmdn_clock_read(void)
3339
/* Calculate elapsed time since bootup. */
3440
sys_uptime = k_uptime_get();
3541

42+
/* Ensure that uptime starts from zero after a system reset by subtracting
43+
* the timestamp during the system initialization.
44+
*/
45+
if (IS_ENABLED(CONFIG_BT_FAST_PAIR_FMDN_CLOCK_UPTIME_PERSISTENCE)) {
46+
__ASSERT_NO_MSG(sys_uptime >= uptime_persistence_init_clock);
47+
sys_uptime -= uptime_persistence_init_clock;
48+
}
49+
3650
/* Convert from milliseconds to seconds. */
3751
sys_uptime /= MSEC_PER_SEC;
3852

@@ -156,3 +170,15 @@ FP_ACTIVATION_MODULE_REGISTER(fp_fmdn_clock,
156170
FP_ACTIVATION_INIT_PRIORITY_DEFAULT,
157171
fp_fmdn_clock_init,
158172
fp_fmdn_clock_uninit);
173+
174+
#if defined(CONFIG_BT_FAST_PAIR_FMDN_CLOCK_UPTIME_PERSISTENCE)
175+
static int bt_fast_pair_fmdn_clock_uptime_persistence_workaround_init(void)
176+
{
177+
uptime_persistence_init_clock = k_uptime_get();
178+
179+
return 0;
180+
}
181+
182+
SYS_INIT(bt_fast_pair_fmdn_clock_uptime_persistence_workaround_init, POST_KERNEL,
183+
CONFIG_BT_FAST_PAIR_FMDN_CLOCK_UPTIME_PERSISTENCE_WORKAROUND_INIT_PRIORITY);
184+
#endif /* defined(CONFIG_BT_FAST_PAIR_FMDN_CLOCK_UPTIME_PERSISTENCE) */

0 commit comments

Comments
 (0)