Skip to content

Commit 94e9b88

Browse files
committed
FreeRTOS SMP: direct access to current TCB inside stack macros
1 parent 4ee6a1f commit 94e9b88

File tree

2 files changed

+149
-58
lines changed

2 files changed

+149
-58
lines changed

include/stack_macros.h

Lines changed: 148 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -66,81 +66,172 @@
6666
*/
6767
#if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) )
6868

69-
/* Only the current stack state is to be checked. */
70-
#define taskCHECK_FOR_STACK_OVERFLOW() \
71-
do \
72-
{ \
73-
/* Is the currently saved stack pointer within the stack limit? */ \
74-
if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \
75-
{ \
76-
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
77-
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
78-
} \
79-
} while( 0 )
69+
#if( configNUMBER_OF_CORES == 1 )
70+
71+
/* Only the current stack state is to be checked. */
72+
#define taskCHECK_FOR_STACK_OVERFLOW() \
73+
do \
74+
{ \
75+
/* Is the currently saved stack pointer within the stack limit? */ \
76+
if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \
77+
{ \
78+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
79+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
80+
} \
81+
} while( 0 )
82+
83+
#else
84+
85+
/* Only the current stack state is to be checked. */
86+
#define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \
87+
do \
88+
{ \
89+
const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \
90+
\
91+
/* Is the currently saved stack pointer within the stack limit? */ \
92+
if( pxTCB->pxTopOfStack <= pxTCB->pxStack + portSTACK_LIMIT_PADDING ) \
93+
{ \
94+
char * pcOverflowTaskName = pxTCB->pcTaskName; \
95+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \
96+
} \
97+
} while( 0 )
98+
99+
#endif
80100

81101
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
82102
/*-----------------------------------------------------------*/
83103

84104
#if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) )
85105

86-
/* Only the current stack state is to be checked. */
87-
#define taskCHECK_FOR_STACK_OVERFLOW() \
88-
do \
89-
{ \
90-
/* Is the currently saved stack pointer within the stack limit? */ \
91-
if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \
92-
{ \
93-
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
94-
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
95-
} \
96-
} while( 0 )
106+
#if( configNUMBER_OF_CORES == 1 )
107+
108+
/* Only the current stack state is to be checked. */
109+
#define taskCHECK_FOR_STACK_OVERFLOW() \
110+
do \
111+
{ \
112+
/* Is the currently saved stack pointer within the stack limit? */ \
113+
if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \
114+
{ \
115+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
116+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
117+
} \
118+
} while( 0 )
119+
120+
#else
121+
122+
/* Only the current stack state is to be checked. */
123+
#define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \
124+
do \
125+
{ \
126+
const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \
127+
\
128+
/* Is the currently saved stack pointer within the stack limit? */ \
129+
if( pxTCB->pxTopOfStack >= pxTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \
130+
{ \
131+
char * pcOverflowTaskName = pxTCB->pcTaskName; \
132+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \
133+
} \
134+
} while( 0 )
135+
136+
#endif
97137

98138
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
99139
/*-----------------------------------------------------------*/
100140

101141
#if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) )
102142

103-
#define taskCHECK_FOR_STACK_OVERFLOW() \
104-
do \
105-
{ \
106-
const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
107-
const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \
108-
\
109-
if( ( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) || \
110-
( pulStack[ 0 ] != ulCheckValue ) || \
111-
( pulStack[ 1 ] != ulCheckValue ) || \
112-
( pulStack[ 2 ] != ulCheckValue ) || \
113-
( pulStack[ 3 ] != ulCheckValue ) ) \
114-
{ \
115-
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
116-
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
117-
} \
118-
} while( 0 )
143+
#if( configNUMBER_OF_CORES == 1 )
144+
145+
#define taskCHECK_FOR_STACK_OVERFLOW() \
146+
do \
147+
{ \
148+
const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
149+
const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \
150+
\
151+
if( ( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) || \
152+
( pulStack[ 0 ] != ulCheckValue ) || \
153+
( pulStack[ 1 ] != ulCheckValue ) || \
154+
( pulStack[ 2 ] != ulCheckValue ) || \
155+
( pulStack[ 3 ] != ulCheckValue ) ) \
156+
{ \
157+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
158+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
159+
} \
160+
} while( 0 )
161+
162+
#else
163+
164+
#define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \
165+
do \
166+
{ \
167+
const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
168+
const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \
169+
const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \
170+
\
171+
if( ( pxTCB->pxTopOfStack <= pxTCB->pxStack + portSTACK_LIMIT_PADDING ) || \
172+
( pulStack[ 0 ] != ulCheckValue ) || \
173+
( pulStack[ 1 ] != ulCheckValue ) || \
174+
( pulStack[ 2 ] != ulCheckValue ) || \
175+
( pulStack[ 3 ] != ulCheckValue ) ) \
176+
{ \
177+
char * pcOverflowTaskName = pxTCB->pcTaskName; \
178+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \
179+
} \
180+
} while( 0 )
181+
182+
#endif
119183

120184
#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
121185
/*-----------------------------------------------------------*/
122186

123187
#if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH > 0 ) && ( portUSING_MPU_WRAPPERS != 1 ) )
124188

125-
#define taskCHECK_FOR_STACK_OVERFLOW() \
126-
do \
127-
{ \
128-
int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \
129-
static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
130-
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
131-
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
132-
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
133-
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
134-
\
135-
pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
136-
\
137-
if( ( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) || \
138-
( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) ) \
139-
{ \
140-
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
141-
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
142-
} \
143-
} while( 0 )
189+
#if( configNUMBER_OF_CORES == 1 )
190+
191+
#define taskCHECK_FOR_STACK_OVERFLOW() \
192+
do \
193+
{ \
194+
int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \
195+
static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
196+
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
197+
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
198+
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
199+
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
200+
\
201+
pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
202+
\
203+
if( ( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) || \
204+
( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) ) \
205+
{ \
206+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
207+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
208+
} \
209+
} while( 0 )
210+
211+
#else
212+
213+
#define taskCHECK_FOR_STACK_OVERFLOW( xCoreID ) \
214+
do \
215+
{ \
216+
int8_t * pcEndOfStack = ( int8_t * ) pxCurrentTCB->pxEndOfStack; \
217+
static const uint8_t ucExpectedStackBytes[] = { tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
218+
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
219+
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
220+
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, \
221+
tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE, tskSTACK_FILL_BYTE }; \
222+
const TCB_t * const pxTCB = pxCurrentTCBs[ xCoreID ]; \
223+
\
224+
pcEndOfStack -= sizeof( ucExpectedStackBytes ); \
225+
\
226+
if( ( pxTCB->pxTopOfStack >= pxTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) || \
227+
( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) ) \
228+
{ \
229+
char * pcOverflowTaskName = pxTCB->pcTaskName; \
230+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxTCB, pcOverflowTaskName ); \
231+
} \
232+
} while( 0 )
233+
234+
#endif
144235

145236
#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
146237
/*-----------------------------------------------------------*/

0 commit comments

Comments
 (0)