Quality RTOS & Embedded Software

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


context switch from the void vApplicationTickHook(void) callback function

Posted by lz1msz on October 27, 2015

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

Details: 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: GOLMSG pMsg; GRAPHICSMESSAGE MyGraphicsMessage; 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 configKERNELINTERRUPTPRIORITY 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

Regards Dimitar Belev

context switch from the void vApplicationTickHook(void) callback function

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


context switch from the void vApplicationTickHook(void) callback function

Posted by lz1msz on October 28, 2015

Thank you!

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

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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

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

Xilinx Microblaze and Zynq partner