Skip to content

Commit f878f9a

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 f878f9a

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

subsys/bluetooth/services/fast_pair/fmdn/Kconfig

+18
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,24 @@ 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+
254+
The kernel uptime does not persist for devices from the nRF54H series even
255+
though they use the GRTC timer as the system clock source. The workaround
256+
is not applied for this device series.
257+
240258
endif # BT_FAST_PAIR_FMDN_CLOCK
241259

242260
config BT_FAST_PAIR_FMDN_DULT

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

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Nordic Semiconductor ASA
2+
* Copyright (c) 2024-2025 Nordic Semiconductor ASA
33
*
44
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
55
*/
@@ -17,6 +17,7 @@ LOG_MODULE_REGISTER(fp_fmdn_clock, CONFIG_BT_FAST_PAIR_LOG_LEVEL);
1717
#include "fp_storage_clock.h"
1818

1919
static uint32_t storage_clock_boot_checkpoint;
20+
static int64_t uptime_on_boot;
2021

2122
static void fmdn_clock_storage_work_handle(struct k_work *work);
2223

@@ -33,6 +34,14 @@ static uint32_t fmdn_clock_read(void)
3334
/* Calculate elapsed time since bootup. */
3435
sys_uptime = k_uptime_get();
3536

37+
/* Ensure that uptime starts from zero after a system reset by subtracting
38+
* the timestamp during the system initialization.
39+
*/
40+
if (IS_ENABLED(CONFIG_BT_FAST_PAIR_FMDN_CLOCK_UPTIME_PERSISTENCE)) {
41+
__ASSERT_NO_MSG(sys_uptime >= uptime_on_boot);
42+
sys_uptime -= uptime_on_boot;
43+
}
44+
3645
/* Convert from milliseconds to seconds. */
3746
sys_uptime /= MSEC_PER_SEC;
3847

@@ -156,3 +165,18 @@ FP_ACTIVATION_MODULE_REGISTER(fp_fmdn_clock,
156165
FP_ACTIVATION_INIT_PRIORITY_DEFAULT,
157166
fp_fmdn_clock_init,
158167
fp_fmdn_clock_uninit);
168+
169+
#if defined(CONFIG_BT_FAST_PAIR_FMDN_CLOCK_UPTIME_PERSISTENCE)
170+
static int bt_fast_pair_fmdn_clock_uptime_persistence_workaround_init(void)
171+
{
172+
uptime_on_boot = k_uptime_get();
173+
174+
return 0;
175+
}
176+
177+
/* Define the system initialization hook with the priority level that is executed as closely
178+
* as possible to the kernel initialization. The kernel uptime value should be read as soon
179+
* as possible after the kernel starts to increase accuracy of the FMDN clock.
180+
*/
181+
SYS_INIT(bt_fast_pair_fmdn_clock_uptime_persistence_workaround_init, POST_KERNEL, 0);
182+
#endif /* defined(CONFIG_BT_FAST_PAIR_FMDN_CLOCK_UPTIME_PERSISTENCE) */

0 commit comments

Comments
 (0)