Skip to content

Commit 5ea95c3

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 e5b15c7 commit 5ea95c3

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))) && \
@@ -153,12 +158,21 @@ static void compare_int_unlock(int32_t chan, bool key)
153158
}
154159
}
155160

161+
static void sys_event_unregister(bool canceled)
162+
{
163+
if (IS_ENABLED(USE_SYS_EVENT) && (sys_evt_handle >= 0)) {
164+
nrf_sys_event_unregister(sys_evt_handle, canceled);
165+
sys_evt_handle = -1;
166+
}
167+
}
168+
156169
static void sys_clock_timeout_handler(int32_t id, uint64_t cc_val, void *p_context)
157170
{
158171
ARG_UNUSED(id);
159172
ARG_UNUSED(p_context);
160173
uint32_t dticks;
161174

175+
sys_event_unregister(false);
162176
dticks = counter_sub(cc_val, last_count) / CYC_PER_TICK;
163177
last_count += (dticks * CYC_PER_TICK);
164178
expired_cc = cc_val;
@@ -591,8 +605,10 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
591605
return;
592606
}
593607

608+
bool sys_evt = ticks <= 30;
594609
uint32_t ch = system_clock_channel_data.channel;
595610

611+
sys_event_unregister(true);
596612
if ((cc_value == expired_cc) && (ticks <= MAX_REL_TICKS)) {
597613
uint32_t cyc = ticks * CYC_PER_TICK;
598614

@@ -609,6 +625,9 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
609625
* is short so fast method can be used which utilizes relative CC configuration.
610626
*/
611627
cc_value += cyc;
628+
if (IS_ENABLED(USE_SYS_EVENT)) {
629+
sys_evt_handle = sys_evt ? nrf_sys_event_register(cyc, false) : -1;
630+
}
612631
nrfx_grtc_syscounter_cc_rel_set(ch, cyc, NRFX_GRTC_CC_RELATIVE_COMPARE);
613632
return;
614633
}
@@ -631,6 +650,9 @@ void sys_clock_set_timeout(int32_t ticks, bool idle)
631650
safe_setting = (int64_t)(prev_cc_val - now) < LATENCY_THR_TICKS;
632651
}
633652

653+
if (IS_ENABLED(USE_SYS_EVENT)) {
654+
sys_evt_handle = sys_evt ? nrf_sys_event_abs_register(cc_value, false) : -1;
655+
}
634656
nrfx_grtc_syscounter_cc_abs_set(ch, cc_value, safe_setting);
635657
}
636658

0 commit comments

Comments
 (0)