2 FreeRTOS.org V5.3.1 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the 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.org without being obliged to provide
\r
11 the source code for any proprietary components. Alternative commercial
\r
12 license and support terms are also available upon request. See the
\r
13 licensing section of http://www.FreeRTOS.org for full details.
\r
15 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
20 You should have received a copy of the GNU General Public License along
\r
21 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
22 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
52 #ifndef STACK_MACROS_H
\r
53 #define STACK_MACROS_H
\r
56 * Call the stack overflow hook function if the stack of the task being swapped
\r
57 * out is currently overflowed, or looks like it might have overflowed in the
\r
60 * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
\r
61 * the current stack state only - comparing the current top of stack value to
\r
62 * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
\r
63 * will also cause the last few stack bytes to be checked to ensure the value
\r
64 * to which the bytes were set when the task was created have not been
\r
65 * overwritten. Note this second test does not guarantee that an overflowed
\r
66 * stack will always be recognised.
\r
69 /*-----------------------------------------------------------*/
\r
71 #if( configCHECK_FOR_STACK_OVERFLOW == 0 )
\r
73 /* FreeRTOSConfig.h is not set to check for stack overflows. */
\r
74 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()
\r
75 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
\r
77 #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */
\r
78 /*-----------------------------------------------------------*/
\r
80 #if( configCHECK_FOR_STACK_OVERFLOW == 1 )
\r
82 /* FreeRTOSConfig.h is only set to use the first method of
\r
83 overflow checking. */
\r
84 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
\r
87 /*-----------------------------------------------------------*/
\r
89 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) )
\r
91 /* Only the current stack state is to be checked. */
\r
92 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
\r
94 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \
\r
96 /* Is the currently saved stack pointer within the stack limit? */ \
\r
97 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \
\r
99 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
103 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
\r
104 /*-----------------------------------------------------------*/
\r
106 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )
\r
108 /* Only the current stack state is to be checked. */
\r
109 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
\r
111 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \
\r
113 /* Is the currently saved stack pointer within the stack limit? */ \
\r
114 if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \
\r
116 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
120 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
\r
121 /*-----------------------------------------------------------*/
\r
123 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
\r
125 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
\r
127 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \
\r
128 static const unsigned portCHAR ucExpectedStackBytes[] = { 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
130 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
131 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
132 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
\r
135 /* Has the extremity of the task stack ever been written over? */ \
\r
136 if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
\r
138 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
142 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
\r
143 /*-----------------------------------------------------------*/
\r
145 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
\r
147 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
\r
149 extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \
\r
150 portCHAR *pcEndOfStack = ( portCHAR * ) pxCurrentTCB->pxEndOfStack; \
\r
151 static const unsigned portCHAR ucExpectedStackBytes[] = { 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
153 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
154 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
155 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
\r
158 pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
\r
160 /* Has the extremity of the task stack ever been written over? */ \
\r
161 if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
\r
163 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
167 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
\r
168 /*-----------------------------------------------------------*/
\r
170 #endif /* STACK_MACROS_H */
\r