#ifndef __KEY_H__
#define __KEY_H__
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_exti.h"
#include "stm32mp1xx_gic.h"
//对RCC/GPIO/EXTI章节的初始化
void hal_key1_exti_init();
//对GIC的初始化
void hal_key1_gic_init();
#endif
#include "key.h"
extern void printf(const char *fmt, ...);
void do_irq(void)
{
unsigned int num;
num = GICC->IAR & 0x3ff;
switch (num)
{
case 99:
printf("key1 press#####\n");
//1.消除EXTI层中断挂起标志位
EXTI->FPR1 |= (0x1 << 9);
//2.消除GICD层的中断挂起标志位
GICD->ICPENDR[3] |= (0x1 << 3);
break;
case 98:
break;
case 97:
break;
}
//3.清除获取到的中断号
GICC->EOIR |= num;
}
#include "key.h"
//对RCC/GPIO/EXTI章节的初始化
void hal_key1_exti_init()
{
//RCC
RCC->MP_AHB4ENSETR |= (0x1 << 5);
//GPIO设置输入模式
GPIOF->MODER &= (~(0x3 << 18));
//EXTI
//1.外部中断选择寄存器,选择与哪个EXTI(16)链接
EXTI->EXTICR3 &= (~(0xff << 8));
EXTI->EXTICR3 |= (0x5 << 8);
//2.设置中断下降沿触发方式
EXTI->FTSR1 |= (0x1 << 9);
//3.中断屏蔽选择寄存器
EXTI->C1IMR1 |= (0b01 << 9);
}
//对GIC的初始化
void hal_key1_gic_init()
{
//GICD的初始化
//1.使能GICD层控制器
GICD->CTLR |= 0x1;
//2.设置GICD层的中断使能
GICD->ISENABLER[3] |= (0x1 << 3);
//3.设置GICD层中断优先级
GICD->IPRIORITYR[24] &= (~(0x1F << 27));
//4.设置GICD层中断目标分配寄存器
GICD->ITARGETSR[24] |= (0x1 << 24);
//GICC章节初始化
//1.使能GICC层控制器
GICC->CTLR |= 0x1;
//2.设置GICC层中断优先级
GICC->PMR |= (0x1 << 3);
}