2 FreeRTOS V5.4.0 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS distribution.
\r
6 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
7 the terms of the GNU General Public License (version 2) as published by the
\r
8 Free Software Foundation and modified by the FreeRTOS exception.
\r
9 **NOTE** The exception to the GPL is included to allow you to distribute a
\r
10 combined work that includes FreeRTOS without being obliged to provide the
\r
11 source code for proprietary components outside of the FreeRTOS kernel.
\r
12 Alternative commercial license and support terms are also available upon
\r
13 request. See the licensing section of http://www.FreeRTOS.org for full
\r
16 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
21 You should have received a copy of the GNU General Public License along
\r
22 with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
\r
23 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
26 ***************************************************************************
\r
28 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
48 #ifndef STACK_MACROS_H
\r
49 #define STACK_MACROS_H
\r
52 * Call the stack overflow hook function if the stack of the task being swapped
\r
53 * out is currently overflowed, or looks like it might have overflowed in the
\r
56 * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
\r
57 * the current stack state only - comparing the current top of stack value to
\r
58 * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
\r
59 * will also cause the last few stack bytes to be checked to ensure the value
\r
60 * to which the bytes were set when the task was created have not been
\r
61 * overwritten. Note this second test does not guarantee that an overflowed
\r
62 * stack will always be recognised.
\r
65 /*-----------------------------------------------------------*/
\r
67 #if( configCHECK_FOR_STACK_OVERFLOW == 0 )
\r
69 /* FreeRTOSConfig.h is not set to check for stack overflows. */
\r
70 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()
\r
71 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
\r
73 #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */
\r
74 /*-----------------------------------------------------------*/
\r
76 #if( configCHECK_FOR_STACK_OVERFLOW == 1 )
\r
78 /* FreeRTOSConfig.h is only set to use the first method of
\r
79 overflow checking. */
\r
80 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
\r
83 /*-----------------------------------------------------------*/
\r
85 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) )
\r
87 /* Only the current stack state is to be checked. */
\r
88 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
\r
90 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \
\r
92 /* Is the currently saved stack pointer within the stack limit? */ \
\r
93 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \
\r
95 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
99 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
\r
100 /*-----------------------------------------------------------*/
\r
102 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )
\r
104 /* Only the current stack state is to be checked. */
\r
105 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
\r
107 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \
\r
109 /* Is the currently saved stack pointer within the stack limit? */ \
\r
110 if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \
\r
112 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
116 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
\r
117 /*-----------------------------------------------------------*/
\r
119 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
\r
121 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
\r
123 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \
\r
124 static const unsigned portCHAR ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
125 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
126 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
127 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
128 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
\r
131 /* Has the extremity of the task stack ever been written over? */ \
\r
132 if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
\r
134 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
138 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
\r
139 /*-----------------------------------------------------------*/
\r
141 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
\r
143 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
\r
145 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \
\r
146 portCHAR *pcEndOfStack = ( portCHAR * ) pxCurrentTCB->pxEndOfStack; \
\r
147 static const unsigned portCHAR ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
148 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
149 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
150 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
151 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
\r
154 pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
\r
156 /* Has the extremity of the task stack ever been written over? */ \
\r
157 if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
\r
159 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
163 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
\r
164 /*-----------------------------------------------------------*/
\r
166 #endif /* STACK_MACROS_H */
\r