@@ -151,11 +151,12 @@ extern void vPortYield( void );
151
151
152
152
void vYieldCore ( int xCoreID );
153
153
#define portYIELD_CORE ( a ) vYieldCore( a )
154
- #define portRESTORE_INTERRUPTS ( ulState ) __asm volatile ( "msr PRIMASK,%0" ::"r" ( ulState ) : )
155
154
156
155
/*-----------------------------------------------------------*/
157
156
158
157
/* Critical nesting count management. */
158
+ #define portCRITICAL_NESTING_IN_TCB 0
159
+
159
160
extern UBaseType_t uxCriticalNestings [ configNUMBER_OF_CORES ];
160
161
#define portGET_CRITICAL_NESTING_COUNT () ( uxCriticalNestings[ portGET_CORE_ID() ] )
161
162
#define portSET_CRITICAL_NESTING_COUNT ( x ) ( uxCriticalNestings[ portGET_CORE_ID() ] = ( x ) )
@@ -181,9 +182,7 @@ extern void vClearInterruptMaskFromISR( uint32_t ulMask ) __attribute__( ( nake
181
182
#define portCLEAR_INTERRUPT_MASK_FROM_ISR ( x ) vClearInterruptMaskFromISR( x )
182
183
183
184
#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" )
187
186
188
187
#if ( configNUMBER_OF_CORES == 1 )
189
188
extern void vPortEnterCritical ( void );
@@ -203,52 +202,49 @@ extern void vPortEnableInterrupts();
203
202
204
203
#define portRTOS_SPINLOCK_COUNT 2
205
204
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
+
206
211
/* Note this is a single method with uxAcquire parameter since we have
207
212
* static vars, the method is always called with a compile time constant for
208
213
* uxAcquire, and the compiler should dothe right thing! */
209
214
static inline void vPortRecursiveLock ( uint32_t ulLockNum ,
210
215
spin_lock_t * pxSpinLock ,
211
216
BaseType_t uxAcquire )
212
217
{
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 ];
215
220
216
221
configASSERT ( ulLockNum < portRTOS_SPINLOCK_COUNT );
217
222
uint32_t ulCoreNum = get_core_num ();
218
- uint32_t ulLockBit = 1u << ulLockNum ;
219
- configASSERT ( ulLockBit < 256u );
220
223
221
224
if ( uxAcquire )
222
225
{
223
- if ( __builtin_expect ( !* pxSpinLock , 0 ) )
224
- {
225
- if ( ucOwnedByCore [ ulCoreNum ] & ulLockBit )
226
+ if (!spin_try_lock_unsafe (pxSpinLock )) {
227
+ if ( ucOwnedByCore [ ulCoreNum ][ ulLockNum ] )
226
228
{
227
229
configASSERT ( ucRecursionCountByLock [ ulLockNum ] != 255u );
228
230
ucRecursionCountByLock [ ulLockNum ]++ ;
229
231
return ;
230
232
}
231
-
232
- while ( __builtin_expect ( !* pxSpinLock , 0 ) )
233
- {
234
- }
233
+ spin_lock_unsafe_blocking (pxSpinLock );
235
234
}
236
-
237
- __mem_fence_acquire ();
238
235
configASSERT ( ucRecursionCountByLock [ ulLockNum ] == 0 );
239
236
ucRecursionCountByLock [ ulLockNum ] = 1 ;
240
- ucOwnedByCore [ ulCoreNum ] |= ulLockBit ;
237
+ ucOwnedByCore [ ulCoreNum ][ ulLockNum ] = 1 ;
241
238
}
242
239
else
243
240
{
244
- configASSERT ( ( ucOwnedByCore [ ulCoreNum ] & ulLockBit ) != 0 );
241
+ configASSERT ( ( ucOwnedByCore [ ulCoreNum ] [ ulLockNum ] ) != 0 );
245
242
configASSERT ( ucRecursionCountByLock [ ulLockNum ] != 0 );
246
243
247
244
if ( !-- ucRecursionCountByLock [ ulLockNum ] )
248
245
{
249
- ucOwnedByCore [ ulCoreNum ] &= ~ulLockBit ;
250
- __mem_fence_release ();
251
- * pxSpinLock = 1 ;
246
+ ucOwnedByCore [ ulCoreNum ] [ ulLockNum ] = 0 ;
247
+ spin_unlock_unsafe (pxSpinLock );
252
248
}
253
249
}
254
250
}
0 commit comments