protmaro.h代码解析
类型重定义
/* Type definitions. */
#define portCHAR char
#define portFLOAT float
#define portDOUBLE double
#define portLONG long
#define portSHORT short
#define portSTACK_TYPE uint32_t
#define portBASE_TYPE long
typedef portSTACK_TYPE StackType_t;
typedef long BaseType_t;
typedef unsigned long UBaseType_t;
#if( configUSE_16_BIT_TICKS == 1 )
typedef uint16_t TickType_t;
#define portMAX_DELAY ( TickType_t ) 0xffff
#else
typedef uint32_t TickType_t;
#define portMAX_DELAY ( TickType_t ) 0xffffffffUL
/* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
not need to be guarded with a critical section. */
#define portTICK_TYPE_IS_ATOMIC 1
#endif
如果定义 configUSE_16_BIT_TICKS 为 1 则表示TickType_t配置最大计数值为16 bit。 portTICK_TYPE_IS_ATOMIC 为1 表示32位数操作是否为原子操作。否则需要进入临界区才能对32位数进行操作。
构架指定
/* Architecture specifics. */
#define portSTACK_GROWTH ( -1 ) //定义堆栈生长的方向
#define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) //调度时间片的大小
#define portBYTE_ALIGNMENT 8 //内存对齐方式,不知道为什么是8byte 猜测与AAPCS 要求堆栈必须8字节对齐 有关
/* Constants used with memory barrier intrinsics. */
#define portSY_FULL_READ_WRITE ( 15 ) //与内存隔离指令一起使用的条件参数
其中隔离指令的参数为指令的option,为确保完成所有操作必须将值设置为0xF
定义临界区相关的函数
/*-----------------------------------------------------------*/
//设置屏蔽中断有消极
static portFORCE_INLINE void vPortSetBASEPRI( uint32_t ulBASEPRI )
{
__asm
{
/* Barrier instructions are not used as this function is only used to
lower the BASEPRI value. */
msr basepri, ulBASEPRI
}
}
/*-----------------------------------------------------------*/
//设置关闭屏蔽优先级为0及大于0的中断
static portFORCE_INLINE void vPortRaiseBASEPRI( void )
{
uint32_t ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY;
__asm
{
/* Set BASEPRI to the max syscall priority to effect a critical
section. */
msr basepri, ulNewBASEPRI
dsb
isb
}
}
/*-----------------------------------------------------------*/
//开启所有的中断
static portFORCE_INLINE void vPortClearBASEPRIFromISR( void )
{
__asm
{
/* Set BASEPRI to 0 so no interrupts are masked. This function is only
used to lower the mask in an interrupt, so memory barriers are not
used. */
msr basepri, #0
}
}
/*-----------------------------------------------------------*/
//设置关闭屏蔽优先级为0及大于0的中断,并返回更改之前的中断优先级
static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI( void )
{
uint32_t ulReturn, ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY;
__asm
{
/* Set BASEPRI to the max syscall priority to effect a critical
section. */
mrs ulReturn, basepri
msr basepri, ulNewBASEPRI
dsb
isb
}
return ulReturn;
}
/*-----------------------------------------------------------*/
//检查当前是否在中断状态,通过ipsr获取中断异常号来实现
static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt( void )
{
uint32_t ulCurrentInterrupt;
BaseType_t xReturn;
/* Obtain the number of the currently executing interrupt. */
__asm
{
mrs ulCurrentInterrupt, ipsr
}
if( ulCurrentInterrupt == 0 )
{
xReturn = pdFALSE;
}
else
{
xReturn = pdTRUE;
}
return xReturn;
}