2 FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 FreeRTOS supports many tools and architectures. V7.0.0 is sponsored by:
\r
6 Atollic AB - Atollic provides professional embedded systems development
\r
7 tools for C/C++ development, code analysis and test automation.
\r
8 See http://www.atollic.com
\r
11 ***************************************************************************
\r
13 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
14 * Complete, revised, and edited pdf reference manuals are also *
\r
17 * Purchasing FreeRTOS documentation will not only help you, by *
\r
18 * ensuring you get running as quickly as possible and with an *
\r
19 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
20 * the FreeRTOS project to continue with its mission of providing *
\r
21 * professional grade, cross platform, de facto standard solutions *
\r
22 * for microcontrollers - completely free of charge! *
\r
24 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
26 * Thank you for using FreeRTOS, and thank you for your support! *
\r
28 ***************************************************************************
\r
31 This file is part of the FreeRTOS distribution.
\r
33 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
34 the terms of the GNU General Public License (version 2) as published by the
\r
35 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
36 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
37 distribute a combined work that includes FreeRTOS without being obliged to
\r
38 provide the source code for proprietary components outside of the FreeRTOS
\r
39 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
40 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
41 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
42 more details. You should have received a copy of the GNU General Public
\r
43 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
44 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
45 by writing to Richard Barry, contact details for whom are available on the
\r
50 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
53 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
56 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
57 licensing and training services.
\r
60 #ifndef STACK_MACROS_H
\r
61 #define STACK_MACROS_H
\r
64 * Call the stack overflow hook function if the stack of the task being swapped
\r
65 * out is currently overflowed, or looks like it might have overflowed in the
\r
68 * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
\r
69 * the current stack state only - comparing the current top of stack value to
\r
70 * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
\r
71 * will also cause the last few stack bytes to be checked to ensure the value
\r
72 * to which the bytes were set when the task was created have not been
\r
73 * overwritten. Note this second test does not guarantee that an overflowed
\r
74 * stack will always be recognised.
\r
77 /*-----------------------------------------------------------*/
\r
79 #if( configCHECK_FOR_STACK_OVERFLOW == 0 )
\r
81 /* FreeRTOSConfig.h is not set to check for stack overflows. */
\r
82 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()
\r
83 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
\r
85 #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */
\r
86 /*-----------------------------------------------------------*/
\r
88 #if( configCHECK_FOR_STACK_OVERFLOW == 1 )
\r
90 /* FreeRTOSConfig.h is only set to use the first method of
\r
91 overflow checking. */
\r
92 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()
\r
95 /*-----------------------------------------------------------*/
\r
97 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) )
\r
99 /* Only the current stack state is to be checked. */
\r
100 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
\r
102 /* Is the currently saved stack pointer within the stack limit? */ \
\r
103 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \
\r
105 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
109 #endif /* configCHECK_FOR_STACK_OVERFLOW > 0 */
\r
110 /*-----------------------------------------------------------*/
\r
112 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )
\r
114 /* Only the current stack state is to be checked. */
\r
115 #define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \
\r
118 /* Is the currently saved stack pointer within the stack limit? */ \
\r
119 if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \
\r
121 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
125 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
\r
126 /*-----------------------------------------------------------*/
\r
128 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
\r
130 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
\r
132 static const unsigned char ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
133 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
134 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
135 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
136 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
\r
139 /* Has the extremity of the task stack ever been written over? */ \
\r
140 if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
\r
142 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
146 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
\r
147 /*-----------------------------------------------------------*/
\r
149 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
\r
151 #define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \
\r
153 char *pcEndOfStack = ( char * ) pxCurrentTCB->pxEndOfStack; \
\r
154 static const unsigned char ucExpectedStackBytes[] = { 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
156 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
157 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
\r
158 tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
\r
161 pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
\r
163 /* Has the extremity of the task stack ever been written over? */ \
\r
164 if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
\r
166 vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
\r
170 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
\r
171 /*-----------------------------------------------------------*/
\r
173 #endif /* STACK_MACROS_H */
\r