2 FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.
5 ***************************************************************************
7 * FreeRTOS tutorial books are available in pdf and paperback. *
8 * Complete, revised, and edited pdf reference manuals are also *
11 * Purchasing FreeRTOS documentation will not only help you, by *
12 * ensuring you get running as quickly as possible and with an *
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
14 * the FreeRTOS project to continue with its mission of providing *
15 * professional grade, cross platform, de facto standard solutions *
16 * for microcontrollers - completely free of charge! *
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
20 * Thank you for using FreeRTOS, and thank you for your support! *
22 ***************************************************************************
25 This file is part of the FreeRTOS distribution.
27 FreeRTOS is free software; you can redistribute it and/or modify it under
28 the terms of the GNU General Public License (version 2) as published by the
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
30 >>>NOTE<<< The modification to the GPL is included to allow you to
31 distribute a combined work that includes FreeRTOS without being obliged to
32 provide the source code for proprietary components outside of the FreeRTOS
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
36 more details. You should have received a copy of the GNU General Public
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
39 by writing to Richard Barry, contact details for whom are available on the
44 http://www.FreeRTOS.org - Documentation, latest information, license and
47 http://www.SafeRTOS.com - A version that is certified for use in safety
50 http://www.OpenRTOS.com - Commercial support, development, porting,
51 licensing and training services.
54 #ifndef STACK_MACROS_H
55 #define STACK_MACROS_H
58 * Call the stack overflow hook function if the stack of the task being swapped
59 * out is currently overflowed, or looks like it might have overflowed in the
62 * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
63 * the current stack state only - comparing the current top of stack value to
64 * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
65 * will also cause the last few stack bytes to be checked to ensure the value
66 * to which the bytes were set when the task was created have not been
67 * overwritten. Note this second test does not guarantee that an overflowed
68 * stack will always be recognised.
71 /*-----------------------------------------------------------*/
73 #if( configCHECK_FOR_STACK_OVERFLOW == 0 )
75 /* FreeRTOSConfig.h is not set to check for stack overflows. */
76 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()
77 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
79 #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */
80 /*-----------------------------------------------------------*/
82 #if( configCHECK_FOR_STACK_OVERFLOW == 1 )
84 /* FreeRTOSConfig.h is only set to use the first method of
86 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
89 /*-----------------------------------------------------------*/
91 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) )
93 /* Only the current stack state is to be checked. */
94 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
96 /* Is the currently saved stack pointer within the stack limit? */ \
97 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \
99 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
103 #endif /* configCHECK_FOR_STACK_OVERFLOW > 0 */
104 /*-----------------------------------------------------------*/
106 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )
108 /* Only the current stack state is to be checked. */
109 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
112 /* Is the currently saved stack pointer within the stack limit? */ \
113 if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \
115 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
119 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
120 /*-----------------------------------------------------------*/
122 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
124 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
126 static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
127 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
128 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
129 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
130 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
133 /* Has the extremity of the task stack ever been written over? */ \
134 if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
136 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
140 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
141 /*-----------------------------------------------------------*/
143 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
145 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
147 char *pcEndOfStack = ( char * ) pxCurrentTCB->pxEndOfStack; \
148 static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
149 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
150 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
151 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
152 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
155 pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
157 /* Has the extremity of the task stack ever been written over? */ \
158 if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
160 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
164 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
165 /*-----------------------------------------------------------*/
167 #endif /* STACK_MACROS_H */