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:
parent
ff80c0b926
commit
b4047307fa
2 changed files with 6 additions and 3 deletions
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue