]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/include/StackMacros.h
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Source / include / StackMacros.h
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 #ifndef STACK_MACROS_H\r
71 #define STACK_MACROS_H\r
72 \r
73 /*\r
74  * Call the stack overflow hook function if the stack of the task being swapped\r
75  * out is currently overflowed, or looks like it might have overflowed in the\r
76  * past.\r
77  *\r
78  * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check\r
79  * the current stack state only - comparing the current top of stack value to\r
80  * the stack limit.  Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1\r
81  * will also cause the last few stack bytes to be checked to ensure the value\r
82  * to which the bytes were set when the task was created have not been\r
83  * overwritten.  Note this second test does not guarantee that an overflowed\r
84  * stack will always be recognised.\r
85  */\r
86 \r
87 /*-----------------------------------------------------------*/\r
88 \r
89 #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) )\r
90 \r
91         /* Only the current stack state is to be checked. */\r
92         #define taskCHECK_FOR_STACK_OVERFLOW()                                                                                                                          \\r
93         {                                                                                                                                                                                                       \\r
94                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
95                 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack )                                                                               \\r
96                 {                                                                                                                                                                                               \\r
97                         vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );       \\r
98                 }                                                                                                                                                                                               \\r
99         }\r
100 \r
101 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\r
102 /*-----------------------------------------------------------*/\r
103 \r
104 #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) )\r
105 \r
106         /* Only the current stack state is to be checked. */\r
107         #define taskCHECK_FOR_STACK_OVERFLOW()                                                                                                                          \\r
108         {                                                                                                                                                                                                       \\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( ( TaskHandle_t ) 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 taskCHECK_FOR_STACK_OVERFLOW()                                                                                                                          \\r
123         {                                                                                                                                                                                                       \\r
124                 const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack;                                                 \\r
125                 const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5;                                                                                  \\r
126                                                                                                                                                                                                                 \\r
127                 if( ( pulStack[ 0 ] != ulCheckValue ) ||                                                                                                \\r
128                         ( pulStack[ 1 ] != ulCheckValue ) ||                                                                                            \\r
129                         ( pulStack[ 2 ] != ulCheckValue ) ||                                                                                            \\r
130                         ( pulStack[ 3 ] != ulCheckValue ) )                                                                                             \\r
131                 {                                                                                                                                                                                               \\r
132                         vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );       \\r
133                 }                                                                                                                                                                                               \\r
134         }\r
135 \r
136 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
137 /*-----------------------------------------------------------*/\r
138 \r
139 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )\r
140 \r
141         #define taskCHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                          \\r
142         {                                                                                                                                                                                                                                                                       \\r
143         int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack;                                                                                                                                         \\r
144         static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
145                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
146                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
147                                                                                                         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                                                                                                                                                                                                                                                                                 \\r
150                                                                                                                                                                                                                                                                                 \\r
151                 pcEndOfStack -= sizeof( ucExpectedStackBytes );                                                                                                                                                                 \\r
152                                                                                                                                                                                                                                                                                 \\r
153                 /* Has the extremity of the task stack ever been written over? */                                                                                                                               \\r
154                 if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )                                   \\r
155                 {                                                                                                                                                                                                                                                               \\r
156                         vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                       \\r
157                 }                                                                                                                                                                                                                                                               \\r
158         }\r
159 \r
160 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
161 /*-----------------------------------------------------------*/\r
162 \r
163 /* Remove stack overflow macro if not being used. */\r
164 #ifndef taskCHECK_FOR_STACK_OVERFLOW\r
165         #define taskCHECK_FOR_STACK_OVERFLOW()\r
166 #endif\r
167 \r
168 \r
169 \r
170 #endif /* STACK_MACROS_H */\r
171 \r