Re: Drift through k_sleep or k_msleep #api
Michael Rosen
Nick,
The design pattern Ive seen for this kind of thing uses the Timer API instead of sleep:
struct k_timer timer; k_timer_init(&timer, NULL, NULL); … k_timer_start(&timer, 0, K_MSEC(1000)); while (1) { k_timer_status_sync(&timer); … }
This lets the body of the main loop run only when the timer expires, and the periodic timer avoid drift from resetting the timer at the top of each loop.
Mike
From: users@... <users@...>
On Behalf Of Erik Englund
Sent: Wednesday, February 3, 2021 2:38 PM To: Nikolaus Huber <nikolaus.huber@...> Cc: users@... Subject: Re: [Zephyr-users] Drift through k_sleep or k_msleep #api
One possible solution is to create a periodic timer and post to a semaphore in the timer callback. A thread could simply wait on the semaphore in an endless loop.
Linux clock_nanosleep (mostly used togheter with Preempt-rt patch) would be a nice addition to Zephyr, that would solve these kinds of tasks.
Med vänlig hälsning Erik Englund
Den ons 3 feb. 2021 kl 20:31 skrev Nikolaus Huber <nikolaus.huber@...>:
|
|