Quality RTOS & Embedded Software

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



Posted by michaeln32 on June 10, 2018


Tasks in the system can creating SW timers using API xTimersCreate().

When the time has come the time service task execute the callback of the timer that was created.

While time service task execute the callback -> Is there a way to know who was the task that creatined this SW timer ?

Thank you


Posted by richard_damon on June 10, 2018

The TimerCallback function is given the handle to the Timer that fired, and that handle has a void* pointer that the application can use to store information for its use. You could set that to the task handle when creating the timer, and then the timer callback could get that.


Posted by michaeln32 on June 11, 2018

Thanks Richard.

Is it ok to add one more filed to TIMER struct - pointer to TCB ?


Posted by richard_damon on June 11, 2018

My comment is that you don't need to add a new item to the struct, it already has a void* pointer in it that is for the use of the user. YOU just need to make sure that when you create a timer you assign it to the creating tasks handle, then the timer call back can get that handle.

The create timer functions prototype is: TimerHandlet xTimerCreate ( const char * const pcTimerName, const TickTypet xTimerPeriod, const UBaseTypet uxAutoReload, void * const pvTimerID, TimerCallbackFunctiont pxCallbackFunction );

That pvTimerID parameter is for YOU to use, it sounds like you want to make it the handle of the task creating the timer.

The timer callback function then just needs to call pvTimerGetID() on the timer handle it was passed to itself to get that value.


Posted by michaeln32 on June 12, 2018

Thanks Richard

  1. Are Only tasks can do xTimerCreate() ? or ISR can do also xTimerCreate() ?

  2. If task do xTimerCreate() and after that it deleted without delete the timer, Is the callback of the timer will continue running pereodicly ?


Posted by richard_damon on June 12, 2018

xTimerCreate doesn't end in FromISR, so it shouldn't be called from an ISR. Since creating a timer will allocate memory for the timer, this really isn't something to be done in an ISR. xTimerCreate() can (and I often do) be called before the scheduler starts, so before tasks start to run.

Deleting a task does NOT delete anything that it created, because FreeRTOS doesn't track that sort of thing, and more importatly because it is quite possible for one task to create various resources that other tasks may use. There is not any natural connection of the creator of a timer and the timer itself. If it creates a timer, the timer will continue to operate even after the task is gone.


Posted by michaeln32 on June 13, 2018

Thank you Richard for your good and helpful answers.

The timer service task will run (be in running state) when a timer expired. The timer greated by a task or by main (before scheduler run) using the API xTimerCreate().

Are there more resons that causes the timer service task to run that are not retelted to xTimerCreate() ?


Posted by richard_damon on June 13, 2018

The Timer Service Tasks needs to run (for a very short time) everytime you adjust the state of a timer (start, stop, restart, etc) as these operations put a command on the Timer Queue for the Timer Service Task to perform these operationss.

The Timer Service Task also handles requests from xTimerPendFunctionCall and xTimerPendFunctionCallFromISR, and those pended function run just like timer callback in the context of the Timer Service Task.

The Timer Service Task will run any time a timer callback is needed to run, and that callback is run in the contex of the Timer Service Task.

One way to think of the Timer Service Task is that it waits on the Timer Request Queue for commands (Start/Stop /Change requests on Timers and Pend Function requests) with a timeout value such that it also wakes up to call timers callbacks as their time expires.


Posted by michaeln32 on June 13, 2018

Thank you very much Richard

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

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

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo, Nuvoton Cortex-M23 demo & STM32H745 dual core (AMP) demo.

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

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

Cadence Tensilica Cortes

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