How to know Scheduler state and which task is running?


Is it possible to know the request and grant signals that the scheduler gets/gives? Would it be possible to have a variable which says which task is currently running?

The question is a bit vague …
Which bigger problem do you want to solve ?

pxCurrentTCB is a pointer to the task currently running (pointer to the TCB of currently running task).

Not sure what you mean by:

I would like to know externally (via GPIO for example) which task is running. So, if I have 8 tasks, with 3 bits I want to know which one is currently executing.

In the source code for FreeRTOS are some ‘TRACE’ macros that are called at various time that can implement this. There is a macro that is called as a task is swapped in, that you could make set the GPIOs. (Would need to look in the code to find the exact name, which I don’t have convenient at the moment). You would define that trace macro in your FreeRTOSConfig.h

See the FreeRTOS trace hooks.

Add some code to traceTASK_SWITCHED_IN. Or put some code in vTaskSwitchContext or taskSELECT_HIGHEST_PRIORITY_TASK.

Or you could use Percipio Trace but I am not sure what you can use for free.

Those are good places to start. Thanks for the quick answer

There are also trace tools that will provide this information. This uses the trace macros to generate a complete trace including the information you want. There is also Segger SystemView, although I’m not sure of the detail that provides.