Skip to content

Commit

Permalink
Update to merge
Browse files Browse the repository at this point in the history
  • Loading branch information
chinglee-iot committed Nov 4, 2024
1 parent 1521667 commit 5aa1423
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 82 deletions.
2 changes: 1 addition & 1 deletion portable/ThirdParty/GCC/RP2040/include/portmacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ extern void vPortEnableInterrupts();

/*-----------------------------------------------------------*/

#define portUSING_GRANULAR_LOCKS ( 1 )
#define portUSING_GRANULAR_LOCKS ( 0 )

/*-----------------------------------------------------------*/

Expand Down
164 changes: 83 additions & 81 deletions portable/ThirdParty/GCC/RP2040/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -1261,115 +1261,117 @@ void vPortSpinlockRelease( portSPINLOCK_TYPE *pxSpinlock )
}
}

void vPortLockDataGroup( portSPINLOCK_TYPE *pxTaskSpinlock, portSPINLOCK_TYPE *pxISRSpinlock )
{
uint32_t uxTaskSpinlockIndex = portSPINLOCK_NUMBER_TO_INDEX( pxTaskSpinlock->uxSpinlockNumber );
uint32_t uxISRSpinlockIndex = portSPINLOCK_NUMBER_TO_INDEX( pxISRSpinlock->uxSpinlockNumber );
#if portUSING_GRANULAR_LOCKS == 1
void vPortLockDataGroup( portSPINLOCK_TYPE *pxTaskSpinlock, portSPINLOCK_TYPE *pxISRSpinlock )
{
uint32_t uxTaskSpinlockIndex = portSPINLOCK_NUMBER_TO_INDEX( pxTaskSpinlock->uxSpinlockNumber );
uint32_t uxISRSpinlockIndex = portSPINLOCK_NUMBER_TO_INDEX( pxISRSpinlock->uxSpinlockNumber );

portDISABLE_INTERRUPTS();
portDISABLE_INTERRUPTS();

BaseType_t xCoreID = portGET_CORE_ID();
BaseType_t xCoreID = portGET_CORE_ID();

if( uxTaskSpinlockIndex < 2 )
{
vPortRecursiveLock(uxTaskSpinlockIndex, spin_lock_instance(pxTaskSpinlock->uxSpinlockNumber), pdTRUE);
vPortRecursiveLock(uxISRSpinlockIndex, spin_lock_instance(pxISRSpinlock->uxSpinlockNumber), pdTRUE);
uxCriticalNestings[ xCoreID ]++;
uxCriticalNestings[ xCoreID ]++;
}
else
{
/* Task spinlock is optional and is always taken first */
if( pxTaskSpinlock != NULL )
if( uxTaskSpinlockIndex < 2 )
{
vPortSpinlockTake( pxTaskSpinlock );
vPortRecursiveLock(uxTaskSpinlockIndex, spin_lock_instance(pxTaskSpinlock->uxSpinlockNumber), pdTRUE);
vPortRecursiveLock(uxISRSpinlockIndex, spin_lock_instance(pxISRSpinlock->uxSpinlockNumber), pdTRUE);
uxCriticalNestings[ xCoreID ]++;
uxCriticalNestings[ xCoreID ]++;
}
else
{
/* Task spinlock is optional and is always taken first */
if( pxTaskSpinlock != NULL )
{
vPortSpinlockTake( pxTaskSpinlock );
uxCriticalNestings[ xCoreID ]++;
}

/* ISR spinlock must always be provided */
vPortSpinlockTake( pxISRSpinlock );
uxCriticalNestings[ xCoreID ]++;
/* ISR spinlock must always be provided */
vPortSpinlockTake( pxISRSpinlock );
uxCriticalNestings[ xCoreID ]++;
}
}
}

void vPortUnlockDataGroup( portSPINLOCK_TYPE *pxTaskSpinlock, portSPINLOCK_TYPE *pxISRSpinlock )
{
BaseType_t xCoreID = portGET_CORE_ID();
BaseType_t xYieldCurrentTask;

uint32_t uxTaskSpinlockIndex = portSPINLOCK_NUMBER_TO_INDEX( pxTaskSpinlock->uxSpinlockNumber );
uint32_t uxISRSpinlockIndex = portSPINLOCK_NUMBER_TO_INDEX( pxISRSpinlock->uxSpinlockNumber );
void vPortUnlockDataGroup( portSPINLOCK_TYPE *pxTaskSpinlock, portSPINLOCK_TYPE *pxISRSpinlock )
{
BaseType_t xCoreID = portGET_CORE_ID();
BaseType_t xYieldCurrentTask;

configASSERT( uxCriticalNestings[ xCoreID ] > 0U );
uint32_t uxTaskSpinlockIndex = portSPINLOCK_NUMBER_TO_INDEX( pxTaskSpinlock->uxSpinlockNumber );
uint32_t uxISRSpinlockIndex = portSPINLOCK_NUMBER_TO_INDEX( pxISRSpinlock->uxSpinlockNumber );

/* Get the xYieldPending stats inside the critical section. */
xYieldCurrentTask = xTaskUnlockCanYield();
configASSERT( uxCriticalNestings[ xCoreID ] > 0U );

if( uxTaskSpinlockIndex < 2 )
{
vPortRecursiveLock(uxTaskSpinlockIndex, spin_lock_instance(pxTaskSpinlock->uxSpinlockNumber), pdFALSE);
vPortRecursiveLock(uxISRSpinlockIndex, spin_lock_instance(pxISRSpinlock->uxSpinlockNumber), pdFALSE);
uxCriticalNestings[ xCoreID ]--;
uxCriticalNestings[ xCoreID ]--;
}
else
{
/* ISR spinlock must always be provided */
vPortSpinlockRelease( pxISRSpinlock );
uxCriticalNestings[ xCoreID ]--;
/* Get the xYieldPending stats inside the critical section. */
xYieldCurrentTask = xTaskUnlockCanYield();

/* Task spinlock is optional and is always taken first */
if( pxTaskSpinlock != NULL )
if( uxTaskSpinlockIndex < 2 )
{
vPortSpinlockRelease( pxTaskSpinlock);
vPortRecursiveLock(uxTaskSpinlockIndex, spin_lock_instance(pxTaskSpinlock->uxSpinlockNumber), pdFALSE);
vPortRecursiveLock(uxISRSpinlockIndex, spin_lock_instance(pxISRSpinlock->uxSpinlockNumber), pdFALSE);
uxCriticalNestings[ xCoreID ]--;
uxCriticalNestings[ xCoreID ]--;
}
}

assert(uxCriticalNestings[ xCoreID ] >= 0);
else
{
/* ISR spinlock must always be provided */
vPortSpinlockRelease( pxISRSpinlock );
uxCriticalNestings[ xCoreID ]--;

if( uxCriticalNestings[ xCoreID ] == 0 )
{
portENABLE_INTERRUPTS();
/* Task spinlock is optional and is always taken first */
if( pxTaskSpinlock != NULL )
{
vPortSpinlockRelease( pxTaskSpinlock);
uxCriticalNestings[ xCoreID ]--;
}
}

/* When a task yields in a critical section it just sets xYieldPending to
* true. So now that we have exited the critical section check if xYieldPending
* is true, and if so yield. */
assert(uxCriticalNestings[ xCoreID ] >= 0);

if( xYieldCurrentTask != pdFALSE )
{
portYIELD();
}
else
if( uxCriticalNestings[ xCoreID ] == 0 )
{
mtCOVERAGE_TEST_MARKER();
portENABLE_INTERRUPTS();

/* When a task yields in a critical section it just sets xYieldPending to
* true. So now that we have exited the critical section check if xYieldPending
* is true, and if so yield. */

if( xYieldCurrentTask != pdFALSE )
{
portYIELD();
}
else
{
mtCOVERAGE_TEST_MARKER();
}
}
}
}

UBaseType_t uxPortLockDataGroupFromISR( portSPINLOCK_TYPE *pxISRSpinlock )
{
UBaseType_t uxSavedInterruptStatus = 0;
UBaseType_t uxPortLockDataGroupFromISR( portSPINLOCK_TYPE *pxISRSpinlock )
{
UBaseType_t uxSavedInterruptStatus = 0;

uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();
uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();

vPortSpinlockTake( pxISRSpinlock );
uxCriticalNestings[ portGET_CORE_ID() ]++;
vPortSpinlockTake( pxISRSpinlock );
uxCriticalNestings[ portGET_CORE_ID() ]++;

return uxSavedInterruptStatus;
}
return uxSavedInterruptStatus;
}

void vPortUnlockDataGroupFromISR( UBaseType_t uxSavedInterruptStatus, portSPINLOCK_TYPE *pxISRSpinlock )
{
BaseType_t xCoreID = portGET_CORE_ID();
void vPortUnlockDataGroupFromISR( UBaseType_t uxSavedInterruptStatus, portSPINLOCK_TYPE *pxISRSpinlock )
{
BaseType_t xCoreID = portGET_CORE_ID();

vPortSpinlockRelease( pxISRSpinlock );
uxCriticalNestings[ xCoreID ]--;
vPortSpinlockRelease( pxISRSpinlock );
uxCriticalNestings[ xCoreID ]--;

assert(uxCriticalNestings[ xCoreID ] >= 0);
assert(uxCriticalNestings[ xCoreID ] >= 0);

if( uxCriticalNestings[ xCoreID ] == 0 )
{
portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
if( uxCriticalNestings[ xCoreID ] == 0 )
{
portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );
}
}
}
#endif

0 comments on commit 5aa1423

Please sign in to comment.