初级会员

- 积分
- 132
- 金钱
- 132
- 注册时间
- 2017-12-25
- 在线时间
- 27 小时
|

楼主 |
发表于 2017-12-29 05:34:56
|
显示全部楼层
嵌套向量中断控制初始化,解读。
void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
{
uint8_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)//判断是否使能
{
/* Compute计算 the Corresponding相应的 IRQ中断清求 Priority优先级 --------------------------------*/
tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
//air=0x500&0x700=0x500 0x700-0x500>>8 =0x2
//这里是算出抢占优先级,所占的位数
tmppre = (0x4 - tmppriority);//0x4-0x2=2
//这里是算出抢占优先级后面要左移的次数
tmpsub = tmpsub >> tmppriority;//0x0f>>2=3
//这里是把响应优先级的有效位计算出来
tmppriority = NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;//0x3<<2=0xc
//抢占优先级向前移一定的位,根据(4-所占的位数)
tmppriority |= (uint8_t)(NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub);//0x0c|3=0xf
//响应优先级与前面算出来的有效位做与,然后与抢占优先级进行组合
tmppriority = tmppriority << 0x04;//因为IP是使用的高四位,所以左移4次=oxf0
NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;//这里是最后配置中断优先级
/* Enable使能 the Selected选择的 IRQ中断请求 Channels通道 --------------------------------------*/
NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
(uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
}
else
{
/* Disable不使能 the Selected选择的 IRQ中断请求 Channels通道 -------------------------------------*/
NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
(uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
}
} |
|