Skip to content

Commit 37c71b9

Browse files
authored
Merge pull request #1 from chinglee-iot/update-core-id-fix
Implement get core ID with interrupt disabled
2 parents b6382df + 23daad0 commit 37c71b9

File tree

2 files changed

+52
-46
lines changed

2 files changed

+52
-46
lines changed

portable/ThirdParty/GCC/RP2040/include/portmacro.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,10 @@ void vYieldCore( int xCoreID );
158158
#define portCRITICAL_NESTING_IN_TCB 0
159159

160160
extern UBaseType_t uxCriticalNestings[ configNUMBER_OF_CORES ];
161-
#define portGET_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ] )
162-
#define portSET_CRITICAL_NESTING_COUNT( x ) ( uxCriticalNestings[ portGET_CORE_ID() ] = ( x ) )
163-
#define portINCREMENT_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ]++ )
164-
#define portDECREMENT_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ]-- )
161+
#define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( uxCriticalNestings[ ( xCoreID ) ] )
162+
#define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( uxCriticalNestings[ ( xCoreID ) ] = ( x ) )
163+
#define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( uxCriticalNestings[ ( xCoreID ) ]++ )
164+
#define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( uxCriticalNestings[ ( xCoreID ) ]-- )
165165

166166
/*-----------------------------------------------------------*/
167167

tasks.c

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@
317317
#define taskATTRIBUTE_IS_IDLE ( UBaseType_t ) ( 1U << 0U )
318318

319319
#if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) )
320-
#define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting )
321-
#define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting = ( x ) )
322-
#define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting++ )
323-
#define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ xCoreID ]->uxCriticalNesting-- )
320+
#define portGET_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting )
321+
#define portSET_CRITICAL_NESTING_COUNT( xCoreID, x ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting = ( x ) )
322+
#define portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting++ )
323+
#define portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID ) ( pxCurrentTCBs[ ( xCoreID ) ]->uxCriticalNesting-- )
324324
#endif /* #if ( ( configNUMBER_OF_CORES > 1 ) && ( portCRITICAL_NESTING_IN_TCB == 1 ) ) */
325325

326326
#define taskBITS_PER_BYTE ( ( size_t ) 8 )
@@ -6941,18 +6941,24 @@ static void prvResetNextTaskUnblockTime( void )
69416941
*/
69426942
void vTaskYieldWithinAPI( void )
69436943
{
6944-
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
6944+
UBaseType_t ulState;
69456945

69466946
traceENTER_vTaskYieldWithinAPI();
69476947

6948-
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U )
6948+
ulState = portSET_INTERRUPT_MASK();
69496949
{
6950-
portYIELD();
6951-
}
6952-
else
6953-
{
6954-
xYieldPendings[ xCoreID ] = pdTRUE;
6950+
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
6951+
6952+
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U )
6953+
{
6954+
portYIELD();
6955+
}
6956+
else
6957+
{
6958+
xYieldPendings[ xCoreID ] = pdTRUE;
6959+
}
69556960
}
6961+
portCLEAR_INTERRUPT_MASK( ulState );
69566962

69576963
traceRETURN_vTaskYieldWithinAPI();
69586964
}
@@ -7001,42 +7007,43 @@ static void prvResetNextTaskUnblockTime( void )
70017007
traceENTER_vTaskEnterCritical();
70027008

70037009
portDISABLE_INTERRUPTS();
7004-
7005-
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
7006-
7007-
if( xSchedulerRunning != pdFALSE )
70087010
{
7009-
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U )
7010-
{
7011-
portGET_TASK_LOCK();
7012-
portGET_ISR_LOCK();
7013-
}
7014-
7015-
portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID );
7011+
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
70167012

7017-
/* This is not the interrupt safe version of the enter critical
7018-
* function so assert() if it is being called from an interrupt
7019-
* context. Only API functions that end in "FromISR" can be used in an
7020-
* interrupt. Only assert if the critical nesting count is 1 to
7021-
* protect against recursive calls if the assert function also uses a
7022-
* critical section. */
7023-
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 1U )
7013+
if( xSchedulerRunning != pdFALSE )
70247014
{
7025-
portASSERT_IF_IN_ISR();
7015+
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U )
7016+
{
7017+
portGET_TASK_LOCK();
7018+
portGET_ISR_LOCK();
7019+
}
70267020

7027-
if( uxSchedulerSuspended == 0U )
7021+
portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID );
7022+
7023+
/* This is not the interrupt safe version of the enter critical
7024+
* function so assert() if it is being called from an interrupt
7025+
* context. Only API functions that end in "FromISR" can be used in an
7026+
* interrupt. Only assert if the critical nesting count is 1 to
7027+
* protect against recursive calls if the assert function also uses a
7028+
* critical section. */
7029+
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 1U )
70287030
{
7029-
/* The only time there would be a problem is if this is called
7030-
* before a context switch and vTaskExitCritical() is called
7031-
* after pxCurrentTCB changes. Therefore this should not be
7032-
* used within vTaskSwitchContext(). */
7033-
prvCheckForRunStateChange();
7031+
portASSERT_IF_IN_ISR();
7032+
7033+
if( uxSchedulerSuspended == 0U )
7034+
{
7035+
/* The only time there would be a problem is if this is called
7036+
* before a context switch and vTaskExitCritical() is called
7037+
* after pxCurrentTCB changes. Therefore this should not be
7038+
* used within vTaskSwitchContext(). */
7039+
prvCheckForRunStateChange();
7040+
}
70347041
}
70357042
}
7036-
}
7037-
else
7038-
{
7039-
mtCOVERAGE_TEST_MARKER();
7043+
else
7044+
{
7045+
mtCOVERAGE_TEST_MARKER();
7046+
}
70407047
}
70417048

70427049
traceRETURN_vTaskEnterCritical();
@@ -7051,14 +7058,13 @@ static void prvResetNextTaskUnblockTime( void )
70517058
UBaseType_t vTaskEnterCriticalFromISR( void )
70527059
{
70537060
UBaseType_t uxSavedInterruptStatus = 0;
7054-
BaseType_t xCoreID;
7061+
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
70557062

70567063
traceENTER_vTaskEnterCriticalFromISR();
70577064

70587065
if( xSchedulerRunning != pdFALSE )
70597066
{
70607067
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
7061-
xCoreID = ( BaseType_t ) portGET_CORE_ID();
70627068

70637069
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U )
70647070
{

0 commit comments

Comments
 (0)