Hi all:
For a auto reload timer, I want to modify timer period after each timer expires . So i want to ask: is it good to use xTimerChangePeriod in a callback function? Why? Or is it better to use notification task to call xTimerChangePeriod?
The timer callback runs in the timer task context and therefore, it must not block otherwise no other timers will be processed. If you want to call xTimerChangePeriod
in a timer callback, you must use the xTicksToWait
as 0 to ensure that the API does not block if the timer command queue is full.
And, by calling with a timeout of 0, it must be ready to handle and error return if the queue is full, and there really isn’t much you can do inside the timer handler to handle the error, as you need to return to the timer task to process the queue.
Hi aggarg, thank for your reply. If I directly process timer command(use prvInsertTimerInActiveList) instead of enqueue command when the timer command queue is full, will there be any serious consequences?
Yes - currently only timer task accesses this list. By directly manipulating this list, you’ll likely introduce concurrency issues. Why can’t you increase the timer command queue size and run the timer task at the highest priority? If you run timer task at the highest priority, any command posted to the timer command queue will be processed immediately.
Thanks for the pro tip! You just saved me a lot of time