rtel wrote on Monday, July 13, 2015:
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.