微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > stm32 嵌套向量中断控制器NVIC

stm32 嵌套向量中断控制器NVIC

时间:11-13 来源:互联网 点击:
嵌套向量中断控制器(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));

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top