richard_damon wrote on Monday, June 05, 2017:
You have something fundamentally wrong if you want to spend 30ms in a callback that gets called every ms, if that is your question.
First, to be clear, you are talking about a FreeRTOS timer, created with created witth xTimerCreate (called from the Timer/Service Task) and not a ‘TickHook’ (vApplicationTickHook) (called from the Timer Tick interrupt itself)).
Timer Callbacks should be fairly quick, because all Timer Callbacks are executed in a single task, and time spent in one callback will delay any other timer that becomes ready during it execution., but it won’t mess up the basic tick functionality of the system. Often the TImer/Service task is placed at the top software priority so the timer callbacks happen as soon as possible, which means that if your callback takes 30ms of actual CPU usage, and is scheduled every 1ms, you will starve the rest of the system for CPU execution time. If you don’t mean for it to be run every tick, but say once a second, then this might work, BUT, during the 30ms it is running, no other timer callback will get called, but they will be delayed until that callback finishes.
The genearl rule I use is that timer callback should be quick and not (normally) block for things, so that one timer can’t significantly influence another, and any periodic action that might actually take some time, or needs to block for something (like I/O) should get a specific task to run in.