stm32 嵌套向量中断控制器NVIC
NVIC 相关的函数包含在 misc.c 文件中
void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
其中,void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)的作用已经分析过了。
1. void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
首先应该设置中断优先级组,分了组之后后面才好 分配抢占优先级和抢占优先级 。
来看分组的参数
2.void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
涉及4个参数
uint8_t NVIC_IRQChannel; 中断通道
/*!< Specifies the IRQ channel to be enabled or disabled.
This parameter can be a value of @ref IRQn_Type
(For the complete STM32 Devices IRQ Channels list, please
refer to stm32f10x.h file) */
uint8_t NVIC_IRQChannelPreemptionPriority; 抢占优先级
/*!< Specifies the pre-emption priority for the IRQ channel
specified in NVIC_IRQChannel. This parameter can be a value
between 0 and 15 as described in the table @ref NVIC_Priority_Table */
uint8_t NVIC_IRQChannelSubPriority; 响应优先级
/*!< Specifies the subpriority level for the IRQ channel specified
in NVIC_IRQChannel. This parameter can be a value
between 0 and 15 as described in the table @ref NVIC_Priority_Table */
FunctionalState NVIC_IRQChannelCmd; 使能位
/*!< Specifies whether the IRQ channel defined in NVIC_IRQChannel
will be enabled or disabled.
This parameter can be set either to ENABLE or DISABLE */
通过配置抢占优先级 实现中断的嵌套。
响应优先级只能排队,不能嵌套。
抢占的情况下,优先级高的就先执行,注意数字越小,优先级越高。
排队的情况下,在同样排队等待的情况,数字小的先执行。
平等的情况:NVIC_PriorityGroup_0
NVIC_IRQChannelPreemptionPriority=0;
NVIC_IRQChannelSubPriority=0;
这样的配置就按照中断发生的先后顺序执行。
3 void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
这个是用在IAP上面的,前面已经分析过了。
4 void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
选择进入低功耗状态下的中断控制
5 void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
Configures the SysTick clock source 配置滴答定时器的时钟源
附录:
csdn 上的一篇关于NVIC 的说明http://blog.csdn.net/denghuanhuandeng/article/details/8350392
STM32的NVIC理解(绿色和深绿色分别为其他优秀网友成果,真诚的感谢。现拷贝过来汇总方便大家学习,如若构成侵权请及时联系)
例程: /* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* Enable the WAKEUP_BUTTON_EXTI_IRQn Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = WAKEUP_BUTTON_EXTI_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = PreemptionPriorityValue;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the KEY_BUTTON_EXTI_IRQn Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = KEY_BUTTON_EXTI_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Configure the SysTick Handler Priority: Preemption priority and subpriority */
NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), !PreemptionPriorityValue, 0));
stm32嵌套向量中断控制器NVI 相关文章:
- STM32嵌套向量中断控制器(NVIC)(11-27)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)