I have some input. I’m looking for the functionality which the FreeRTOS function implements. FreeRTOS calculates the time to sleep based on the previous waking time, and updates the pointed variable accordingly.
“Pointer to a variable that holds the time at which the task was last unblocked. The variable must be initialised with the current time prior to its first use (see the example below). Following this the variable is automatically updated within vTaskDelayUntil().”
This ensures that one call to the function each loop makes the function run with a chosen frequency.
doing something periodical is unfortunately so far RIOT is not super friendly with. This is due to the fact that RIOT is designed around a tickless-scheduling design, which means we don’t have means to find out in which point of time a thread started to run and we don’t have a ``discrete system time in ticks as in FreeRTOS. This means, that we can not (easily) just substract some offset ticks from a sleep value.
For the long-term we are planning to remodel our timer architecture, and it is planned to introduce something as timer_msg_periodic(..) to send periodic messages from the timer to a task.
For now I would suggest the following solution to your problem (although it introduces a little overhead):
Let your function that you need to run periodically run in it’s own thread, something like this:
It is very important, that the timer_thread has the higher priority. I don’t know about your specific applications and the requirements you have on the precision of the timing. To improve this, you can use the OFFSET to compensate for the scheduling delay of the timer thread - best measure this our for your concrete platform.
Hope this helps, let me know if there are any questions!