Hi, I am using stm32L series controller with version 9.0.0 of FreeRTOS. I am using deferred interrupt processing using timer service task. For every 120 ms my internal timer generates an interrupt and from the timer’s period elapsed callback function I call xTimerPendFunctionCallFromISR which in turn calls a small function which does average of 40 samples of adc. The function takes around 50ms
My problem is when ever this callback function is getting executed other task of same priority is getting invoked in a very rare case eventhough preemption is off. Why is this happening?
Thanks in advance.
configUSE_PREEMPTION 0(co operative scheduling)
#define configTIMER_TASK_PRIORITY 0
#define configTIMER_QUEUE_LENGTH 5
#define configTIMER_TASK_STACK_DEPTH 512
One thing to note, even with preemption off, other tasks will be given a chance to run if the current task hits a yield point, which as I remember, includes any FreeRTOS call that wakes another task. So if in the process of getting this data you make any FreeRTOS calls that could be the answer.
A second point, this seems to be a bad use of the Pend Function. Pended Functions, like Timer Callbacks are supposed to be fairly small and quick routines, as while they are running, the Timer task is busy and not able to handle other timer actions. These functions are also not supposed to do anything that could block, as this can result in the Timer Task getting hung.
Generally, operations of this length would be assigned to a task, that would be waiting for your notification, and then perform the action.
I also tend to discourage disabling preemption and going to co-operative scheduling, as that really does mean that you really DO need to make sure that ALL your tasks are cooperative enough to make things work, and this is normally harder to do then isolate shared access into critical sections.
Thanks richard for the reply. Before posting itself I verified the possibility of calling an yield and no I ain’t calling it. And for the possibility of second point I am using the timer task only for this callback function.