2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\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 * The FreeRTOS eBook and reference manual are available to purchase for a *
\r
29 * small fee. Help yourself get started quickly while also helping the *
\r
30 * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *
\r
32 ***************************************************************************
\r
36 Please ensure to read the configuration and relevant port sections of the
\r
37 online documentation.
\r
39 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
42 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
45 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
46 licensing and training services.
\r
49 #ifndef STACK_MACROS_H
\r
50 #define STACK_MACROS_H
\r
53 * Call the stack overflow hook function if the stack of the task being swapped
\r
54 * out is currently overflowed, or looks like it might have overflowed in the
\r
57 * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
\r
58 * the current stack state only - comparing the current top of stack value to
\r
59 * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
\r
60 * will also cause the last few stack bytes to be checked to ensure the value
\r
61 * to which the bytes were set when the task was created have not been
\r
62 * overwritten. Note this second test does not guarantee that an overflowed
\r
63 * stack will always be recognised.
\r
66 /*-----------------------------------------------------------*/
\r
68 #if( configCHECK_FOR_STACK_OVERFLOW == 0 )
\r
70 /* FreeRTOSConfig.h is not set to check for stack overflows. */
\r
71 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()
\r
72 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
\r
74 #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */
\r
75 /*-----------------------------------------------------------*/
\r
77 #if( configCHECK_FOR_STACK_OVERFLOW == 1 )
\r
79 /* FreeRTOSConfig.h is only set to use the first method of
\r
80 overflow checking. */
\r
81 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
\r
84 /*-----------------------------------------------------------*/
\r
86 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) )
\r
88 /* Only the current stack state is to be checked. */
\r
89 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
\r
91 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName ); \
\r
93 /* Is the currently saved stack pointer within the stack limit? */ \
\r
94 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \
\r
96 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
100 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
\r
101 /*-----------------------------------------------------------*/
\r
103 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )
\r
105 /* Only the current stack state is to be checked. */
\r
106 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
\r
108 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName ); \
\r
110 /* Is the currently saved stack pointer within the stack limit? */ \
\r
111 if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \
\r
113 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
117 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
\r
118 /*-----------------------------------------------------------*/
\r
120 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
\r
122 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
\r
124 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName ); \
\r
125 static const unsigned char ucExpectedStackBytes[] = { 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
129 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
\r
132 /* Has the extremity of the task stack ever been written over? */ \
\r
133 if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
\r
135 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
139 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
\r
140 /*-----------------------------------------------------------*/
\r
142 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
\r
144 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
\r
146 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName ); \
\r
147 char *pcEndOfStack = ( char * ) pxCurrentTCB->pxEndOfStack; \
\r
148 static const unsigned char ucExpectedStackBytes[] = { 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
152 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
\r
155 pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
\r
157 /* Has the extremity of the task stack ever been written over? */ \
\r
158 if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
\r
160 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
164 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
\r
165 /*-----------------------------------------------------------*/
\r
167 #endif /* STACK_MACROS_H */
\r