]> 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 V5.4.2 - 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         * Looking for a quick start?  Then check out the FreeRTOS eBook!          *\r
29         * See http://www.FreeRTOS.org/Documentation for details                   *\r
30         *                                                                         *\r
31         ***************************************************************************\r
32 \r
33         1 tab == 4 spaces!\r
34 \r
35         Please ensure to read the configuration and relevant port sections of the\r
36         online documentation.\r
37 \r
38         http://www.FreeRTOS.org - Documentation, latest information, license and\r
39         contact details.\r
40 \r
41         http://www.SafeRTOS.com - A version that is certified for use in safety\r
42         critical systems.\r
43 \r
44         http://www.OpenRTOS.com - Commercial support, development, porting,\r
45         licensing and training services.\r
46 */\r
47 \r
48 #ifndef STACK_MACROS_H\r
49 #define STACK_MACROS_H\r
50 \r
51 /*\r
52  * Call the stack overflow hook function if the stack of the task being swapped\r
53  * out is currently overflowed, or looks like it might have overflowed in the\r
54  * past.\r
55  *\r
56  * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check\r
57  * the current stack state only - comparing the current top of stack value to\r
58  * the stack limit.  Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1\r
59  * will also cause the last few stack bytes to be checked to ensure the value\r
60  * to which the bytes were set when the task was created have not been \r
61  * overwritten.  Note this second test does not guarantee that an overflowed\r
62  * stack will always be recognised.\r
63  */\r
64 \r
65 /*-----------------------------------------------------------*/\r
66 \r
67 #if( configCHECK_FOR_STACK_OVERFLOW == 0 )\r
68 \r
69         /* FreeRTOSConfig.h is not set to check for stack overflows. */\r
70         #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()\r
71         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()\r
72 \r
73 #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */\r
74 /*-----------------------------------------------------------*/\r
75 \r
76 #if( configCHECK_FOR_STACK_OVERFLOW == 1 )\r
77 \r
78         /* FreeRTOSConfig.h is only set to use the first method of\r
79         overflow checking. */\r
80         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()\r
81 \r
82 #endif\r
83 /*-----------------------------------------------------------*/\r
84 \r
85 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) )\r
86 \r
87         /* Only the current stack state is to be checked. */\r
88         #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()                                                                                                            \\r
89         {                                                                                                                                                                                                       \\r
90         extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );              \\r
91                                                                                                                                                                                                                 \\r
92                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
93                 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack )                                                                               \\r
94                 {                                                                                                                                                                                               \\r
95                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );        \\r
96                 }                                                                                                                                                                                               \\r
97         }\r
98 \r
99 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\r
100 /*-----------------------------------------------------------*/\r
101 \r
102 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )\r
103 \r
104         /* Only the current stack state is to be checked. */\r
105         #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()                                                                                                            \\r
106         {                                                                                                                                                                                                       \\r
107         extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );              \\r
108                                                                                                                                                                                                                 \\r
109                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
110                 if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack )                                                                  \\r
111                 {                                                                                                                                                                                               \\r
112                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );        \\r
113                 }                                                                                                                                                                                               \\r
114         }\r
115 \r
116 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\r
117 /*-----------------------------------------------------------*/\r
118 \r
119 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )\r
120 \r
121         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                                   \\r
122         {                                                                                                                                                                                                                                                                                               \\r
123         extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );                                                                                                      \\r
124         static const unsigned char ucExpectedStackBytes[] = {   tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
125                                                                                                                                 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                                                                                                                                                                                                                                                                                                         \\r
130                                                                                                                                                                                                                                                                                                         \\r
131                 /* Has the extremity of the task stack ever been written over? */                                                                                                                                                       \\r
132                 if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )                                          \\r
133                 {                                                                                                                                                                                                                                                                                       \\r
134                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                                                \\r
135                 }                                                                                                                                                                                                                                                                                       \\r
136         }\r
137 \r
138 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
139 /*-----------------------------------------------------------*/\r
140 \r
141 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )\r
142 \r
143         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                                   \\r
144         {                                                                                                                                                                                                                                                                                               \\r
145         extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName );                                                                                                      \\r
146         char *pcEndOfStack = ( char * ) pxCurrentTCB->pxEndOfStack;                                                                                                                                                             \\r
147         static const unsigned char ucExpectedStackBytes[] = {   tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
148                                                                                                                                 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                                                                                                                                                                                                                                                                                                         \\r
153                                                                                                                                                                                                                                                                                                         \\r
154                 pcEndOfStack -= sizeof( ucExpectedStackBytes );                                                                                                                                                                                         \\r
155                                                                                                                                                                                                                                                                                                         \\r
156                 /* Has the extremity of the task stack ever been written over? */                                                                                                                                                       \\r
157                 if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )                                                           \\r
158                 {                                                                                                                                                                                                                                                                                       \\r
159                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                                                \\r
160                 }                                                                                                                                                                                                                                                                                       \\r
161         }\r
162 \r
163 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
164 /*-----------------------------------------------------------*/\r
165 \r
166 #endif /* STACK_MACROS_H */\r
167 \r