tobudos-kernel/arch/arm/pico-RP2040/gcc/picoPortMacro.h

80 lines
2.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _PICOPORTMACRO_
#define _PICOPORTMACRO_
#include "hardware/sync.h"
#include "hardware/exception.h"//用于修改中断处理函数的头文件
#include "pico/multicore.h"
#include "hardware/clocks.h"
#include "hardware/exception.h"
#include "hardware/irq.h"
#include "pico.h"
#include <assert.h>
#include <stdio.h>
#ifndef configSMP_SPINLOCK_0
#define configSMP_SPINLOCK_0 PICO_SPINLOCK_ID_OS1
#endif
#ifndef configSMP_SPINLOCK_1
#define configSMP_SPINLOCK_1 PICO_SPINLOCK_ID_OS2
#endif
/* Define to trap errors during development. */
#define configASSERT(x) assert(x)
#define INVALID_PRIMARY_CORE_NUM 0xffu
#define portMIN_INTERRUPT_PRIORITY ( 255UL )
typedef uint32_t BaseType_t;
#if(USE_SMP==1u)
/* Multi-core */
#define portMAX_CORE_COUNT 2
//获取core ID
#define port_GET_CORE_ID() get_core_num()
#define portRTOS_SPINLOCK_COUNT 2
extern uint8_t ucOwnedByCore[ portMAX_CORE_COUNT ];
extern uint8_t ucRecursionCountByLock[ portRTOS_SPINLOCK_COUNT ];
static void vPortRecursiveLock(uint32_t ulLockNum, spin_lock_t *pxSpinLock, BaseType_t uxAcquire) {
configASSERT(ulLockNum >= 0 && ulLockNum < portRTOS_SPINLOCK_COUNT );
uint32_t ulCoreNum = get_core_num();
uint32_t ulLockBit = 1u << ulLockNum;
configASSERT(ulLockBit < 256u );
if( uxAcquire )
{
//printf("Acquire spinlock core !%d \r\n", ulCoreNum);
if( __builtin_expect( !*pxSpinLock, 0 ) )
{
if( ucOwnedByCore[ulCoreNum] & ulLockBit )
{
configASSERT(ucRecursionCountByLock[ulLockNum] != 255u );
ucRecursionCountByLock[ulLockNum]++;
return;
}
while ( __builtin_expect( !*pxSpinLock, 0 ) );
}
__mem_fence_acquire();
configASSERT(ucRecursionCountByLock[ulLockNum] == 0 );
ucRecursionCountByLock[ulLockNum] = 1;
ucOwnedByCore[ulCoreNum] |= ulLockBit;
} else {
//printf("Release spinlock core !%d \r\n", ulCoreNum);
configASSERT((ucOwnedByCore[ulCoreNum] & ulLockBit) != 0 );
configASSERT(ucRecursionCountByLock[ulLockNum] != 0 );
if( !--ucRecursionCountByLock[ulLockNum] )
{
ucOwnedByCore[ulCoreNum] &= ~ulLockBit;
__mem_fence_release();
*pxSpinLock = 1;
}
}
}
#define portGET_ISR_LOCK() vPortRecursiveLock(0, spin_lock_instance(configSMP_SPINLOCK_0), (BaseType_t)1)
#define portRELEASE_ISR_LOCK() vPortRecursiveLock(0, spin_lock_instance(configSMP_SPINLOCK_0), (BaseType_t)0)
#define portGET_TASK_LOCK() vPortRecursiveLock(1, spin_lock_instance(configSMP_SPINLOCK_1), (BaseType_t)1)
#define portRELEASE_TASK_LOCK() vPortRecursiveLock(1, spin_lock_instance(configSMP_SPINLOCK_1), (BaseType_t) 0)
#endif
#endif