stack_macros.h
Go to the documentation of this file.
1 /*
2  * FreeRTOS Kernel V10.0.0
3  * Copyright (C) 2017 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. If you wish to use our Amazon
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  *
23  * http://www.FreeRTOS.org
24  * http://aws.amazon.com/freertos
25  *
26  * 1 tab == 4 spaces!
27  */
28 
29 #ifndef STACK_MACROS_H
30 #define STACK_MACROS_H
31 
32 /*
33  * Call the stack overflow hook function if the stack of the task being swapped
34  * out is currently overflowed, or looks like it might have overflowed in the
35  * past.
36  *
37  * Setting configCHECK_FOR_STACK_OVERFLOW to 1 will cause the macro to check
38  * the current stack state only - comparing the current top of stack value to
39  * the stack limit. Setting configCHECK_FOR_STACK_OVERFLOW to greater than 1
40  * will also cause the last few stack bytes to be checked to ensure the value
41  * to which the bytes were set when the task was created have not been
42  * overwritten. Note this second test does not guarantee that an overflowed
43  * stack will always be recognised.
44  */
45 
46 /*-----------------------------------------------------------*/
47 
48 #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) )
49 
50  /* Only the current stack state is to be checked. */
51  #define taskCHECK_FOR_STACK_OVERFLOW() \
52  { \
53  /* Is the currently saved stack pointer within the stack limit? */ \
54  if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack ) \
55  { \
56  vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
57  } \
58  }
59 
60 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
61 /*-----------------------------------------------------------*/
62 
63 #if( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) )
64 
65  /* Only the current stack state is to be checked. */
66  #define taskCHECK_FOR_STACK_OVERFLOW() \
67  { \
68  \
69  /* Is the currently saved stack pointer within the stack limit? */ \
70  if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack ) \
71  { \
72  vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
73  } \
74  }
75 
76 #endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
77 /*-----------------------------------------------------------*/
78 
79 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
80 
81  #define taskCHECK_FOR_STACK_OVERFLOW() \
82  { \
83  const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
84  const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \
85  \
86  if( ( pulStack[ 0 ] != ulCheckValue ) || \
87  ( pulStack[ 1 ] != ulCheckValue ) || \
88  ( pulStack[ 2 ] != ulCheckValue ) || \
89  ( pulStack[ 3 ] != ulCheckValue ) ) \
90  { \
91  vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
92  } \
93  }
94 
95 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
96 /*-----------------------------------------------------------*/
97 
98 #if( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) )
99 
100  #define taskCHECK_FOR_STACK_OVERFLOW() \
101  { \
102  int8_t *pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \
103  static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
104  tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
105  tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
106  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  \
109  \
110  pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
111  \
112  /* Has the extremity of the task stack ever been written over? */ \
113  if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
114  { \
115  vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
116  } \
117  }
118 
119 #endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
120 /*-----------------------------------------------------------*/
121 
122 /* Remove stack overflow macro if not being used. */
123 #ifndef taskCHECK_FOR_STACK_OVERFLOW
124  #define taskCHECK_FOR_STACK_OVERFLOW()
125 #endif
126 
127 
128 
129 #endif /* STACK_MACROS_H */
130 


inertial_sense_ros
Author(s):
autogenerated on Sat Sep 19 2020 03:19:05