stm32 中断

本文介绍了STM32中断系统的内部结构,包括ISER、ICER、ISPR、ICPR、IABR和IP寄存器的功能。重点讨论了中断使能、中断优先级设置,并解析了SCB->AIRCR在确定抢占和响应优先级中的作用。
摘要由CSDN通过智能技术生成

void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
{
  
 uint32_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; 
tmppre = (0x4 - tmppriority);
 tmpsub = tmpsub >> tmppriority;
 tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre; 
tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub; 
tmppriority = tmppriority << 0x04; 
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); 
}}

首先这是官方固件库的源码

我们就从这段代码解析:

首先我们看这个结构体

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值