finding the task that is running at a given time

Hi, Is there a function in Freertos that indicates the task that was running before a given task and the task that will run after it? To be more clear, if the task that is running now is T, can I kow the task that was running before T and the task that will run after T ? Thank you

finding the task that is running at a given time

Hi, I haven’t used the trace facility, but I’m sure that it may do what you require. Check the freeRTOS documentation online for useTraceFacility examples. Brad

finding the task that is running at a given time

You can determine the task that ran last by adding something like the following to the bottom of FreeRTOSConfig.h.
/* Define xLastTask in a C file somewhere. */
extern TaskHandle_t xLastTask;

#define traceTASK_SWITCHED_OUT() if( xLastTask != pxCurrentTCB ) xLastTask = pxCurrentTCB
Then the handle of the previous task will be stored in xLastTask. You cannot determine which task will run next, as FreeRTOS doesn’t even know that. For example, tasks are often unblocked by an interrupt, and there is no way of knowing which tasks will be unblocked when. You do know that FreeRTOS will always run the highest priority task that is in the Ready state, and if there is more than one such task at the same priority, then it will run the one that has been in the Ready state the longest since it last executed. Regards.

finding the task that is running at a given time

Thank you for your reply. I added the definition of traceTASKSWITCHEDOUT() like you said and I defined xLastTask at the beginning of the file tasks.c But when I compile, I get an error : “undefined reference to xLastTask” on the call of the function traceTASKSWITCHEDOUT(). Is it because I defined xLastTask in the wrong place? If so, where should I define it?

finding the task that is running at a given time

The post two above is not clear. xLastTask must be declared in a c file and extern in FreeRTOSConfig.h. In a C file – TaskHandle_t xLastTask; In FreeRTOSConfig.h – extern TaskHandle_t xLastTask;

finding the task that is running at a given time

Yes I did this first but I had the error “unknown typename TaskHandlet” in FreeRTOSConfig.h. The type TaskHandlet is defined in task.h so I thought I can’t use it in FreeRTOSConfig.h So I put the extern in the C file and I got “undefined reference to xLastTask”

finding the task that is running at a given time

Try adding
#include "task.h"
immediately above where TaskHandle_t is used, that way the type should be defined in each file in which FreeRTOSConfig.h is included. Regards.

finding the task that is running at a given time

When I add this, I get a lot of new errors