

- Desktop task timer tutorial how to#
- Desktop task timer tutorial software#
- Desktop task timer tutorial code#
With the Timer task having the highest priority in the system, the queue can be smaller. Basically, the queue needs to hold as many command items which can be sent by other tasks (or interrupts) until they can be served by the Timer Task. The question might be: What is a useful length for that queue? Because the longer it is, the more RAM is used. The length of the queue can be configured with the following macro, while the name of the queue “TmrQ” is hard-coded in the RTOS: #define configTIMER_QUEUE_LENGTH 10 This queue is used for IPC (Inter-Process Communication) between the timer task and the other tasks of the system. The other thing that gets created is a queue for the timer task, named ‘TmrQ’: To find out what your tasks are using on the stack, see Understanding FreeRTOS Task Stack Usage and Kernel awareness Information. The timer stack size really depends on what you are doing in the timer hooks called from the timer task. I recommend giving the timer task the highest task priority in the system, otherwise, you will see some latency in the timer hook execution. #define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE * 2) #define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) The timer task name, priority and stack size can be configured with the following macros in FreeRTOSConfig.h #define configTIMER_SERVICE_TASK_NAME "Tmr Svc" Basically, it checks if a timer has been expired and calls the associated timer hook.
Desktop task timer tutorial software#
This timer task is responsible to handle all FreeRTOS software timers in the system. In the above screenshot (Event Object column) you can see as well that the Tmr Svc is waiting for receiving an object in the TmrQ queue. Because this creates the ‘Tmr Svc’ task during vTaskStartScheduler(): If you are not using FreeRTOS software timers, set that macro to 0, otherwise, your application is using more resources than necessary. To use FreeRTOS timers, you have to turn them on with the following entry in FreeRTOSConfig.h: #define configUSE_TIMERS 1 Auto-Reload: This timer will automatically be restarted when it expires, making it ideal for periodic kinds of things.Making it ideal for a ‘one-shot’ kind of thing. One-Shot: When the timer expires, it is not restarted again.One-Shot and Auto-ReloadįreeRTOS software timers support two different software timer, configured at timer creation time:

And that way, the Timer API has parameters like ‘ticksToWait’ to specify the waiting time if the timer queue is full. The Timer Task will wake up when something is sent to that queue. Using that queue, other tasks can send commands to the timer task, for example, to start or stop a timer. The other concept the Timer task is using is a queue: this queue is used for inter-process communication. When a timer has expired, the Timer Service task calls its callback (the Timer callback). The Timer Service task is not continuously running: from the Timer List, the task knows the time when it has to wake up each time a timer in the timer list has expired. There is a dedicated Tmr Svc (Timer Service or Deamon) task that maintains an ordered list of software timers, with the timer to expire next in front of the list). The following diagram gives an overview, how Software Timers in FreeRTOS are implemented: I’m using MCUXpresso IDE 10.0.2 and FreeRTOS 10.0.1 in this article.

Desktop task timer tutorial code#
If you want to add the code used in this tutorial to your own project, make sure you have a working FreeRTOS project first. I have put the example code in a project on GitHub (MCUXpresso IDE, but applicable for any other IDE, too).
Desktop task timer tutorial how to#
In this tutorial, I show how to create FreeRTOS software timers and how to use them. The good news is that there is a much more efficient way to do this in FreeRTOS with software timers. However, using a task might be too much overhead doing this.

With using an RTOS, I can do a similar thing using a task: The task will run with a given frequency and I can periodically work in it. Hardware timers are essential to most embedded applications: I use them mostly for triggering actions at a given frequency, such as acquiring data from a sensor.
