STM32之HAL例程-CMSIS_OS系统封装文件分析

1、数据类型重定义和宏定义预览 

/* 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;

typedef void * TaskHandle_t;

typedef uint32_t TickType_t;

typedef void (*TaskFunction_t)( void * ); // 一种函数类型的申明,返回类型为void,形式参数为    
                                              void类型的指针

// 用于含MPU单元的宏定义
#define PRIVILEGED_FUNCTION
#define PRIVILEGED_DATA
#define portUSING_MPU_WRAPPERS 0

2、优先级

#define configPRIO_BITS                        4        /* 15 priority levels for stm32 */

#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY  5
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY     0xf

#define configMAX_SYSCALL_INTERRUPT_PRIORITY  ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

#define configKERNEL_INTERRUPT_PRIORITY     ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )

为什么要左移呢?STM32使用高4位作为其优先级设置位。

3、临界区和开关中断

// 关中断
#define taskDISABLE_INTERRUPTS()	    portDISABLE_INTERRUPTS()
#define portDISABLE_INTERRUPTS()				ulPortSetInterruptMask()
// 高于configMAX_SYSCALL_INTERRUPT_PRIORITY数值的中断被屏蔽
__asm uint32_t ulPortSetInterruptMask( void )
{
	PRESERVE8

	mrs r0, basepri
	mov r1, #configMAX_SYSCALL_INTERRUPT_PRIORITY
	msr basepri, r1
	bx r14
}


#define taskENABLE_INTERRUPTS()		    portENABLE_INTERRUPTS()
#define portENABLE_INTERRUPTS()					vPortClearInterruptMask( 0 )
// 清零开中断
__asm void vPortClearInterruptMask( uint32_t ulNewMask )
{
	PRESERVE8

	msr basepri, r0
	bx r14
}


#define taskYIELD()					    portYIELD()

#define taskENTER_CRITICAL()		    portENTER_CRITICAL()
#define portENTER_CRITICAL()					vPortEnterCritical()
void vPortEnterCritical( void )
{
	portDISABLE_INTERRUPTS();
	uxCriticalNesting++;
	__dsb( portSY_FULL_READ_WRITE );
	__isb( portSY_FULL_READ_WRITE );

	/* This is not the interrupt safe version of the enter critical function so
	assert() if it is being called from an interrupt context.  Only API
	functions that end in "FromISR" can be used in an interrupt.  Only assert if
	the critical nesting count is 1 to protect against recursive calls if the
	assert function also uses a critical section. */
	if( uxCriticalNesting == 1 )
	{
		configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 );
	}
}

#define taskENTER_CRITICAL_FROM_ISR()   portSET_INTERRUPT_MASK_FROM_ISR()
#define portSET_INTERRUPT_MASK_FROM_ISR()		ulPortSetInterruptMask()


#define taskEXIT_CRITICAL()			    portEXIT_CRITICAL()
#define portEXIT_CRITICAL()						vPortExitCritical()
void vPortExitCritical( void )
{
	configASSERT( uxCriticalNesting );
	uxCriticalNesting--;
	if( uxCriticalNesting == 0 )
	{
		portENABLE_INTERRUPTS();
	}
}


#define taskEXIT_CRITICAL_FROM_ISR( x ) portCLEAR_INTERRUPT_MASK_FROM_ISR( x )
#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x)	vPortClearInterruptMask(x)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值