]> git.sur5r.net Git - freertos/blob - Source/include/StackMacros.h
Ready for V5.2.0 release.
[freertos] / Source / include / StackMacros.h
1 /*\r
2         FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \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 \r
10         FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
11         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
12         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for \r
13         more details.\r
14 \r
15         You should have received a copy of the GNU General Public License along \r
16         with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 \r
17         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
18 \r
19         A special exception to the GPL is included to allow you to distribute a \r
20         combined work that includes FreeRTOS.org without being obliged to provide\r
21         the source code for any proprietary components.  See the licensing section\r
22         of http://www.FreeRTOS.org for full details.\r
23 \r
24 \r
25         ***************************************************************************\r
26         *                                                                         *\r
27         * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *\r
28         *                                                                         *\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
33         * .zip file.                                                              *\r
34         *                                                                         *\r
35         ***************************************************************************\r
36 \r
37         1 tab == 4 spaces!\r
38 \r
39         Please ensure to read the configuration and relevant port sections of the\r
40         online documentation.\r
41 \r
42         http://www.FreeRTOS.org - Documentation, latest information, license and\r
43         contact details.\r
44 \r
45         http://www.SafeRTOS.com - A version that is certified for use in safety\r
46         critical systems.\r
47 \r
48         http://www.OpenRTOS.com - Commercial support, development, porting,\r
49         licensing and training services.\r
50 */\r
51 \r
52 #ifndef STACK_MACROS_H\r
53 #define STACK_MACROS_H\r
54 \r
55 /*\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
58  * past.\r
59  *\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
67  */\r
68 \r
69 /*-----------------------------------------------------------*/\r
70 \r
71 #if( configCHECK_FOR_STACK_OVERFLOW == 0 )\r
72 \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
76 \r
77 #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */\r
78 /*-----------------------------------------------------------*/\r
79 \r
80 #if( configCHECK_FOR_STACK_OVERFLOW == 1 )\r
81 \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
85 \r
86 #endif\r
87 /*-----------------------------------------------------------*/\r
88 \r
89 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) )\r
90 \r
91         /* Only the current stack state is to be checked. */\r
92         #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()                                                                                                            \\r
93         {                                                                                                                                                                                                       \\r
94         extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName );          \\r
95                                                                                                                                                                                                                 \\r
96                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
97                 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack )                                                                               \\r
98                 {                                                                                                                                                                                               \\r
99                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );        \\r
100                 }                                                                                                                                                                                               \\r
101         }\r
102 \r
103 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\r
104 /*-----------------------------------------------------------*/\r
105 \r
106 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )\r
107 \r
108         /* Only the current stack state is to be checked. */\r
109         #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()                                                                                                            \\r
110         {                                                                                                                                                                                                       \\r
111         extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName );          \\r
112                                                                                                                                                                                                                 \\r
113                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
114                 if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack )                                                                  \\r
115                 {                                                                                                                                                                                               \\r
116                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );        \\r
117                 }                                                                                                                                                                                               \\r
118         }\r
119 \r
120 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\r
121 /*-----------------------------------------------------------*/\r
122 \r
123 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )\r
124 \r
125         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                                   \\r
126         {                                                                                                                                                                                                                                                                                               \\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
133                                                                                                                                                                                                                                                                                                         \\r
134                                                                                                                                                                                                                                                                                                         \\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
137                 {                                                                                                                                                                                                                                                                                       \\r
138                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                                                \\r
139                 }                                                                                                                                                                                                                                                                                       \\r
140         }\r
141 \r
142 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
143 /*-----------------------------------------------------------*/\r
144 \r
145 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )\r
146 \r
147         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                                   \\r
148         {                                                                                                                                                                                                                                                                                               \\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
156                                                                                                                                                                                                                                                                                                         \\r
157                                                                                                                                                                                                                                                                                                         \\r
158                 pcEndOfStack -= sizeof( ucExpectedStackBytes );                                                                                                                                                                                         \\r
159                                                                                                                                                                                                                                                                                                         \\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
162                 {                                                                                                                                                                                                                                                                                       \\r
163                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                                                \\r
164                 }                                                                                                                                                                                                                                                                                       \\r
165         }\r
166 \r
167 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
168 /*-----------------------------------------------------------*/\r
169 \r
170 #endif /* STACK_MACROS_H */\r
171 \r