GD32如何配置中断优先级分组以及中断优先级

2024-06-07 16:36

本文主要是介绍GD32如何配置中断优先级分组以及中断优先级,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

使用GD32 MCU的过程中,大家可能会有以下疑问:中断优先级如何配置和使用?

本文将会为大家解析中断优先级分组以及中断优先级的配置使用:

  • 中断优先级分组配置

一个GD32 MCU系统需要大家明确系统中使用的中断优先级分组,避免中断优先级配置越界导致一些不符合预期的中断现象。

中断优先级分组可采用以下函数接口,其中有4个bit可用于中断优先级分组,如果全用于抢占优先级,则可以配置0-15的优先级,如果2位用于抢占,2位用于次优先级,则抢占优先级可以配置0-3,此优先级可以配置0-3。

C
/*!\brief      set the priority group\param[in]  nvic_prigroup: the NVIC priority group\arg        NVIC_PRIGROUP_PRE0_SUB4:0 bits for pre-emption priority 4 bits for subpriority\arg        NVIC_PRIGROUP_PRE1_SUB3:1 bits for pre-emption priority 3 bits for subpriority\arg        NVIC_PRIGROUP_PRE2_SUB2:2 bits for pre-emption priority 2 bits for subpriority\arg        NVIC_PRIGROUP_PRE3_SUB1:3 bits for pre-emption priority 1 bits for subpriority\arg        NVIC_PRIGROUP_PRE4_SUB0:4 bits for pre-emption priority 0 bits for subpriority\param[out] none\retval     none
*/
void nvic_priority_group_set(uint32_t nvic_prigroup)
{/* set the priority group value */SCB->AIRCR = NVIC_AIRCR_VECTKEY_MASK | nvic_prigroup;
}

注意:如果中断优先级配置为2位抢占和2位此优先级的话,抢占优先级配置为4(二进制为100b),优先级配置越界,实际配置进去的优先级为0,最高优先级,因而明确中断优先级分组非常重要。

  • 中断优先级配置

中断优先级配置采用以下函数。

C
/*!\brief      enable NVIC request\param[in]  nvic_irq: the NVIC interrupt request, detailed in IRQn_Type\param[in]  nvic_irq_pre_priority: the pre-emption priority needed to set\param[in]  nvic_irq_sub_priority: the subpriority needed to set\param[out] none\retval     none
*/
void nvic_irq_enable(uint8_t nvic_irq, uint8_t nvic_irq_pre_priority, uint8_t nvic_irq_sub_priority)
{uint32_t temp_priority = 0x00U, temp_pre = 0x00U, temp_sub = 0x00U;/* use the priority group value to get the temp_pre and the temp_sub */if(((SCB->AIRCR) & (uint32_t)0x700U)==NVIC_PRIGROUP_PRE0_SUB4){temp_pre=0U;temp_sub=0x4U;}else if(((SCB->AIRCR) & (uint32_t)0x700U)==NVIC_PRIGROUP_PRE1_SUB3){temp_pre=1U;temp_sub=0x3U;}else if(((SCB->AIRCR) & (uint32_t)0x700U)==NVIC_PRIGROUP_PRE2_SUB2){temp_pre=2U;temp_sub=0x2U;}else if(((SCB->AIRCR) & (uint32_t)0x700U)==NVIC_PRIGROUP_PRE3_SUB1){temp_pre=3U;temp_sub=0x1U;}else if(((SCB->AIRCR) & (uint32_t)0x700U)==NVIC_PRIGROUP_PRE4_SUB0){temp_pre=4U;temp_sub=0x0U;}else{nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);temp_pre=2U;temp_sub=0x2U;}/* get the temp_priority to fill the NVIC->IP register */temp_priority = (uint32_t)nvic_irq_pre_priority << (0x4U - temp_pre);temp_priority |= nvic_irq_sub_priority &(0x0FU >> (0x4U - temp_sub));temp_priority = temp_priority << 0x04U;NVIC->IP[nvic_irq] = (uint8_t)temp_priority;/* enable the selected IRQ */NVIC->ISER[nvic_irq >> 0x05U] = (uint32_t)0x01U << (nvic_irq & (uint8_t)0x1FU);
}

 nvic_irq为中断号,中断号可以通过gd32f30x.h获取,如下图所示,nvic_irq_pre_priority为抢占优先级配置,nvic_irq_sub_priority为此优先级配置,注意优先级配置要根据优先级分组进行配置,不要越界哦。

