Skip to content

Commit e0f9e6c

Browse files
authored
Merge branch 'main' into fix/idle_task_name_len
2 parents 926b8d7 + 31dd1e3 commit e0f9e6c

File tree

2 files changed

+85
-65
lines changed

2 files changed

+85
-65
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: 81 additions & 61 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() ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting )
321-
#define portSET_CRITICAL_NESTING_COUNT( x ) ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting = ( x ) )
322-
#define portINCREMENT_CRITICAL_NESTING_COUNT() ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxCriticalNesting++ )
323-
#define portDECREMENT_CRITICAL_NESTING_COUNT() ( pxCurrentTCBs[ portGET_CORE_ID() ]->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 )
@@ -807,13 +807,14 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
807807
{
808808
UBaseType_t uxPrevCriticalNesting;
809809
const TCB_t * pxThisTCB;
810+
BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
810811

811812
/* This must only be called from within a task. */
812813
portASSERT_IF_IN_ISR();
813814

814815
/* This function is always called with interrupts disabled
815816
* so this is safe. */
816-
pxThisTCB = pxCurrentTCBs[ portGET_CORE_ID() ];
817+
pxThisTCB = pxCurrentTCBs[ xCoreID ];
817818

818819
while( pxThisTCB->xTaskRunState == taskTASK_SCHEDULED_TO_YIELD )
819820
{
@@ -825,11 +826,11 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
825826
* the suspension and critical nesting counts, as well as release
826827
* and reacquire the correct locks. And then, do it all over again
827828
* if our state changed again during the reacquisition. */
828-
uxPrevCriticalNesting = portGET_CRITICAL_NESTING_COUNT();
829+
uxPrevCriticalNesting = portGET_CRITICAL_NESTING_COUNT( xCoreID );
829830

830831
if( uxPrevCriticalNesting > 0U )
831832
{
832-
portSET_CRITICAL_NESTING_COUNT( 0U );
833+
portSET_CRITICAL_NESTING_COUNT( xCoreID, 0U );
833834
portRELEASE_ISR_LOCK();
834835
}
835836
else
@@ -854,8 +855,9 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
854855
portDISABLE_INTERRUPTS();
855856
portGET_TASK_LOCK();
856857
portGET_ISR_LOCK();
858+
xCoreID = ( BaseType_t ) portGET_CORE_ID();
857859

858-
portSET_CRITICAL_NESTING_COUNT( uxPrevCriticalNesting );
860+
portSET_CRITICAL_NESTING_COUNT( xCoreID, uxPrevCriticalNesting );
859861

860862
if( uxPrevCriticalNesting == 0U )
861863
{
@@ -874,13 +876,14 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
874876
BaseType_t xCurrentCoreTaskPriority;
875877
BaseType_t xLowestPriorityCore = ( BaseType_t ) -1;
876878
BaseType_t xCoreID;
879+
const BaseType_t xCurrentCoreID = portGET_CORE_ID();
877880

878881
#if ( configRUN_MULTIPLE_PRIORITIES == 0 )
879882
BaseType_t xYieldCount = 0;
880883
#endif /* #if ( configRUN_MULTIPLE_PRIORITIES == 0 ) */
881884

882885
/* This must be called from a critical section. */
883-
configASSERT( portGET_CRITICAL_NESTING_COUNT() > 0U );
886+
configASSERT( portGET_CRITICAL_NESTING_COUNT( xCurrentCoreID ) > 0U );
884887

885888
#if ( configRUN_MULTIPLE_PRIORITIES == 0 )
886889

@@ -969,11 +972,11 @@ static void prvAddNewTaskToReadyList( TCB_t * pxNewTCB ) PRIVILEGED_FUNCTION;
969972

970973
#if ( configRUN_MULTIPLE_PRIORITIES == 0 )
971974
/* Verify that the calling core always yields to higher priority tasks. */
972-
if( ( ( pxCurrentTCBs[ portGET_CORE_ID() ]->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) == 0U ) &&
973-
( pxTCB->uxPriority > pxCurrentTCBs[ portGET_CORE_ID() ]->uxPriority ) )
975+
if( ( ( pxCurrentTCBs[ xCurrentCoreID ]->uxTaskAttributes & taskATTRIBUTE_IS_IDLE ) == 0U ) &&
976+
( pxTCB->uxPriority > pxCurrentTCBs[ xCurrentCoreID ]->uxPriority ) )
974977
{
975-
configASSERT( ( xYieldPendings[ portGET_CORE_ID() ] == pdTRUE ) ||
976-
( taskTASK_IS_RUNNING( pxCurrentTCBs[ portGET_CORE_ID() ] ) == pdFALSE ) );
978+
configASSERT( ( xYieldPendings[ xCurrentCoreID ] == pdTRUE ) ||
979+
( taskTASK_IS_RUNNING( pxCurrentTCBs[ xCurrentCoreID ] ) == pdFALSE ) );
977980
}
978981
#endif
979982
}
@@ -3865,7 +3868,7 @@ void vTaskSuspendAll( void )
38653868
ulState = portSET_INTERRUPT_MASK();
38663869

38673870
/* This must never be called from inside a critical section. */
3868-
configASSERT( portGET_CRITICAL_NESTING_COUNT() == 0 );
3871+
configASSERT( portGET_CRITICAL_NESTING_COUNT( portGET_CORE_ID() ) == 0 );
38693872

38703873
/* portSOFTWARE_BARRIER() is only implemented for emulated/simulated ports that
38713874
* do not otherwise exhibit real time behaviour. */
@@ -3988,8 +3991,7 @@ BaseType_t xTaskResumeAll( void )
39883991
* tasks from this list into their appropriate ready list. */
39893992
taskENTER_CRITICAL();
39903993
{
3991-
BaseType_t xCoreID;
3992-
xCoreID = ( BaseType_t ) portGET_CORE_ID();
3994+
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
39933995

39943996
/* If uxSchedulerSuspended is zero then this function does not match a
39953997
* previous call to vTaskSuspendAll(). */
@@ -5172,7 +5174,7 @@ BaseType_t xTaskIncrementTick( void )
51725174
/* vTaskSwitchContext() must never be called from within a critical section.
51735175
* This is not necessarily true for single core FreeRTOS, but it is for this
51745176
* SMP port. */
5175-
configASSERT( portGET_CRITICAL_NESTING_COUNT() == 0 );
5177+
configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0 );
51765178

51775179
if( uxSchedulerSuspended != ( UBaseType_t ) 0U )
51785180
{
@@ -6922,16 +6924,24 @@ static void prvResetNextTaskUnblockTime( void )
69226924
*/
69236925
void vTaskYieldWithinAPI( void )
69246926
{
6927+
UBaseType_t ulState;
6928+
69256929
traceENTER_vTaskYieldWithinAPI();
69266930

6927-
if( portGET_CRITICAL_NESTING_COUNT() == 0U )
6928-
{
6929-
portYIELD();
6930-
}
6931-
else
6931+
ulState = portSET_INTERRUPT_MASK();
69326932
{
6933-
xYieldPendings[ portGET_CORE_ID() ] = pdTRUE;
6933+
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
6934+
6935+
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U )
6936+
{
6937+
portYIELD();
6938+
}
6939+
else
6940+
{
6941+
xYieldPendings[ xCoreID ] = pdTRUE;
6942+
}
69346943
}
6944+
portCLEAR_INTERRUPT_MASK( ulState );
69356945

69366946
traceRETURN_vTaskYieldWithinAPI();
69376947
}
@@ -6980,40 +6990,43 @@ static void prvResetNextTaskUnblockTime( void )
69806990
traceENTER_vTaskEnterCritical();
69816991

69826992
portDISABLE_INTERRUPTS();
6983-
6984-
if( xSchedulerRunning != pdFALSE )
69856993
{
6986-
if( portGET_CRITICAL_NESTING_COUNT() == 0U )
6987-
{
6988-
portGET_TASK_LOCK();
6989-
portGET_ISR_LOCK();
6990-
}
6991-
6992-
portINCREMENT_CRITICAL_NESTING_COUNT();
6994+
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
69936995

6994-
/* This is not the interrupt safe version of the enter critical
6995-
* function so assert() if it is being called from an interrupt
6996-
* context. Only API functions that end in "FromISR" can be used in an
6997-
* interrupt. Only assert if the critical nesting count is 1 to
6998-
* protect against recursive calls if the assert function also uses a
6999-
* critical section. */
7000-
if( portGET_CRITICAL_NESTING_COUNT() == 1U )
6996+
if( xSchedulerRunning != pdFALSE )
70016997
{
7002-
portASSERT_IF_IN_ISR();
6998+
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U )
6999+
{
7000+
portGET_TASK_LOCK();
7001+
portGET_ISR_LOCK();
7002+
}
70037003

7004-
if( uxSchedulerSuspended == 0U )
7004+
portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID );
7005+
7006+
/* This is not the interrupt safe version of the enter critical
7007+
* function so assert() if it is being called from an interrupt
7008+
* context. Only API functions that end in "FromISR" can be used in an
7009+
* interrupt. Only assert if the critical nesting count is 1 to
7010+
* protect against recursive calls if the assert function also uses a
7011+
* critical section. */
7012+
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 1U )
70057013
{
7006-
/* The only time there would be a problem is if this is called
7007-
* before a context switch and vTaskExitCritical() is called
7008-
* after pxCurrentTCB changes. Therefore this should not be
7009-
* used within vTaskSwitchContext(). */
7010-
prvCheckForRunStateChange();
7014+
portASSERT_IF_IN_ISR();
7015+
7016+
if( uxSchedulerSuspended == 0U )
7017+
{
7018+
/* The only time there would be a problem is if this is called
7019+
* before a context switch and vTaskExitCritical() is called
7020+
* after pxCurrentTCB changes. Therefore this should not be
7021+
* used within vTaskSwitchContext(). */
7022+
prvCheckForRunStateChange();
7023+
}
70117024
}
70127025
}
7013-
}
7014-
else
7015-
{
7016-
mtCOVERAGE_TEST_MARKER();
7026+
else
7027+
{
7028+
mtCOVERAGE_TEST_MARKER();
7029+
}
70177030
}
70187031

