volatile uint8_t * const pucFirstUserPriorityRegister = ( uint8_t * ) ( portNVIC_IP_REGISTERS_OFFSET_16 + portFIRST_USER_INTERRUPT_NUMBER );
通过宏pucFirstUserPriorityRegister=0xE000E400(根据宏名字,这是NVIC寄存器地址)
中断优先级设置寄存器的第一个寄存器。
ulOriginalPriority = *pucFirstUserPriorityRegister;保存第一个寄存器的值
获取寄存器有效位。
ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY & ucMaxPriorityValue;
#define configMAX_SYSCALL_INTERRUPT_PRIORITY \
( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
configMAX_SYSCALL_INTERRUPT_PRIORITY=(5<<(8-4))
ulMaxPRIGROUPValue = portMAX_PRIGROUP_BITS;//为7
while( ( ucMaxPriorityValue & portTOP_BIT_OF_BYTE ) == portTOP_BIT_OF_BYTE )
{//portTOP_BIT_OF_BYTE=0x80
/*有几个有效位,就执行几次*/
ulMaxPRIGROUPValue--;//最后的值为7-4
ucMaxPriorityValue <<= ( uint8_t ) 0x01;
}
/* Shift the priority group value back to its position within the AIRCR
register. *///注释表明,将得到的值填入AIRCR寄存器,来确定如何分组。
ulMaxPRIGROUPValue <<= portPRIGROUP_SHIFT;//3左移8位
ulMaxPRIGROUPValue &= portPRIORITY_GROUP_MASK;//仅保留3左移8位后的位为1
这里3左移8位,然后填入PRIGROUP;
/* Make PendSV and SysTick the lowest priority interrupts. */因为用4位表示优先级,所以这里是15。
portNVIC_SYSPRI2_REG |= portNVIC_PENDSV_PRI;
portNVIC_SYSPRI2_REG |= portNVIC_SYSTICK_PRI;
void vPortSetupTimerInterrupt( void )
{
/* Configure SysTick to interrupt at the requested rate. *///产生指定周期的中断
portNVIC_SYSTICK_LOAD_REG =
( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;
portNVIC_SYSTICK_CTRL_REG =
( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );
}
__asm void prvStartFirstTask( void )
{
PRESERVE8
/* Use the NVIC offset register to locate the stack. */
ldr r0, =0xE000ED08
ldr r0, [r0]
ldr r0, [r0]
/* Set the msp back to the start of the stack. */
msr msp, r0
/* Globally enable interrupts. */
cpsie i
cpsie f
dsb
isb
/* Call SVC to start the first task. */
svc 0
nop
nop
}