Fix MISRA_C_2012 rule 13.2 violation (#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 <ubuntu@ip-172-31-34-245.ap-northeast-1.compute.internal>
Co-authored-by: chinglee-iot <61685396+chinglee-iot@users.noreply.github.com>
Co-authored-by: Monika Singh <moninom@amazon.com>
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
This commit is contained in:
Rahul Kar 2023-12-07 12:15:09 +05:30 committed by GitHub
parent d1a0202125
commit 55094e2ddf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 35 deletions

View file

@ -61,7 +61,8 @@
/* Is the currently saved stack pointer within the stack limit? */ \ /* Is the currently saved stack pointer within the stack limit? */ \
if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \ if( pxCurrentTCB->pxTopOfStack <= pxCurrentTCB->pxStack + portSTACK_LIMIT_PADDING ) \
{ \ { \
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
} \ } \
} while( 0 ) } while( 0 )
@ -77,7 +78,8 @@
/* Is the currently saved stack pointer within the stack limit? */ \ /* Is the currently saved stack pointer within the stack limit? */ \
if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \ if( pxCurrentTCB->pxTopOfStack >= pxCurrentTCB->pxEndOfStack - portSTACK_LIMIT_PADDING ) \
{ \ { \
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
} \ } \
} while( 0 ) } while( 0 )
@ -89,14 +91,15 @@
#define taskCHECK_FOR_STACK_OVERFLOW() \ #define taskCHECK_FOR_STACK_OVERFLOW() \
do { \ do { \
const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \ const uint32_t * const pulStack = ( uint32_t * ) pxCurrentTCB->pxStack; \
const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5U; \ const uint32_t ulCheckValue = ( uint32_t ) 0xa5a5a5a5; \
\ \
if( ( pulStack[ 0 ] != ulCheckValue ) || \ if( ( pulStack[ 0 ] != ulCheckValue ) || \
( pulStack[ 1 ] != ulCheckValue ) || \ ( pulStack[ 1 ] != ulCheckValue ) || \
( pulStack[ 2 ] != ulCheckValue ) || \ ( pulStack[ 2 ] != ulCheckValue ) || \
( pulStack[ 3 ] != ulCheckValue ) ) \ ( pulStack[ 3 ] != ulCheckValue ) ) \
{ \ { \
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
} \ } \
} while( 0 ) } while( 0 )
@ -120,7 +123,8 @@
/* Has the extremity of the task stack ever been written over? */ \ /* Has the extremity of the task stack ever been written over? */ \
if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \ if( memcmp( ( void * ) pcEndOfStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) != 0 ) \
{ \ { \
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pxCurrentTCB->pcTaskName ); \ char * pcOverflowTaskName = pxCurrentTCB->pcTaskName; \
vApplicationStackOverflowHook( ( TaskHandle_t ) pxCurrentTCB, pcOverflowTaskName ); \
} \ } \
} while( 0 ) } while( 0 )

20
tasks.c
View file

@ -3916,7 +3916,8 @@ void vTaskSuspendAll( void )
} }
else else
{ {
xReturn = xNextTaskUnblockTime - xTickCount; xReturn = xNextTaskUnblockTime;
xReturn -= xTickCount;
} }
return xReturn; return xReturn;
@ -4549,14 +4550,17 @@ char * pcTaskGetName( TaskHandle_t xTaskToQuery ) /*lint !e971 Unqualified char
void vTaskStepTick( TickType_t xTicksToJump ) void vTaskStepTick( TickType_t xTicksToJump )
{ {
TickType_t xUpdatedTickCount;
traceENTER_vTaskStepTick( xTicksToJump ); traceENTER_vTaskStepTick( xTicksToJump );
/* Correct the tick count value after a period during which the tick /* Correct the tick count value after a period during which the tick
* was suppressed. Note this does *not* call the tick hook function for * was suppressed. Note this does *not* call the tick hook function for
* each stepped tick. */ * each stepped tick. */
configASSERT( ( xTickCount + xTicksToJump ) <= xNextTaskUnblockTime ); xUpdatedTickCount = xTickCount + xTicksToJump;
configASSERT( xUpdatedTickCount <= xNextTaskUnblockTime );
if( ( xTickCount + xTicksToJump ) == xNextTaskUnblockTime ) if( xUpdatedTickCount == xNextTaskUnblockTime )
{ {
/* Arrange for xTickCount to reach xNextTaskUnblockTime in /* Arrange for xTickCount to reach xNextTaskUnblockTime in
* xTaskIncrementTick() when the scheduler resumes. This ensures * xTaskIncrementTick() when the scheduler resumes. This ensures
@ -8450,6 +8454,8 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
{ {
TickType_t xTimeToWake; TickType_t xTimeToWake;
const TickType_t xConstTickCount = xTickCount; const TickType_t xConstTickCount = xTickCount;
List_t * const pxDelayedList = pxDelayedTaskList;
List_t * const pxOverflowDelayedList = pxOverflowDelayedTaskList;
#if ( INCLUDE_xTaskAbortDelay == 1 ) #if ( INCLUDE_xTaskAbortDelay == 1 )
{ {
@ -8497,14 +8503,14 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
/* Wake time has overflowed. Place this item in the overflow /* Wake time has overflowed. Place this item in the overflow
* list. */ * list. */
traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST();
vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); vListInsert( pxOverflowDelayedList, &( pxCurrentTCB->xStateListItem ) );
} }
else else
{ {
/* The wake time has not overflowed, so the current block list /* The wake time has not overflowed, so the current block list
* is used. */ * is used. */
traceMOVED_TASK_TO_DELAYED_LIST(); traceMOVED_TASK_TO_DELAYED_LIST();
vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); vListInsert( pxDelayedList, &( pxCurrentTCB->xStateListItem ) );
/* If the task entering the blocked state was placed at the /* If the task entering the blocked state was placed at the
* head of the list of blocked tasks then xNextTaskUnblockTime * head of the list of blocked tasks then xNextTaskUnblockTime
@ -8534,13 +8540,13 @@ static void prvAddCurrentTaskToDelayedList( TickType_t xTicksToWait,
{ {
traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(); traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST();
/* Wake time has overflowed. Place this item in the overflow list. */ /* Wake time has overflowed. Place this item in the overflow list. */
vListInsert( pxOverflowDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); vListInsert( pxOverflowDelayedList, &( pxCurrentTCB->xStateListItem ) );
} }
else else
{ {
traceMOVED_TASK_TO_DELAYED_LIST(); traceMOVED_TASK_TO_DELAYED_LIST();
/* The wake time has not overflowed, so the current block list is used. */ /* The wake time has not overflowed, so the current block list is used. */
vListInsert( pxDelayedTaskList, &( pxCurrentTCB->xStateListItem ) ); vListInsert( pxDelayedList, &( pxCurrentTCB->xStateListItem ) );
/* If the task entering the blocked state was placed at the head of the /* If the task entering the blocked state was placed at the head of the
* list of blocked tasks then xNextTaskUnblockTime needs to be updated * list of blocked tasks then xNextTaskUnblockTime needs to be updated