Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

finding the task that is running at a given time

Posted by juhc on July 13, 2015

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

Posted by bradgoold on July 13, 2015

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

Posted by rtel on 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.

Regards.


finding the task that is running at a given time

Posted by juhc on July 14, 2015

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

Posted by davedoors on July 14, 2015

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

Posted by juhc on July 14, 2015

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

Posted by rtel on July 14, 2015

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

Posted by juhc on July 14, 2015

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


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS