Skip to content

Commit 15ac1e2

Browse files
committed
[nrf fromlist] drivers: timer: nrf_grtc: Use nrf_sys_event registration
Use API for registering synchronous interrupts. It reduced interrupt latency due to NVM memory wake up. Upstream PR #: 99377 Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 4d30759 commit 15ac1e2

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

drivers/timer/nrf_grtc_timer.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <zephyr/drivers/timer/nrf_grtc_timer.h>
1616
#include <nrfx_grtc.h>
1717
#include <zephyr/sys/math_extras.h>
18+
#include <nrf_sys_event.h>
1819

1920
#define GRTC_NODE DT_NODELABEL(grtc)
2021
#define HFCLK_NODE DT_PHANDLE_BY_NAME(GRTC_NODE, clocks, hfclock)
@@ -82,6 +83,10 @@ static nrfx_grtc_channel_t system_clock_channel_data = {
8283
.p_context = NULL,
8384
.channel = (uint8_t)-1,
8485
};
86+
#if defined(CONFIG_NRF_SYS_EVENT_GRTC_CHAN_CNT) && (CONFIG_NRF_SYS_EVENT_GRTC_CHAN_CNT > 0)
87+
#define USE_SYS_EVENT 1
88+
#endif
89+
static int sys_evt_handle = -1;
8590

8691
#define IS_CHANNEL_ALLOWED_ASSERT(chan) \
8792
__ASSERT_NO_MSG((NRFX_GRTC_CONFIG_ALLOWED_CC_CHANNELS_MASK & (1UL << (chan))) && \
@@ -142,12 +147,21 @@ static void compare_int_unlock(int32_t chan, bool key)
142147
}
143148
}
144149

150+
static void sys_event_unregister(bool canceled)
151+
{
152+
if (IS_ENABLED(USE_SYS_EVENT) && (sys_evt_handle >= 0)) {
153+
nrf_sys_event_unregister(sys_evt_handle, canceled);
154+
sys_evt_handle = -1;
155+
}
156+
}
157+
145158
static void sys_clock_timeout_handler(int32_t id, uint64_t cc_val, void *p_context)
146159
{
147160
ARG_UNUSED(id);
148161
ARG_UNUSED(p_context);
149162
uint32_t dticks;
150163

164+
sys_event_unregister(false);
151165
dticks = counter_sub(cc_val, last_count) / CYC_PER_TICK;
152166
last_count += (dticks * CYC_PER_TICK);
153167
expired_cc = cc_val;
@@ -560,8 +574,10 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
560574
return;
561575
}
562576

577+
bool sys_evt = ticks <= 30;
563578
uint32_t ch = system_clock_channel_data.channel;
564579

580+
sys_event_unregister(true);
565581
if ((cc_value == expired_cc) && (ticks <= MAX_REL_TICKS)) {
566582
uint32_t cyc = ticks * CYC_PER_TICK;
567583

@@ -578,6 +594,9 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
578594
* is short so fast method can be used which utilizes relative CC configuration.
579595
*/
580596
cc_value += cyc;
597+
if (IS_ENABLED(USE_SYS_EVENT)) {
598+
sys_evt_handle = sys_evt ? nrf_sys_event_register(cyc, false) : -1;
599+
}
581600
nrfx_grtc_syscounter_cc_rel_set(ch, cyc, NRFX_GRTC_CC_RELATIVE_COMPARE);
582601
return;
583602
}
@@ -600,6 +619,9 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
600619
safe_setting = (int64_t)(prev_cc_val - now) < LATENCY_THR_TICKS;
601620
}
602621

622+
if (IS_ENABLED(USE_SYS_EVENT)) {
623+
sys_evt_handle = sys_evt ? nrf_sys_event_abs_register(cc_value, false) : -1;
624+
}
603625
nrfx_grtc_syscounter_cc_abs_set(ch, cc_value, safe_setting);
604626
}
605627

0 commit comments

Comments
 (0)