]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/include/StackMacros.h
31f59de49a5ec6e69af585a55093b419fc5c6844
[freertos] / FreeRTOS / Source / include / StackMacros.h
1 /*\r
2     FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
5 \r
6     ***************************************************************************\r
7      *                                                                       *\r
8      *    FreeRTOS provides completely free yet professionally developed,    *\r
9      *    robust, strictly quality controlled, supported, and cross          *\r
10      *    platform software that has become a de facto standard.             *\r
11      *                                                                       *\r
12      *    Help yourself get started quickly and support the FreeRTOS         *\r
13      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
14      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
15      *                                                                       *\r
16      *    Thank you!                                                         *\r
17      *                                                                       *\r
18     ***************************************************************************\r
19 \r
20     This file is part of the FreeRTOS distribution.\r
21 \r
22     FreeRTOS is free software; you can redistribute it and/or modify it under\r
23     the terms of the GNU General Public License (version 2) as published by the\r
24     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
25 \r
26     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
27     >>! a combined work that includes FreeRTOS without being obliged to provide\r
28     >>! the source code for proprietary components outside of the FreeRTOS\r
29     >>! kernel.\r
30 \r
31     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
32     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
33     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
34     link: http://www.freertos.org/a00114.html\r
35 \r
36     1 tab == 4 spaces!\r
37 \r
38     ***************************************************************************\r
39      *                                                                       *\r
40      *    Having a problem?  Start by reading the FAQ "My application does   *\r
41      *    not run, what could be wrong?"                                     *\r
42      *                                                                       *\r
43      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
44      *                                                                       *\r
45     ***************************************************************************\r
46 \r
47     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
48     license and Real Time Engineers Ltd. contact details.\r
49 \r
50     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
51     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
52     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
53 \r
54     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
55     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
56     licenses offer ticketed support, indemnification and middleware.\r
57 \r
58     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
59     engineered and independently SIL3 certified version for use in safety and\r
60     mission critical applications that require provable dependability.\r
61 \r
62     1 tab == 4 spaces!\r
63 */\r
64 \r
65 #ifndef STACK_MACROS_H\r
66 #define STACK_MACROS_H\r
67 \r
68 /*\r
69  * Call the stack overflow hook function if the stack of the task being swapped\r
70  * out is currently overflowed, or looks like it might have overflowed in the\r
71  * past.\r
72  *\r
73  * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check\r
74  * the current stack state only - comparing the current top of stack value to\r
75  * the stack limit.  Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1\r
76  * will also cause the last few stack bytes to be checked to ensure the value\r
77  * to which the bytes were set when the task was created have not been\r
78  * overwritten.  Note this second test does not guarantee that an overflowed\r
79  * stack will always be recognised.\r
80  */\r
81 \r
82 /*-----------------------------------------------------------*/\r
83 \r
84 #if( configCHECK_FOR_STACK_OVERFLOW == 0 )\r
85 \r
86         /* FreeRTOSConfig.h is not set to check for stack overflows. */\r
87         #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()\r
88         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()\r
89 \r
90 #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */\r
91 /*-----------------------------------------------------------*/\r
92 \r
93 #if( configCHECK_FOR_STACK_OVERFLOW == 1 )\r
94 \r
95         /* FreeRTOSConfig.h is only set to use the first method of\r
96         overflow checking. */\r
97         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()\r
98 \r
99 #endif\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                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
108                 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack )                                                                               \\r
109                 {                                                                                                                                                                                               \\r
110                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );        \\r
111                 }                                                                                                                                                                                               \\r
112         }\r
113 \r
114 #endif /* configCHECK_FOR_STACK_OVERFLOW > 0 */\r
115 /*-----------------------------------------------------------*/\r
116 \r
117 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )\r
118 \r
119         /* Only the current stack state is to be checked. */\r
120         #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()                                                                                                            \\r
121         {                                                                                                                                                                                                       \\r
122                                                                                                                                                                                                                 \\r
123                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
124                 if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack )                                                                  \\r
125                 {                                                                                                                                                                                               \\r
126                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );        \\r
127                 }                                                                                                                                                                                               \\r
128         }\r
129 \r
130 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\r
131 /*-----------------------------------------------------------*/\r
132 \r
133 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )\r
134 \r
135         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                           \\r
136         {                                                                                                                                                                                                                                                                                       \\r
137         static const unsigned char ucExpectedStackBytes[] = {   tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
138                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
139                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
140                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
141                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE };       \\r
142                                                                                                                                                                                                                                                                                                 \\r
143                                                                                                                                                                                                                                                                                                 \\r
144                 /* Has the extremity of the task stack ever been written over? */                                                                                                                                               \\r
145                 if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )                                  \\r
146                 {                                                                                                                                                                                                                                                                               \\r
147                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                                        \\r
148                 }                                                                                                                                                                                                                                                                               \\r
149         }\r
150 \r
151 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
152 /*-----------------------------------------------------------*/\r
153 \r
154 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )\r
155 \r
156         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                           \\r
157         {                                                                                                                                                                                                                                                                                       \\r
158         char *pcEndOfStack = ( char * ) pxCurrentTCB->pxEndOfStack;                                                                                                                                                                     \\r
159         static const unsigned char ucExpectedStackBytes[] = {   tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
160                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
161                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
162                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
163                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE };       \\r
164                                                                                                                                                                                                                                                                                                 \\r
165                                                                                                                                                                                                                                                                                                 \\r
166                 pcEndOfStack -= sizeof( ucExpectedStackBytes );                                                                                                                                                                                 \\r
167                                                                                                                                                                                                                                                                                                 \\r
168                 /* Has the extremity of the task stack ever been written over? */                                                                                                                                               \\r
169                 if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )                                                   \\r
170                 {                                                                                                                                                                                                                                                                               \\r
171                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                                        \\r
172                 }                                                                                                                                                                                                                                                                               \\r
173         }\r
174 \r
175 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
176 /*-----------------------------------------------------------*/\r
177 \r
178 #endif /* STACK_MACROS_H */\r
179 \r