GD32MCU技术交流群:859440462

更多GD32 MCU相关咨询:单片机开发板_国产mcu视频_GD32 - 苏州聚沃电子科技有限公司

这篇关于GD32如何配置中断优先级分组以及中断优先级的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1039710

相关文章

Zookeeper安装和配置说明

一、Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式。 ■ 单机模式:Zookeeper只运行在一台服务器上,适合测试环境; ■ 伪集群模式:就是在一台物理机上运行多个Zookeeper 实例; ■ 集群模式:Zookeeper运行于一个集群上,适合生产环境,这个计算机集群被称为一个“集合体”(ensemble) Zookeeper通过复制来实现

CentOS7安装配置mysql5.7 tar免安装版

一、CentOS7.4系统自带mariadb # 查看系统自带的Mariadb[root@localhost~]# rpm -qa|grep mariadbmariadb-libs-5.5.44-2.el7.centos.x86_64# 卸载系统自带的Mariadb[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7

hadoop开启回收站配置

开启回收站功能,可以将删除的文件在不超时的情况下,恢复原数据,起到防止误删除、备份等作用。 开启回收站功能参数说明 (1)默认值fs.trash.interval = 0,0表示禁用回收站;其他值表示设置文件的存活时间。 (2)默认值fs.trash.checkpoint.interval = 0,检查回收站的间隔时间。如果该值为0,则该值设置和fs.trash.interval的参数值相等。

NameNode内存生产配置

Hadoop2.x 系列,配置 NameNode 内存 NameNode 内存默认 2000m ,如果服务器内存 4G , NameNode 内存可以配置 3g 。在 hadoop-env.sh 文件中配置如下。 HADOOP_NAMENODE_OPTS=-Xmx3072m Hadoop3.x 系列,配置 Nam

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

第10章 中断和动态时钟显示

第10章 中断和动态时钟显示 从本章开始,按照书籍的划分,第10章开始就进入保护模式(Protected Mode)部分了,感觉从这里开始难度突然就增加了。 书中介绍了为什么有中断(Interrupt)的设计,中断的几种方式:外部硬件中断、内部中断和软中断。通过中断做了一个会走的时钟和屏幕上输入字符的程序。 我自己理解中断的一些作用: 为了更好的利用处理器的性能。协同快速和慢速设备一起工作

wolfSSL参数设置或配置项解释

1. wolfCrypt Only 解释:wolfCrypt是一个开源的、轻量级的、可移植的加密库,支持多种加密算法和协议。选择“wolfCrypt Only”意味着系统或应用将仅使用wolfCrypt库进行加密操作,而不依赖其他加密库。 2. DTLS Support 解释:DTLS(Datagram Transport Layer Security)是一种基于UDP的安全协议,提供类似于

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

沁恒CH32在MounRiver Studio上环境配置以及使用详细教程

目录 1.  RISC-V简介 2.  CPU架构现状 3.  MounRiver Studio软件下载 4.  MounRiver Studio软件安装 5.  MounRiver Studio软件介绍 6.  创建工程 7.  编译代码 1.  RISC-V简介         RISC就是精简指令集计算机(Reduced Instruction SetCom

log4j2相关配置说明以及${sys:catalina.home}应用

${sys:catalina.home} 等价于 System.getProperty("catalina.home") 就是Tomcat的根目录:  C:\apache-tomcat-7.0.77 <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" /> 2017-08-10