Skip to content

Commit 73f6e3a

Browse files
kilograhamgraham sanderson
and
graham sanderson
authored
RP2040 Updates: (#1193)
* Standardize on configNUMBER_OF_CORES != 1 to select SMP functionality * Fix SDK pico_sync interoperability (configSUPPORT_PICO_SYNC_INTEROP == 1) Co-authored-by: graham sanderson <graham.sanderson@raspeberryi.com>
1 parent f239da0 commit 73f6e3a

File tree

2 files changed

+99
-110
lines changed

2 files changed

+99
-110
lines changed

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

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,12 @@ extern void vPortYield( void );
151151

152152
void vYieldCore( int xCoreID );
153153
#define portYIELD_CORE( a ) vYieldCore( a )
154-
#define portRESTORE_INTERRUPTS( ulState ) __asm volatile ( "msr PRIMASK,%0" ::"r" ( ulState ) : )
155154

156155
/*-----------------------------------------------------------*/
157156

158157
/* Critical nesting count management. */
158+
#define portCRITICAL_NESTING_IN_TCB 0
159+
159160
extern UBaseType_t uxCriticalNestings[ configNUMBER_OF_CORES ];
160161
#define portGET_CRITICAL_NESTING_COUNT() ( uxCriticalNestings[ portGET_CORE_ID() ] )
161162
#define portSET_CRITICAL_NESTING_COUNT( x ) ( uxCriticalNestings[ portGET_CORE_ID() ] = ( x ) )
@@ -181,9 +182,7 @@ extern void vClearInterruptMaskFromISR( uint32_t ulMask ) __attribute__( ( nake
181182
#define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vClearInterruptMaskFromISR( x )
182183

183184
#define portDISABLE_INTERRUPTS() __asm volatile ( " cpsid i " ::: "memory" )
184-
185-
extern void vPortEnableInterrupts();
186-
#define portENABLE_INTERRUPTS() vPortEnableInterrupts()
185+
#define portENABLE_INTERRUPTS() __asm volatile ( " cpsie i " ::: "memory" )
187186

188187
#if ( configNUMBER_OF_CORES == 1 )
189188
extern void vPortEnterCritical( void );
@@ -203,52 +202,49 @@ extern void vPortEnableInterrupts();
203202

204203
#define portRTOS_SPINLOCK_COUNT 2
205204

205+
#if PICO_SDK_VERSION_MAJOR < 2
206+
__force_inline static bool spin_try_lock_unsafe(spin_lock_t *lock) {
207+
return *lock;
208+
}
209+
#endif
210+
206211
/* Note this is a single method with uxAcquire parameter since we have
207212
* static vars, the method is always called with a compile time constant for
208213
* uxAcquire, and the compiler should dothe right thing! */
209214
static inline void vPortRecursiveLock( uint32_t ulLockNum,
210215
spin_lock_t * pxSpinLock,
211216
BaseType_t uxAcquire )
212217
{
213-
static uint8_t ucOwnedByCore[ portMAX_CORE_COUNT ];
214-
static uint8_t ucRecursionCountByLock[ portRTOS_SPINLOCK_COUNT ];
218+
static volatile uint8_t ucOwnedByCore[ portMAX_CORE_COUNT ][portRTOS_SPINLOCK_COUNT];
219+
static volatile uint8_t ucRecursionCountByLock[ portRTOS_SPINLOCK_COUNT ];
215220

216221
configASSERT( ulLockNum < portRTOS_SPINLOCK_COUNT );
217222
uint32_t ulCoreNum = get_core_num();
218-
uint32_t ulLockBit = 1u << ulLockNum;
219-
configASSERT( ulLockBit < 256u );
220223

221224
if( uxAcquire )
222225
{
223-
if( __builtin_expect( !*pxSpinLock, 0 ) )
224-
{
225-
if( ucOwnedByCore[ ulCoreNum ] & ulLockBit )
226+
if (!spin_try_lock_unsafe(pxSpinLock)) {
227+
if( ucOwnedByCore[ ulCoreNum ][ ulLockNum ] )
226228
{
227229
configASSERT( ucRecursionCountByLock[ ulLockNum ] != 255u );
228230
ucRecursionCountByLock[ ulLockNum ]++;
229231
return;
230232
}
231-
232-
while( __builtin_expect( !*pxSpinLock, 0 ) )
233-
{
234-
}
233+
spin_lock_unsafe_blocking(pxSpinLock);
235234
}
236-
237-
__mem_fence_acquire();
238235
configASSERT( ucRecursionCountByLock[ ulLockNum ] == 0 );
239236
ucRecursionCountByLock[ ulLockNum ] = 1;
240-
ucOwnedByCore[ ulCoreNum ] |= ulLockBit;
237+
ucOwnedByCore[ ulCoreNum ][ ulLockNum ] = 1;
241238
}
242239
else
243240
{
244-
configASSERT( ( ucOwnedByCore[ ulCoreNum ] & ulLockBit ) != 0 );
241+
configASSERT( ( ucOwnedByCore[ ulCoreNum ] [ulLockNum ] ) != 0 );
245242
configASSERT( ucRecursionCountByLock[ ulLockNum ] != 0 );
246243

247244
if( !--ucRecursionCountByLock[ ulLockNum ] )
248245
{
249-
ucOwnedByCore[ ulCoreNum ] &= ~ulLockBit;
250-
__mem_fence_release();
251-
*pxSpinLock = 1;
246+
ucOwnedByCore[ ulCoreNum ] [ ulLockNum ] = 0;
247+
spin_unlock_unsafe(pxSpinLock);
252248
}
253249
}
254250
}

0 commit comments

Comments
 (0)