Skip to content

Commit

Permalink
[nrf fromlist] tests: drivers: timer: grtc: Fix GRTC test
Browse files Browse the repository at this point in the history
The `z_nrf_grtc_timer_get_ticks()` function converts system ticks
to GRTC ticks. It gets the current system tick to calculate an
absolute GRTC value. The same does the test function to provide
an argument to be converted. If the system tick occurs between those
`sys_clock_tick_get()` calls the `z_nrf_grtc_timer_get_ticks()` will
take into account the newer tick while the test estimate bases on
the old tick value. Due to that the maximum result error is 1 system
tick minus 1 GRTC tick which equals (`CYC_PER_TICK` - 1) for GRTC
ticks.

Upstream PR: zephyrproject-rtos/zephyr#71688

Signed-off-by: Adam Kondraciuk <[email protected]>
  • Loading branch information
adamkondraciuk authored and nordicjm committed May 16, 2024
1 parent 25fbeab commit 1a8f9cb
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/drivers/timer/nrf_grtc_timer/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ ZTEST(nrf_grtc_timer, test_get_ticks)
zassert_true((ticks >= exp_ticks) && (ticks <= (exp_ticks + GRTC_SLEW_TICKS)),
"Unexpected result %" PRId64 " (expected: %" PRId64 ")", ticks, exp_ticks);

k_msleep(1);

for (uint32_t i = 0; i < NUMBER_OF_TRIES; i++) {
/* Absolute timeout 1ms in the past */
t = Z_TIMEOUT_TICKS(Z_TICK_ABS(sys_clock_tick_get() - K_MSEC(1).ticks));
Expand Down

0 comments on commit 1a8f9cb

Please sign in to comment.