context switch from the void vApplicationTickHook(void) callback function

lz1msz wrote on Tuesday, October 27, 2015:

We are in charge for development of project, based on FreeRTOS VER 8.2.0

MCU: PIC24EP family /PIC24EP512GU810/
Compiler: XC16 1.21 PRO mode, all optimization enabled
FreeRTOS version: 8.2.0

We are using 5 tasks and several ISRs, but due to behavior issue, need to clarify our ISRs coding:

  1. Is it RTOS save to switch the context in the callback function: vApplicationTickHook(void)
    Due to it is valuable to use it as a 1mS tick timer, we need to send message queue to task and wake-up the task. My question is: Is this context switch RTOS save code for the tick hook. I add the source code inside the vApplicationTickHook(void) function:

void vApplicationTickHook(void)
// Local variables:
BaseTypet xHigherPriorityTaskWoken;
unsigned char PortYieldFlag;

PortYieldFlag = 0;

// Process outgoing messages to the graphics task:
TouchDetectPosition();                                                      // Update the current coordinates
TouchGetMsg(&pMsg);                                                         // Decide if the new points generate touch message

// If there is touch message received, send it to the graphics task:
if(pMsg.type != EVENTINVALID)                                              // Received is valid message
    MyGraphicsMessage.MessageCommand = GRAPHICSTASKTOUCSCREENMESSAGE;     // Name the message command header, that this is touch screen message
    MyGraphicsMessage.MessageData.MyGolMessage = pMsg;
    xHigherPriorityTaskWoken = pdFALSE;                                     // Initialize the variable, which store the condition if context switch is needed
    xQueueSendFromISR(GraphicsTaskQueue, &MyGraphicsMessage, &xHigherPriorityTaskWoken); // Send the message to the graphics task queue
    if(xHigherPriorityTaskWoken == pdTRUE)                                  // Check if context switch is needed
        //taskYIELD();                                                        // Perform the context switch
        PortYieldFlag = 1;

// Timestamp functions for all tasks:
MAINAPPLICATIONTASKSTimeStampTick();                                       // Rolling the software timers

// Process time for load screen duration:
if(1 == MAINAPPLICATIONTASKSLoadScreenTimerTick())  // Inside this function message queue is send to the desired task
    PortYieldFlag = 1;

// Application level task wake-up hook:
if(PortYieldFlag == 1)

} // End of vApplicationTickHook()

  1. Due to we use many ISRs with different priority, we changed the:#define configKERNEL_INTERRUPT_PRIORITY 0x07

(Also modified all needed values in the needed port files)

Currently all of our ISRs, which can cause context switch are priority level 7, all other ISRs are less priority level

Is this configuration RTOS SAVE?

Many thanks in advance

Dimitar Belev

rtel wrote on Tuesday, October 27, 2015:

Looking at how the port is implemented on that part I would say no, it is not safe. In other ports it is safe, but also pointless, as the tick interrupt will switch to the highest priority task anyway.

It is ok to unblock a task (using vTaskNotifyGiveFromISR()), but don’t then perform a context switch. As mentioned above, if the unblocked task is the highest priority task it will get selected to run anyway.


lz1msz wrote on Wednesday, October 28, 2015:

Thank you!