![]() The next parameter with ‘pdTRUE’ requests an ‘auto-reload’ timer, which means the timer is a periodic one, and not a one-shot timer. The first parameter is a string for the timer name, followed by the timer (initial) period in RTOS timer ticks. VTimerCallback1SecExpired) /* callback */ To create a new timer, I use: timerHndl1Sec = xTimerCreate( TimerCallbackFunction_t pxCallbackFunction ) To create a new software timer, I need a timer handle for it: xTimerHandle timerHndl1Sec īelow is the API to create a new timer: TimerHandle_t xTimerCreate( const char * const pcTimerName, In this example, I’m going to create a software timer which blinks a LED every second. But if multiple commands can be sent from higher priority tasks or from interrupts, make sure your queue is long enough for this. 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, 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. □ What you see here is the queue for the timer task, not the list of timers created. The other thing which 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 to give 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. This timer task is responsible to handle all FreeRTOS software timers in the system. In 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-kind 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 he as to wake up each time a timer in the timer list has expired. There is a dedicated ‘ Tmr Svc‘ (Timer Service or Deamon) Task which maintains an ordered list of software timers, with the timer to expire next in front of the list).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |