实现三个按键的中断,现象和代码
do_ipr.c
#include "stm32mp1xx_gic.h"
#include "stm32mp1xx_exti.h"
extern void printf(const char *fmt, ...);
unsigned int i = 0;
void do_irq(void)
{//获取要处理的中断的中断号unsigned int irqno=GICC->IAR&0x3ff;switch (irqno){case 99:printf("key1_intc\n");//清除GICD中断排队标志GICD->ICPENDR[3] |= (0X1<<3);//清除EXTI中断触发标志EXTI->FPR1 |= (0X1<<9);break;case 97:printf("key2_intc\n");//清除GICD中断排队标志GICD->ICPENDR[3] |= (0X1<<1);//清除EXTI中断触发标志EXTI->FPR1 |= (0X1<<7);break;case 98:printf("key3_intc\n");//清除GICD中断排队标志GICD->ICPENDR[3] |= (0X1<<2);//清除EXTI中断触发标志EXTI->FPR1 |= (0X1<<8);break;default:break;}//清除IAR寄存器中的中断号GICC->EOIR |= irqno;
}
key_inc.h
#ifndef __KEY_INC_H__
#define __KEY_INC_H__
#include "stm32mp1xx_gic.h"
#include "stm32mp1xx_exti.h"
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_gpio.h"void key1_it_config();void key2_it_config();void key3_it_config();
#endif
key_inc.c
#include"key_inc.h"void key1_it_config(){//使能GPIOF外设时钟RCC->MP_AHB4ENSETR |= (0x1<<5);//将PF9设置为输入模式GPIOF->MODER &= (~(0x3<<18));//设置由PF9管脚产生EXTI9事件EXTI->EXTICR3 &= (~(0XFF<<8));EXTI->EXTICR3|= (0X05<<8);//通过下降沿检测EXTI9事件是否产生EXTI->FTSR1 |= (0x1<<9);//取消EXTI9中断屏蔽EXTI->C1IMR1 |= (0x1<<9);//设置EXTI9中断全局使能GICD->ISENABLER[3] |= (0x1<<3);//设置中断优先级GICD->IPRIORITYR[24] &= (~(0x1f<<27));//设置CPU0处理当前中断GICD->ITARGETSR[24] |= (0x1<<24);//设置组0中断可以被转发到GICC层GICD->CTRL |=0X1;//设置中断优先级掩码GICC->PMR |= (0x1f<<3);//设置组0中断交给指定处理器处理GICC->CTRL |= 0x1;}void key2_it_config(){//使能GPIOF外设时钟RCC->MP_AHB4ENSETR |= (0x1<<5);//将PF7设置为输入模式GPIOF->MODER &= (~(0x3<<14));//设置由PF7管脚产生EXTI7事件EXTI->EXTICR2 &= (~(0XFF<<24));EXTI->EXTICR2|= (0X05<<24);//通过下降沿检测EXTI7事件是否产生EXTI->FTSR1 |= (0x1<<7);//取消EXTI7中断屏蔽EXTI->C1IMR1 |= (0x1<<7);//设置EXTI7中断全局使能GICD->ISENABLER[3] |= (0x1<<1);//设置中断优先级GICD->IPRIORITYR[24] &= (~(0x1f<<11));//设置CPU0处理当前中断GICD->ITARGETSR[24] |= (0x1<<8);//设置组0中断可以被转发到GICC层GICD->CTRL |=0X1;//设置中断优先级掩码GICC->PMR |= (0x1f<<3);//设置组0中断交给指定处理器处理GICC->CTRL |= 0x1;}void key3_it_config(){//使能GPIOF外设时钟RCC->MP_AHB4ENSETR |= (0x1<<5);//将PF8设置为输入模式GPIOF->MODER &= (~(0x3<<16));//设置由PF8管脚产生EXTI8事件EXTI->EXTICR3 &= (~(0XFF));EXTI->EXTICR3|= (0X05);//通过下降沿检测EXTI8事件是否产生EXTI->FTSR1 |= (0x1<<8);//取消EXTI8中断屏蔽EXTI->C1IMR1 |= (0x1<<8);//设置EXTI8中断全局使能GICD->ISENABLER[3] |= (0x1<<2);//设置中断优先级GICD->IPRIORITYR[24] &= (~(0x1f<<19));//设置CPU0处理当前中断GICD->ITARGETSR[24] |= (0x1<<16);//设置组0中断可以被转发到GICC层GICD->CTRL |=0X1;//设置中断优先级掩码GICC->PMR |= (0x1f<<3);//设置组0中断交给指定处理器处理GICC->CTRL |= 0x1;}
现象