cancel
Showing results for 
Search instead for 
Did you mean: 

Can FreeRTOS only "do things" during the Timer Tick interrupt (typically every 1 ms?)

arnold_w
Senior

I'm trying to understand how the internals of FreeRTOS work and in particular I'm curious whether FreeRTOS thread execution and handling only occurs with 1 ms "granularity". Let's take an example, let's assume I create a thread that only takes 0.3 ms to execute, what happens when it's done executing? Will the CPU "execute in vacuum" (execute nops?) for 0.7 ms until the next Timer Tick interrupt or will a context switch happen immediately to the thread with highest priority? Another example, I understand that there's a way to send "signals" between threads. If I send such a signal 0.4 ms after a Timer Tick interrupt, will it then be received by the receiving thread immediately or not until the next Timer Tick interrupt, 0.6 ms later? If the system clock is running at several hundred MHz, do you then get more useful task execution (less executing in "vacuum") "bang for the buck" if you change the Timer Tick frequency from 1kHz to 10 kHz?

3 REPLIES 3
KnarfB
Principal III

No. If the running task calls a FreeRTOS API function like xQueueSend, this may wake up a higher prio task immediately that was waiting (blocked) for data from that queue. Similar if you call osDelay, FreeRTOS will immediately schedule the next task due. Not so if you use HAL_Delay because FreeRTOS is not involved. One can say that the tick is only used in pre-emptive scheduling to schedule tasks even when they do not call FreeRTOS function (cooperative multitasking).

hth

KnarfB

Uwe Bonnes
Principal III

Normally there is a idle thread when nothing is to do. Mostly it uses WFI. When some event happens, so that the CPU needs to react, wakeup from WFI happens and the scheduler is called to find what thread should handle the interrupt. So best is to handle things that have to happend fast inside the interrupt, reaction with relaxed reactions time in a thread and use the main thread for the rest.

KnarfB
Principal III

Here is a TimeDoctor trace of a FreeRTOS project with 4 scheduled tasks:0693W00000FDq3DQAT.pngfor TimeDoctor see https://gitlab.com/KnarfB/timedoctor (work in progress)

hth

KnarfB