Skip to content

Commit 2570119

Browse files
adamkondraciukgmarull
authored andcommitted
[nrf fromlist] drivers: timer: grtc: Fix ticks calculation for GRTC
Fixed calculation of GRTC ticks inside `z_nrf_grtc_timer_get_ticks()` function. Upstream PR: zephyrproject-rtos/zephyr#71688 Signed-off-by: Adam Kondraciuk <[email protected]>
1 parent 6c515dd commit 2570119

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

drivers/timer/nrf_grtc_timer.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,21 @@ uint64_t z_nrf_grtc_timer_get_ticks(k_timeout_t t)
319319
int64_t curr_tick;
320320
int64_t result;
321321
int64_t abs_ticks;
322+
int64_t grtc_ticks;
322323

323324
curr_time = counter();
324325
curr_tick = sys_clock_tick_get();
325326

327+
grtc_ticks = t.ticks * CYC_PER_TICK;
326328
abs_ticks = Z_TICK_ABS(t.ticks);
327329
if (abs_ticks < 0) {
328330
/* relative timeout */
329-
return (t.ticks > (int64_t)COUNTER_SPAN) ? -EINVAL : (curr_time + t.ticks);
331+
return (grtc_ticks > (int64_t)COUNTER_SPAN) ?
332+
-EINVAL : (curr_time + grtc_ticks);
330333
}
331334

332335
/* absolute timeout */
333-
result = abs_ticks - curr_tick;
336+
result = (abs_ticks - curr_tick) * CYC_PER_TICK;
334337

335338
if (result > (int64_t)COUNTER_SPAN) {
336339
return -EINVAL;

include/zephyr/drivers/timer/nrf_grtc_timer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ uint64_t z_nrf_grtc_timer_compare_read(int32_t chan);
111111
*
112112
* @param chan Channel ID.
113113
*
114-
* @param target_time Absolute target time in ticks.
114+
* @param target_time Absolute target time in GRTC ticks.
115115
*
116116
* @param handler User function called in the context of the GRTC interrupt.
117117
*

0 commit comments

Comments
 (0)