Quality RTOS & Embedded Software

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




Hook Functions
[More Advanced]

Idle Hook Function

The idle task can optionally call an application defined hook (or callback) function - the idle hook. The idle task runs at the very lowest priority, so such an idle hook function will only get executed when there are no tasks of higher priority that are able to run. This makes the idle hook function an ideal place to put the processor into a low power state - providing an automatic power saving whenever there is no processing to be performed.

The idle hook will only get called if configUSE_IDLE_HOOK is set to 1 within FreeRTOSConfig.h. When this is set the application must provide the hook function with the following prototype:

void vApplicationIdleHook( void );
The idle hook is called repeatedly as long as the idle task is running. It is paramount that the idle hook function does not call any API functions that could cause it to block. Also, if the application makes use of the vTaskDelete() API function then the idle task hook must be allowed to periodically return (this is because the idle task is responsible for cleaning up the resources that were allocated by the RTOS kernel to the task that has been deleted).



Tick Hook Function

The tick interrupt can optionally call an application defined hook (or callback) function - the tick hook. The tick hook provides a convenient place to implement timer functionality.

The tick hook will only get called if configUSE_TICK_HOOK is set to 1 within FreeRTOSConfig.h. When this is set the application must provide the hook function with the following prototype:

void vApplicationTickHook( void );
vApplicationTickHook() executes from within an ISR so must be very short, not use much stack, and not call any API functions that don't end in "FromISR" or "FROM_ISR".

See the demo application file crhook.c for an example of how to use a tick hook.



Malloc Failed Hook Function

The memory allocation schemes implemented by heap_1.c, heap_2.c, heap_3.c, heap_4.c and heap_5.c can optionally include a malloc() failure hook (or callback) function that can be configured to get called if pvPortMalloc() ever returns NULL.

Defining the malloc() failure hook will help identify problems caused by lack of heap memory - especially when a call to pvPortMalloc() fails within an API function.

The malloc failed hook will only get called if configUSE_MALLOC_FAILED_HOOK is set to 1 within FreeRTOSConfig.h. When this is set the application must provide the hook function with the following prototype:

void vApplicationMallocFailedHook( void );



Stack Overflow Hook Function

See the Stack Overflow Protection page for details.



Daemon Task Startup Hook

The RTOS daemon task is the same as the Timer Service Task. Sometimes it is referred to as the daemon task because the task is now used for more than just servicing timers.

If configUSE_DAEMON_TASK_STARTUP_HOOK is set to 1 in FreeRTOSConfig.h then the Daemon Task Startup Hook will be called as soon as the Daemon Task starts executing for the first time. This is useful if the application includes initialisation code that would benefit from executing after the scheduler has been started, which allows the initialisation code to make use of the RTOS functionality.

If configUSE_DAEMON_TASK_STARTUP_HOOK is set to 1 then the application writer must provide an implementation of the Daemon Task startup hook function with the following name an prototype.

void vApplicationDaemonTaskStartupHook( void );




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




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists