FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [January 2011 Threads] hook functionsPosted by umnrw on January 26, 2011 Hi,
I need to know about the hook functions in FreeRTOS kernel which are called whenever a scheduling decision is made. I have used traceTASK_SWITCHED_OUT, and traceTASK_SWITCHED_IN macros, but they work with tasks, not at every context switch. Can someone provide a little information or any example to use them?
thanks.
RE: hook functionsPosted by MEdwards on January 26, 2011 In FreeRTOSConfig.h:
For an idle hook set configUSE_IDLE_HOOK to 1, then in your application write a function void vApplicationIdleHook( void );
For a tick hook set configUSE_TICK_HOOK to 1, then in your application write a function void vApplicationTickHook( void );
Those are mentioned on http://www.freertos.org/a00016.html
Also, for a malloc() failed hook set configUSE_MALLOC_FAILED_HOOK to 1, then in your application write a function void vApplicationMallocFailedHook( void ); /* used for heap_1.c and heap_2.c and heap_3.c only */
Is there a link for the malloc failed thing?
For stack overflow hook set configCHECK_FOR_STACK_OVERFLOW to 1 or 2, and provide a function void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );
see http://www.freertos.org/Stacks-and-stack-overflow-checking.html
RE: hook functionsPosted by umnrw on January 27, 2011 thanks a lot for a detailed answer.
tick hook is called during each tick interrupt by the kernel. I need a hook function that is called at every context switch (whenever a scheduling decision is made). Is there any hook function to fulfill this requirement?
best regards.
RE: hook functionsPosted by Richard on January 27, 2011 You can do this using the traceTASK_SWITCHED_OUT and traceTASK_SWITCHED_IN macros. The sections I'm currently adding to the tutorial books actually contain an example that show you how to do just that.
These macros run in the context of the tasks.c file, so have access to the pxCurrentTCB variable. Therefore, what you do is something along the lines of:
xTaskHandle xTaskThatWasRunning;
#define traceTASK_SWITCHED_OUT xTaskThatWasRunning = pxCurrentTCB
#define traceTASK_SWITCHED_IN \ ____if( xTaskThatWasRunning != pxCurrentTCB ) \ ____{ \ ________/* A context switch has occurred, do something. */ \ ____}
Regards.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|