*/
voidNVIC_Config(void)
{
NVIC_InitTypeDefNVIC_InitStructure;
/*Configureonebitforpreemptionpriority--------------------------------*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
/*EXTI0--------------------------------------------------------------------*/
NVIC_InitStructure.NVIC_IRQChannel=EXTI0_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=9;//指定抢占式优先级别4,可取0-15
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*Configureonebitforpreemptionpriority--------------------------------*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_3);
/*SPI1--------------------------------------------------------------------*/
NVIC_InitStructure.NVIC_IRQChannel=SPI1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
解析:1.按照NVIC_PriorityGroup_4这么分,就分为了16个抢占(优先)级,每个抢占(优先)级下只有1个副优先级:0;
按照NVIC_PriorityGroup_3这么分,就分为了8个抢占(优先)级,每个抢占(优先)级下只有2个副优先级:0-1;
2.(优先级强弱:) EXTI0_IRQChannel 是0级组》 SPI的3级组高优先级组的人,可以打断低阶级的正在做事的人(嵌套),所以当SPI正在工作时,EXTI0可以打断他进入EXTI0中断;
关于“前提条件3”的实例:
前提条件3:同一组优先级别中,不同的抢占级别之间,其中一抢占级别正在做事,另外抢占级别不能打断他;(即”同一组优先级下的中断源间,没有中断嵌套“)
/*
***************************************************************************************************
**
**NVIC_Config()
**
**
**功能描述:中断向量配置。
**
**参数:无
**
**返回值:无
**
***************************************************************************************************
*/
voidNVIC_Config(void)
{
NVIC_InitTypeDefNVIC_InitStructure;
/*Configureonebitforpreemptionpriority--------------------------------*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
/*UART1--------------------------------------------------------------------*/
NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
/*UART2--------------------------------------------------------------------*/