Skip to content

Commit 55094e2

Browse files
kar-rahul-awsUbuntuchinglee-iotmoninom1aggarg
authored
Fix MISRA_C_2012 rule 13.2 violation (FreeRTOS#855)
* Assign volatile variables to local non-volatile variables before read * Fix stack macro overflow check volatile access * Explicit the read order of volatile variable * Fix issue : ISO C90 forbids mixed declarations and code --------- Co-authored-by: Ubuntu <[email protected]> Co-authored-by: chinglee-iot <[email protected]> Co-authored-by: Monika Singh <[email protected]> Co-authored-by: Gaurav-Aggarwal-AWS <[email protected]>
1 parent d1a0202 commit 55094e2

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

include/stack_macros.h

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@
5656
#if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH < 0 ) )
5757

5858
/* Only the current stack state is to be checked. */
59-
#define taskCHECK_FOR_STACK_OVERFLOW() \
60-
do { \
61-
/* Is the currently saved stack pointer within the stack limit? */ \
62-
if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \
63-
{ \
64-
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
65-
} \
59+
#define taskCHECK_FOR_STACK_OVERFLOW() \
60+
do { \
61+
/* Is the currently saved stack pointer within the stack limit? */ \
62+
if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \
63+
{ \
64+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
65+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
66+
} \
6667
} while( 0 )
6768

6869
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
@@ -71,33 +72,35 @@
7172
#if ( ( configCHECK_FOR_STACK_OVERFLOW == 1 ) && ( portSTACK_GROWTH > 0 ) )
7273

7374
/* Only the current stack state is to be checked. */
74-
#define taskCHECK_FOR_STACK_OVERFLOW() \
75-
do { \
76-
\
77-
/* Is the currently saved stack pointer within the stack limit? */ \
78-
if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \
79-
{ \
80-
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
81-
} \
75+
#define taskCHECK_FOR_STACK_OVERFLOW() \
76+
do { \
77+
\
78+
/* Is the currently saved stack pointer within the stack limit? */ \
79+
if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \
80+
{ \
81+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
82+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
83+
} \
8284
} while( 0 )
8385

8486
#endif /* configCHECK_FOR_STACK_OVERFLOW == 1 */
8587
/*-----------------------------------------------------------*/
8688

8789
#if ( ( configCHECK_FOR_STACK_OVERFLOW > 1 ) && ( portSTACK_GROWTH < 0 ) )
8890

89-
#define taskCHECK_FOR_STACK_OVERFLOW() \
90-
do { \
91-
const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
92-
const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \
93-
\
94-
if( ( pulStack[ 0 ] != ulCheckValue ) || \
95-
( pulStack[ 1 ] != ulCheckValue ) || \
96-
( pulStack[ 2 ] != ulCheckValue ) || \
97-
( pulStack[ 3 ] != ulCheckValue ) ) \
98-
{ \
99-
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
100-
} \
91+
#define taskCHECK_FOR_STACK_OVERFLOW() \
92+
do { \
93+
const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
94+
const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \
95+
\
96+
if( ( pulStack[ 0 ] != ulCheckValue ) || \
97+
( pulStack[ 1 ] != ulCheckValue ) || \
98+
( pulStack[ 2 ] != ulCheckValue ) || \
99+
( pulStack[ 3 ] != ulCheckValue ) ) \
100+
{ \
101+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
102+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
103+
} \
101104
} while( 0 )
102105

103106
#endif /* #if( configCHECK_FOR_STACK_OVERFLOW > 1 ) */
@@ -120,7 +123,8 @@
120123
/* Has the extremity of the task stack ever been written over? */ \
121124
if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
122125
{ \
123-
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \
126+
char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
127+
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
124128
} \
125129
} while( 0 )
126130

tasks.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3916,7 +3916,8 @@ void vTaskSuspendAll( void )
39163916
}
39173917
else
39183918
{
3919-
xReturn = xNextTaskUnblockTime - xTickCount;
3919+
xReturn = xNextTaskUnblockTime;
3920+
xReturn -= xTickCount;
39203921
}
39213922

39223923
return xReturn;
@@ -4549,14 +4550,17 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char
45494550

45504551
void vTaskStepTick( TickType_t xTicksToJump )
45514552
{
4553+
TickType_t xUpdatedTickCount;
4554+
45524555
traceENTER_vTaskStepTick( xTicksToJump );
45534556

45544557
/* Correct the tick count value after a period during which the tick
45554558
* was suppressed. Note this does *not* call the tick hook function for
45564559
* each stepped tick. */
4557-
configASSERT( ( xTickCount + xTicksToJump ) <= xNextTaskUnblockTime );
4560+
xUpdatedTickCount = xTickCount + xTicksToJump;
4561+
configASSERT( xUpdatedTickCount <= xNextTaskUnblockTime );
45584562

4559-
if( ( xTickCount + xTicksToJump ) == xNextTaskUnblockTime )
4563+
if( xUpdatedTickCount == xNextTaskUnblockTime )
45604564
{
45614565
/* Arrange for xTickCount to reach xNextTaskUnblockTime in
45624566
* xTaskIncrementTick() when the scheduler resumes. This ensures
@@ -8450,6 +8454,8 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
84508454
{
84518455
TickType_t xTimeToWake;
84528456
const TickType_t xConstTickCount = xTickCount;
8457+
List_t * const pxDelayedList = pxDelayedTaskList;
8458+
List_t * const pxOverflowDelayedList = pxOverflowDelayedTaskList;
84538459

84548460
#if ( INCLUDE_xTaskAbortDelay == 1 )
84558461
{
@@ -8497,14 +8503,14 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
84978503
/* Wake time has overflowed. Place this item in the overflow
84988504
* list. */
84998505
traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST();
8500-
vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );
8506+
vListInsert( pxOverflowDelayedList, &( pxCurrentTCB->xStateListItem ) );
85018507
}
85028508
else
85038509
{
85048510
/* The wake time has not overflowed, so the current block list
85058511
* is used. */
85068512
traceMOVED_TASK_TO_DELAYED_LIST();
8507-
vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );
8513+
vListInsert( pxDelayedList, &( pxCurrentTCB->xStateListItem ) );
85088514

85098515
/* If the task entering the blocked state was placed at the
85108516
* head of the list of blocked tasks then xNextTaskUnblockTime
@@ -8534,13 +8540,13 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
85348540
{
85358541
traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST();
85368542
/* Wake time has overflowed. Place this item in the overflow list. */
8537-
vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );
8543+
vListInsert( pxOverflowDelayedList, &( pxCurrentTCB->xStateListItem ) );
85388544
}
85398545
else
85408546
{
85418547
traceMOVED_TASK_TO_DELAYED_LIST();
85428548
/* The wake time has not overflowed, so the current block list is used. */
8543-
vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) );
8549+
vListInsert( pxDelayedList, &( pxCurrentTCB->xStateListItem ) );
85448550

85458551
/* If the task entering the blocked state was placed at the head of the
85468552
* list of blocked tasks then xNextTaskUnblockTime needs to be updated

0 commit comments

Comments
 (0)