drivers: timer: grtc: Fix ticks calculation for GRTC

Fixed calculation of GRTC ticks inside
`z_nrf_grtc_timer_get_ticks()` function.

Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no>
This commit is contained in:
Adam Kondraciuk 2024-01-29 15:04:01 +01:00 committed by Henrik Brix Andersen
commit b4047307fa
2 changed files with 6 additions and 3 deletions

View file

@ -332,18 +332,21 @@ uint64_t z_nrf_grtc_timer_get_ticks(k_timeout_t t)
int64_t curr_tick;
int64_t result;
int64_t abs_ticks;
int64_t grtc_ticks;
curr_time = counter();
curr_tick = sys_clock_tick_get();
grtc_ticks = t.ticks * CYC_PER_TICK;
abs_ticks = Z_TICK_ABS(t.ticks);
if (abs_ticks < 0) {
/* relative timeout */
return (t.ticks > (int64_t)COUNTER_SPAN) ? -EINVAL : (curr_time + t.ticks);
return (grtc_ticks > (int64_t)COUNTER_SPAN) ?
-EINVAL : (curr_time + grtc_ticks);
}
/* absolute timeout */
result = abs_ticks - curr_tick;
result = (abs_ticks - curr_tick) * CYC_PER_TICK;
if (result > (int64_t)COUNTER_SPAN) {
return -EINVAL;

View file

@ -113,7 +113,7 @@ int z_nrf_grtc_timer_compare_read(int32_t chan, uint64_t *val);
*
* @param chan Channel ID.
*
* @param target_time Absolute target time in ticks.
* @param target_time Absolute target time in GRTC ticks.
*
* @param handler User function called in the context of the GRTC interrupt.
*