]> git.sur5r.net Git - freertos/blob
1114b6d29d07273ae1f467e3ffc47954841d17ca
[freertos] /
1 /*\r
2     FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3         \r
4 \r
5         FreeRTOS supports many tools and architectures. V7.0.0 is sponsored by:\r
6         Atollic AB - Atollic provides professional embedded systems development \r
7         tools for C/C++ development, code analysis and test automation.  \r
8         See http://www.atollic.com\r
9         \r
10 \r
11     ***************************************************************************\r
12      *                                                                       *\r
13      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
14      *    Complete, revised, and edited pdf reference manuals are also       *\r
15      *    available.                                                         *\r
16      *                                                                       *\r
17      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
18      *    ensuring you get running as quickly as possible and with an        *\r
19      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
20      *    the FreeRTOS project to continue with its mission of providing     *\r
21      *    professional grade, cross platform, de facto standard solutions    *\r
22      *    for microcontrollers - completely free of charge!                  *\r
23      *                                                                       *\r
24      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
25      *                                                                       *\r
26      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
27      *                                                                       *\r
28     ***************************************************************************\r
29 \r
30 \r
31     This file is part of the FreeRTOS distribution.\r
32 \r
33     FreeRTOS is free software; you can redistribute it and/or modify it under\r
34     the terms of the GNU General Public License (version 2) as published by the\r
35     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
36     >>>NOTE<<< The modification to the GPL is included to allow you to\r
37     distribute a combined work that includes FreeRTOS without being obliged to\r
38     provide the source code for proprietary components outside of the FreeRTOS\r
39     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
40     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
41     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
42     more details. You should have received a copy of the GNU General Public\r
43     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
44     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
45     by writing to Richard Barry, contact details for whom are available on the\r
46     FreeRTOS WEB site.\r
47 \r
48     1 tab == 4 spaces!\r
49 \r
50     http://www.FreeRTOS.org - Documentation, latest information, license and\r
51     contact details.\r
52 \r
53     http://www.SafeRTOS.com - A version that is certified for use in safety\r
54     critical systems.\r
55 \r
56     http://www.OpenRTOS.com - Commercial support, development, porting,\r
57     licensing and training services.\r
58 */\r
59 \r
60 #ifndef STACK_MACROS_H\r
61 #define STACK_MACROS_H\r
62 \r
63 /*\r
64  * Call the stack overflow hook function if the stack of the task being swapped\r
65  * out is currently overflowed, or looks like it might have overflowed in the\r
66  * past.\r
67  *\r
68  * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check\r
69  * the current stack state only - comparing the current top of stack value to\r
70  * the stack limit.  Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1\r
71  * will also cause the last few stack bytes to be checked to ensure the value\r
72  * to which the bytes were set when the task was created have not been\r
73  * overwritten.  Note this second test does not guarantee that an overflowed\r
74  * stack will always be recognised.\r
75  */\r
76 \r
77 /*-----------------------------------------------------------*/\r
78 \r
79 #if( configCHECK_FOR_STACK_OVERFLOW == 0 )\r
80 \r
81         /* FreeRTOSConfig.h is not set to check for stack overflows. */\r
82         #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()\r
83         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()\r
84 \r
85 #endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */\r
86 /*-----------------------------------------------------------*/\r
87 \r
88 #if( configCHECK_FOR_STACK_OVERFLOW == 1 )\r
89 \r
90         /* FreeRTOSConfig.h is only set to use the first method of\r
91         overflow checking. */\r
92         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()\r
93 \r
94 #endif\r
95 /*-----------------------------------------------------------*/\r
96 \r
97 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) )\r
98 \r
99         /* Only the current stack state is to be checked. */\r
100         #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()                                                                                                            \\r
101         {                                                                                                                                                                                                       \\r
102                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
103                 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack )                                                                               \\r
104                 {                                                                                                                                                                                               \\r
105                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );        \\r
106                 }                                                                                                                                                                                               \\r
107         }\r
108 \r
109 #endif /* configCHECK_FOR_STACK_OVERFLOW > 0 */\r
110 /*-----------------------------------------------------------*/\r
111 \r
112 #if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) )\r
113 \r
114         /* Only the current stack state is to be checked. */\r
115         #define taskFIRST_CHECK_FOR_STACK_OVERFLOW()                                                                                                            \\r
116         {                                                                                                                                                                                                       \\r
117                                                                                                                                                                                                                 \\r
118                 /* Is the currently saved stack pointer within the stack limit? */                                                              \\r
119                 if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack )                                                                  \\r
120                 {                                                                                                                                                                                               \\r
121                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );        \\r
122                 }                                                                                                                                                                                               \\r
123         }\r
124 \r
125 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */\r
126 /*-----------------------------------------------------------*/\r
127 \r
128 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )\r
129 \r
130         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                           \\r
131         {                                                                                                                                                                                                                                                                                       \\r
132         static const unsigned char ucExpectedStackBytes[] = {   tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
133                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
134                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
135                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
136                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE };       \\r
137                                                                                                                                                                                                                                                                                                 \\r
138                                                                                                                                                                                                                                                                                                 \\r
139                 /* Has the extremity of the task stack ever been written over? */                                                                                                                                               \\r
140                 if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )                                  \\r
141                 {                                                                                                                                                                                                                                                                               \\r
142                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                                        \\r
143                 }                                                                                                                                                                                                                                                                               \\r
144         }\r
145 \r
146 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
147 /*-----------------------------------------------------------*/\r
148 \r
149 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )\r
150 \r
151         #define taskSECOND_CHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                           \\r
152         {                                                                                                                                                                                                                                                                                       \\r
153         char *pcEndOfStack = ( char * ) pxCurrentTCB->pxEndOfStack;                                                                                                                                                                     \\r
154         static const unsigned char ucExpectedStackBytes[] = {   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                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
157                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \\r
158                                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE };       \\r
159                                                                                                                                                                                                                                                                                                 \\r
160                                                                                                                                                                                                                                                                                                 \\r
161                 pcEndOfStack -= sizeof( ucExpectedStackBytes );                                                                                                                                                                                 \\r
162                                                                                                                                                                                                                                                                                                 \\r
163                 /* Has the extremity of the task stack ever been written over? */                                                                                                                                               \\r
164                 if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )                                                   \\r
165                 {                                                                                                                                                                                                                                                                               \\r
166                         vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                                        \\r
167                 }                                                                                                                                                                                                                                                                               \\r
168         }\r
169 \r
170 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 #endif /* STACK_MACROS_H */\r
174 \r