]> git.sur5r.net Git - freertos/blob - Source/include/StackMacros.h
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Source / include / StackMacros.h
1 /*\r
2     FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     This file is part of the FreeRTOS distribution.\r
5 \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
14     license details.\r
15 \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
19     more details.\r
20 \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
24 \r
25 \r
26     ***************************************************************************\r
27     *                                                                         *\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
31     *                                                                         *\r
32     ***************************************************************************\r
33 \r
34     1 tab == 4 spaces!\r
35 \r
36     Please ensure to read the configuration and relevant port sections of the\r
37     online documentation.\r
38 \r
39     http://www.FreeRTOS.org - Documentation, latest information, license and\r
40     contact details.\r
41 \r
42     http://www.SafeRTOS.com - A version that is certified for use in safety\r
43     critical systems.\r
44 \r
45     http://www.OpenRTOS.com - Commercial support, development, porting,\r
46     licensing and training services.\r
47 */\r
48 \r
49 #ifndef STACK_MACROS_H\r
50 #define STACK_MACROS_H\r
51 \r
52 /*\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
55  * past.\r
56  *\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
64  */\r
65 \r
66 /*-----------------------------------------------------------*/\r
67 \r
68 #if( configCHECK_FOR_STACK_OVERFLOW == 0 )\r
69 \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
73 \r
74 #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */\r
75 /*-----------------------------------------------------------*/\r
76 \r
77 #if( configCHECK_FOR_STACK_OVERFLOW == 1 )\r
78 \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
82 \r
83 #endif\r
84 /*-----------------------------------------------------------*/\r
85 \r
86 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) )\r
87 \r
88         /* Only the current stack state is to be checked. */\r
89         #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()                                                                                                            \\r
90         {                                                                                                                                                                                                       \\r
91         extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );              \\r
92                                                                                                                                                                                                                 \\r
93                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
94                 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack )                                                                               \\r
95                 {                                                                                                                                                                                               \\r
96                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );        \\r
97                 }                                                                                                                                                                                               \\r
98         }\r
99 \r
100 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\r
101 /*-----------------------------------------------------------*/\r
102 \r
103 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )\r
104 \r
105         /* Only the current stack state is to be checked. */\r
106         #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()                                                                                                            \\r
107         {                                                                                                                                                                                                       \\r
108         extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );              \\r
109                                                                                                                                                                                                                 \\r
110                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
111                 if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack )                                                                  \\r
112                 {                                                                                                                                                                                               \\r
113                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );        \\r
114                 }                                                                                                                                                                                               \\r
115         }\r
116 \r
117 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\r
118 /*-----------------------------------------------------------*/\r
119 \r
120 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )\r
121 \r
122         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                                   \\r
123         {                                                                                                                                                                                                                                                                                               \\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
130                                                                                                                                                                                                                                                                                                         \\r
131                                                                                                                                                                                                                                                                                                         \\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
134                 {                                                                                                                                                                                                                                                                                       \\r
135                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                                                \\r
136                 }                                                                                                                                                                                                                                                                                       \\r
137         }\r
138 \r
139 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
140 /*-----------------------------------------------------------*/\r
141 \r
142 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )\r
143 \r
144         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                                   \\r
145         {                                                                                                                                                                                                                                                                                               \\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
153                                                                                                                                                                                                                                                                                                         \\r
154                                                                                                                                                                                                                                                                                                         \\r
155                 pcEndOfStack -= sizeof( ucExpectedStackBytes );                                                                                                                                                                                         \\r
156                                                                                                                                                                                                                                                                                                         \\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
159                 {                                                                                                                                                                                                                                                                                       \\r
160                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                                                \\r
161                 }                                                                                                                                                                                                                                                                                       \\r
162         }\r
163 \r
164 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
165 /*-----------------------------------------------------------*/\r
166 \r
167 #endif /* STACK_MACROS_H */\r
168 \r