Implement get core ID with interrupt disabled

This commit is contained in:
Ching-Hsin,Lee 2024-12-14 11:21:04 +08:00
parent b6382df843
commit 23daad03f6
2 changed files with 54 additions and 48 deletions

View file

@ -158,10 +158,10 @@ void vYieldCore( int xCoreID );
#define portCRITICAL_NESTING_IN_TCB 0 #define portCRITICAL_NESTING_IN_TCB 0
extern UBaseType_t uxCriticalNestings[ configNUMBER_OF_CORES ]; extern UBaseType_t uxCriticalNestings[ configNUMBER_OF_CORES ];
#define portGET_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ] ) #define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( uxCriticalNestings[ ( xCoreID ) ] )
#define portSET_CRITICAL_NESTING_COUNT( x ) ( uxCriticalNestings[ portGET_CORE_ID() ] = ( x ) ) #define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( uxCriticalNestings[ ( xCoreID ) ] = ( x ) )
#define portINCREMENT_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ]++ ) #define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( uxCriticalNestings[ ( xCoreID ) ]++ )
#define portDECREMENT_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ]-- ) #define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( uxCriticalNestings[ ( xCoreID ) ]-- )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/

22
tasks.c
View file

@ -317,10 +317,10 @@
#define taskATTRIBUTE_IS_IDLE ( UBaseType_t ) ( 1U << 0U ) #define taskATTRIBUTE_IS_IDLE ( UBaseType_t ) ( 1U << 0U )
#if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) )
#define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting ) #define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting )
#define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting = ( x ) ) #define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting = ( x ) )
#define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting++ ) #define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting++ )
#define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting-- ) #define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting-- )
#endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) */ #endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) */
#define taskBITS_PER_BYTE ( ( size_t ) 8 ) #define taskBITS_PER_BYTE ( ( size_t ) 8 )
@ -6941,10 +6941,14 @@ static void prvResetNextTaskUnblockTime( void )
*/ */
void vTaskYieldWithinAPI( void ) void vTaskYieldWithinAPI( void )
{ {
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); UBaseType_t ulState;
traceENTER_vTaskYieldWithinAPI(); traceENTER_vTaskYieldWithinAPI();
ulState = portSET_INTERRUPT_MASK();
{
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U )
{ {
portYIELD(); portYIELD();
@ -6953,6 +6957,8 @@ static void prvResetNextTaskUnblockTime( void )
{ {
xYieldPendings[ xCoreID ] = pdTRUE; xYieldPendings[ xCoreID ] = pdTRUE;
} }
}
portCLEAR_INTERRUPT_MASK( ulState );
traceRETURN_vTaskYieldWithinAPI(); traceRETURN_vTaskYieldWithinAPI();
} }
@ -7001,7 +7007,7 @@ static void prvResetNextTaskUnblockTime( void )
traceENTER_vTaskEnterCritical(); traceENTER_vTaskEnterCritical();
portDISABLE_INTERRUPTS(); portDISABLE_INTERRUPTS();
{
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID(); const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
if( xSchedulerRunning != pdFALSE ) if( xSchedulerRunning != pdFALSE )
@ -7038,6 +7044,7 @@ static void prvResetNextTaskUnblockTime( void )
{ {
mtCOVERAGE_TEST_MARKER(); mtCOVERAGE_TEST_MARKER();
} }
}
traceRETURN_vTaskEnterCritical(); traceRETURN_vTaskEnterCritical();
} }
@ -7051,14 +7058,13 @@ static void prvResetNextTaskUnblockTime( void )
UBaseType_t vTaskEnterCriticalFromISR( void ) UBaseType_t vTaskEnterCriticalFromISR( void )
{ {
UBaseType_t uxSavedInterruptStatus = 0; UBaseType_t uxSavedInterruptStatus = 0;
BaseType_t xCoreID; const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
traceENTER_vTaskEnterCriticalFromISR(); traceENTER_vTaskEnterCriticalFromISR();
if( xSchedulerRunning != pdFALSE ) if( xSchedulerRunning != pdFALSE )
{ {
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
xCoreID = ( BaseType_t ) portGET_CORE_ID();
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U ) if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U )
{ {