]> begriffs open source - cmsis-freertos/blob - Source/include/StackMacros.h
Updated to FreeRTOS V10.1.1
[cmsis-freertos] / Source / include / StackMacros.h
1 /*
2  * FreeRTOS Kernel V10.1.1
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 #ifndef STACK_MACROS_H
29 #define STACK_MACROS_H
30
31 #ifndef _MSC_VER /* Visual Studio doesn't support #warning. */
32         #warning The name of this file has changed to stack_macros.h.  Please update your code accordingly.  This source file (which has the original name) will be removed in future released.
33 #endif
34
35 /*
36  * Call the stack overflow hook function if the stack of the task being swapped
37  * out is currently overflowed, or looks like it might have overflowed in the
38  * past.
39  *
40  * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
41  * the current stack state only - comparing the current top of stack value to
42  * the stack limit.  Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
43  * will also cause the last few stack bytes to be checked to ensure the value
44  * to which the bytes were set when the task was created have not been
45  * overwritten.  Note this second test does not guarantee that an overflowed
46  * stack will always be recognised.
47  */
48
49 /*-----------------------------------------------------------*/
50
51 #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) )
52
53         /* Only the current stack state is to be checked. */
54         #define taskCHECK_FOR_STACK_OVERFLOW()                                                                                                                          \
55         {                                                                                                                                                                                                       \
56                 /* Is the currently saved stack pointer within the stack limit? */                                                              \
57                 if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack )                                                                               \
58                 {                                                                                                                                                                                               \
59                         vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );       \
60                 }                                                                                                                                                                                               \
61         }
62
63 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
64 /*-----------------------------------------------------------*/
65
66 #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) )
67
68         /* Only the current stack state is to be checked. */
69         #define taskCHECK_FOR_STACK_OVERFLOW()                                                                                                                          \
70         {                                                                                                                                                                                                       \
71                                                                                                                                                                                                                 \
72                 /* Is the currently saved stack pointer within the stack limit? */                                                              \
73                 if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack )                                                                  \
74                 {                                                                                                                                                                                               \
75                         vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );       \
76                 }                                                                                                                                                                                               \
77         }
78
79 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
80 /*-----------------------------------------------------------*/
81
82 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
83
84         #define taskCHECK_FOR_STACK_OVERFLOW()                                                                                                                          \
85         {                                                                                                                                                                                                       \
86                 const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack;                                                 \
87                 const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5;                                                                                  \
88                                                                                                                                                                                                                 \
89                 if( ( pulStack[ 0 ] != ulCheckValue ) ||                                                                                                \
90                         ( pulStack[ 1 ] != ulCheckValue ) ||                                                                                            \
91                         ( pulStack[ 2 ] != ulCheckValue ) ||                                                                                            \
92                         ( pulStack[ 3 ] != ulCheckValue ) )                                                                                             \
93                 {                                                                                                                                                                                               \
94                         vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );       \
95                 }                                                                                                                                                                                               \
96         }
97
98 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
99 /*-----------------------------------------------------------*/
100
101 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
102
103         #define taskCHECK_FOR_STACK_OVERFLOW()                                                                                                                                                                                          \
104         {                                                                                                                                                                                                                                                                       \
105         int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack;                                                                                                                                         \
106         static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \
107                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \
108                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \
109                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE,         \
110                                                                                                         tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE };       \
111                                                                                                                                                                                                                                                                                 \
112                                                                                                                                                                                                                                                                                 \
113                 pcEndOfStack -= sizeof( ucExpectedStackBytes );                                                                                                                                                                 \
114                                                                                                                                                                                                                                                                                 \
115                 /* Has the extremity of the task stack ever been written over? */                                                                                                                               \
116                 if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 )                                   \
117                 {                                                                                                                                                                                                                                                               \
118                         vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName );                                                                       \
119                 }                                                                                                                                                                                                                                                               \
120         }
121
122 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
123 /*-----------------------------------------------------------*/
124
125 /* Remove stack overflow macro if not being used. */
126 #ifndef taskCHECK_FOR_STACK_OVERFLOW
127         #define taskCHECK_FOR_STACK_OVERFLOW()
128 #endif
129
130
131
132 #endif /* STACK_MACROS_H */
133