1 |
/* |
---|
2 |
FreeRTOS V5.4.1 - Copyright (C) 2009 Real Time Engineers Ltd. |
---|
3 |
|
---|
4 |
This file is part of the FreeRTOS distribution. |
---|
5 |
|
---|
6 |
FreeRTOS is free software; you can redistribute it and/or modify it under |
---|
7 |
the terms of the GNU General Public License (version 2) as published by the |
---|
8 |
Free Software Foundation and modified by the FreeRTOS exception. |
---|
9 |
**NOTE** The exception to the GPL is included to allow you to distribute a |
---|
10 |
combined work that includes FreeRTOS without being obliged to provide the |
---|
11 |
source code for proprietary components outside of the FreeRTOS kernel. |
---|
12 |
Alternative commercial license and support terms are also available upon |
---|
13 |
request. See the licensing section of http://www.FreeRTOS.org for full |
---|
14 |
license details. |
---|
15 |
|
---|
16 |
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT |
---|
17 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
18 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
19 |
more details. |
---|
20 |
|
---|
21 |
You should have received a copy of the GNU General Public License along |
---|
22 |
with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59 |
---|
23 |
Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
---|
24 |
|
---|
25 |
|
---|
26 |
*************************************************************************** |
---|
27 |
* * |
---|
28 |
* Looking for a quick start? Then check out the FreeRTOS eBook! * |
---|
29 |
* See http://www.FreeRTOS.org/Documentation for details * |
---|
30 |
* * |
---|
31 |
*************************************************************************** |
---|
32 |
|
---|
33 |
1 tab == 4 spaces! |
---|
34 |
|
---|
35 |
Please ensure to read the configuration and relevant port sections of the |
---|
36 |
online documentation. |
---|
37 |
|
---|
38 |
http://www.FreeRTOS.org - Documentation, latest information, license and |
---|
39 |
contact details. |
---|
40 |
|
---|
41 |
http://www.SafeRTOS.com - A version that is certified for use in safety |
---|
42 |
critical systems. |
---|
43 |
|
---|
44 |
http://www.OpenRTOS.com - Commercial support, development, porting, |
---|
45 |
licensing and training services. |
---|
46 |
*/ |
---|
47 |
|
---|
48 |
#ifndef STACK_MACROS_H |
---|
49 |
#define STACK_MACROS_H |
---|
50 |
|
---|
51 |
/* |
---|
52 |
* Call the stack overflow hook function if the stack of the task being swapped |
---|
53 |
* out is currently overflowed, or looks like it might have overflowed in the |
---|
54 |
* past. |
---|
55 |
* |
---|
56 |
* Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check |
---|
57 |
* the current stack state only - comparing the current top of stack value to |
---|
58 |
* the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1 |
---|
59 |
* will also cause the last few stack bytes to be checked to ensure the value |
---|
60 |
* to which the bytes were set when the task was created have not been |
---|
61 |
* overwritten. Note this second test does not guarantee that an overflowed |
---|
62 |
* stack will always be recognised. |
---|
63 |
*/ |
---|
64 |
|
---|
65 |
/*-----------------------------------------------------------*/ |
---|
66 |
|
---|
67 |
#if( configCHECK_FOR_STACK_OVERFLOW == 0 ) |
---|
68 |
|
---|
69 |
/* FreeRTOSConfig.h is not set to check for stack overflows. */ |
---|
70 |
#define taskFIRST_CHECK_FOR_STACK_OVERFLOW() |
---|
71 |
#define taskSECOND_CHECK_FOR_STACK_OVERFLOW() |
---|
72 |
|
---|
73 |
#endif /* configCHECK_FOR_STACK_OVERFLOW == 0 */ |
---|
74 |
/*-----------------------------------------------------------*/ |
---|
75 |
|
---|
76 |
#if( configCHECK_FOR_STACK_OVERFLOW == 1 ) |
---|
77 |
|
---|
78 |
/* FreeRTOSConfig.h is only set to use the first method of |
---|
79 |
overflow checking. */ |
---|
80 |
#define taskSECOND_CHECK_FOR_STACK_OVERFLOW() |
---|
81 |
|
---|
82 |
#endif |
---|
83 |
/*-----------------------------------------------------------*/ |
---|
84 |
|
---|
85 |
#if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH < 0 ) ) |
---|
86 |
|
---|
87 |
/* Only the current stack state is to be checked. */ |
---|
88 |
#define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \ |
---|
89 |
{ \ |
---|
90 |
extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \ |
---|
91 |
\ |
---|
92 |
/* Is the currently saved stack pointer within the stack limit? */ \ |
---|
93 |
if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \ |
---|
94 |
{ \ |
---|
95 |
vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ |
---|
96 |
} \ |
---|
97 |
} |
---|
98 |
|
---|
99 |
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ |
---|
100 |
/*-----------------------------------------------------------*/ |
---|
101 |
|
---|
102 |
#if( ( configCHECK_FOR_STACK_OVERFLOW > 0 ) && ( portSTACK_GROWTH > 0 ) ) |
---|
103 |
|
---|
104 |
/* Only the current stack state is to be checked. */ |
---|
105 |
#define taskFIRST_CHECK_FOR_STACK_OVERFLOW() \ |
---|
106 |
{ \ |
---|
107 |
extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \ |
---|
108 |
\ |
---|
109 |
/* Is the currently saved stack pointer within the stack limit? */ \ |
---|
110 |
if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \ |
---|
111 |
{ \ |
---|
112 |
vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ |
---|
113 |
} \ |
---|
114 |
} |
---|
115 |
|
---|
116 |
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */ |
---|
117 |
/*-----------------------------------------------------------*/ |
---|
118 |
|
---|
119 |
#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) ) |
---|
120 |
|
---|
121 |
#define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \ |
---|
122 |
{ \ |
---|
123 |
extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \ |
---|
124 |
static const unsigned portCHAR ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
---|
125 |
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
---|
126 |
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
---|
127 |
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
---|
128 |
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ |
---|
129 |
\ |
---|
130 |
\ |
---|
131 |
/* Has the extremity of the task stack ever been written over? */ \ |
---|
132 |
if( memcmp( ( void * ) pxCurrentTCB->pxStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ |
---|
133 |
{ \ |
---|
134 |
vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ |
---|
135 |
} \ |
---|
136 |
} |
---|
137 |
|
---|
138 |
#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ |
---|
139 |
/*-----------------------------------------------------------*/ |
---|
140 |
|
---|
141 |
#if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) ) |
---|
142 |
|
---|
143 |
#define taskSECOND_CHECK_FOR_STACK_OVERFLOW() \ |
---|
144 |
{ \ |
---|
145 |
extern void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName ); \ |
---|
146 |
portCHAR *pcEndOfStack = ( portCHAR * ) pxCurrentTCB->pxEndOfStack; \ |
---|
147 |
static const unsigned portCHAR ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
---|
148 |
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
---|
149 |
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
---|
150 |
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \ |
---|
151 |
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \ |
---|
152 |
\ |
---|
153 |
\ |
---|
154 |
pcEndOfStack -= sizeof( ucExpectedStackBytes ); \ |
---|
155 |
\ |
---|
156 |
/* Has the extremity of the task stack ever been written over? */ \ |
---|
157 |
if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ |
---|
158 |
{ \ |
---|
159 |
vApplicationStackOverflowHook( ( xTaskHandle ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ |
---|
160 |
} \ |
---|
161 |
} |
---|
162 |
|
---|
163 |
#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */ |
---|
164 |
/*-----------------------------------------------------------*/ |
---|
165 |
|
---|
166 |
#endif /* STACK_MACROS_H */ |
---|
167 |
|
---|