70197032
traceRETURN_vTaskEnterCritical();
@@ -7028,19 +7041,20 @@ static void prvResetNextTaskUnblockTime( void )
70287041
UBaseType_t vTaskEnterCriticalFromISR( void )
70297042
{
70307043
UBaseType_t uxSavedInterruptStatus = 0;
7044+
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
70317045

70327046
traceENTER_vTaskEnterCriticalFromISR();
70337047

70347048
if( xSchedulerRunning != pdFALSE )
70357049
{
70367050
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
70377051

7038-
if( portGET_CRITICAL_NESTING_COUNT() == 0U )
7052+
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U )
70397053
{
70407054
portGET_ISR_LOCK();
70417055
}
70427056

7043-
portINCREMENT_CRITICAL_NESTING_COUNT();
7057+
portINCREMENT_CRITICAL_NESTING_COUNT( xCoreID );
70447058
}
70457059
else
70467060
{
@@ -7104,28 +7118,30 @@ static void prvResetNextTaskUnblockTime( void )
71047118

71057119
void vTaskExitCritical( void )
71067120
{
7121+
const BaseType_t xCoreID = ( BaseType_t ) portGET_CORE_ID();
7122+
71077123
traceENTER_vTaskExitCritical();
71087124

71097125
if( xSchedulerRunning != pdFALSE )
71107126
{
71117127
/* If critical nesting count is zero then this function
71127128
* does not match a previous call to vTaskEnterCritical(). */
7113-
configASSERT( portGET_CRITICAL_NESTING_COUNT() > 0U );
7129+
configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U );
71147130

71157131
/* This function should not be called in ISR. Use vTaskExitCriticalFromISR
71167132
* to exit critical section from ISR. */
71177133
portASSERT_IF_IN_ISR();
71187134

7119-
if( portGET_CRITICAL_NESTING_COUNT() > 0U )
7135+
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U )
71207136
{
7121-
portDECREMENT_CRITICAL_NESTING_COUNT();
7137+
portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID );
71227138

7123-
if( portGET_CRITICAL_NESTING_COUNT() == 0U )
7139+
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U )
71247140
{
71257141
BaseType_t xYieldCurrentTask;
71267142

71277143
/* Get the xYieldPending stats inside the critical section. */
7128-
xYieldCurrentTask = xYieldPendings[ portGET_CORE_ID() ];
7144+
xYieldCurrentTask = xYieldPendings[ xCoreID ];
71297145

71307146
portRELEASE_ISR_LOCK();
71317147
portRELEASE_TASK_LOCK();
@@ -7165,19 +7181,23 @@ static void prvResetNextTaskUnblockTime( void )
71657181

71667182
void vTaskExitCriticalFromISR( UBaseType_t uxSavedInterruptStatus )
71677183
{
7184+
BaseType_t xCoreID;
7185+
71687186
traceENTER_vTaskExitCriticalFromISR( uxSavedInterruptStatus );
71697187

71707188
if( xSchedulerRunning != pdFALSE )
71717189
{
7190+
xCoreID = ( BaseType_t ) portGET_CORE_ID();
7191+
71727192
/* If critical nesting count is zero then this function
71737193
* does not match a previous call to vTaskEnterCritical(). */
7174-
configASSERT( portGET_CRITICAL_NESTING_COUNT() > 0U );
7194+
configASSERT( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U );
71757195

7176-
if( portGET_CRITICAL_NESTING_COUNT() > 0U )
7196+
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) > 0U )
71777197
{
7178-
portDECREMENT_CRITICAL_NESTING_COUNT();
7198+
portDECREMENT_CRITICAL_NESTING_COUNT( xCoreID );
71797199

7180-
if( portGET_CRITICAL_NESTING_COUNT() == 0U )
7200+
if( portGET_CRITICAL_NESTING_COUNT( xCoreID ) == 0U )
71817201
{
71827202
portRELEASE_ISR_LOCK();
71837203
portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );

0 commit comments

Comments
 (0)