Skip to content

Commit

Permalink
tests/sys/event_ztimer: add event_periodic_start_now() to test
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian18 committed Oct 14, 2024
1 parent 90473c6 commit d4cd708
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tests/sys/event_ztimer/main.c
Original file line number Diff line number Diff line change
@@ -64,10 +64,9 @@ static void callback_4times(void *arg)
uint8_t *count = (uint8_t *)arg;

*count = *count + 1;
uint32_t now = event_periodic.timer.last;
uint32_t now = ztimer_now(ZTIMER_USEC);
uint32_t elapsed = now - before;
before = now;
expect((elapsed) >= 1 * US_PER_SEC);
if (*count <= 4) {
printf("trigger %d of periodic timeout, elapsed time: %" PRIu32 " us\n",
*count, elapsed);
@@ -110,8 +109,15 @@ int main(void)
event_periodic_init(&event_periodic, ZTIMER_USEC, EVENT_PRIO_MEDIUM,
&event_4times.super);
event_periodic_set_count(&event_periodic, 4);
before = ztimer_now(ZTIMER_USEC);
event_periodic_start(&event_periodic, EVENT_TIMEOUT_TIME);
before = event_periodic.timer.last;
puts("waiting for periodic callback to be triggered 4 times");
mutex_lock(&lock);
puts("posting periodic timed callback with timeout 1sec and no delay");
event_periodic_set_count(&event_periodic, 4);
iter = 0; /* reset callback argument counter to 0 */
before = ztimer_now(ZTIMER_USEC);
event_periodic_start_now(&event_periodic, EVENT_TIMEOUT_TIME);
puts("waiting for periodic callback to be triggered 4 times");
mutex_lock(&lock);
puts("posting timed callback with timeout 0.5sec, clear right after");

0 comments on commit d4cd708

Please sign in to comment.