#include "key.h"
extern void printf(const char *fmt, ...);
unsigned int i=0;
void hal_key1_rcc_gpio_init(void)
{
// 1. Enable the GPIO clock
RCC->MP_AHB4ENSETR |= (0x1 << 5);
// 2.给PF9设置为输入模式
GPIOF->MODER &= (~(0x3 << 18));
// 给PF7设置为输入模式
GPIOF->MODER &= (~(0x3 << 14));
// 给PF8设置为输入模式
GPIOF->MODER &= (~(0x3 << 16));
}
void hal_key1_exti_init(void)
{
EXTI->EXTICR3 |= (0x05 << 8);
EXTI->EXTICR2 |= (0x05 << 24);
EXTI->EXTICR3 |= (0x05 << 0);
// EXTI_FTSR1下降沿触发
EXTI->FTSR1 |= (0x7 << 7);
// EXTI_FTSR1中断不屏蔽
EXTI->C1IMR1 &= (~(0x7 << 7));
EXTI->C1IMR1 |= (0x7 << 7);
}
void hal_key1_gic_init(void)
{
GICD->ISENABLER[3] |= (0x7 << 1); // 设置对应的中断号使能
GICD->IPRIORITYR[24] |= (0x1 << 27);
GICD->IPRIORITYR[24] |= (0x2 << 11);
GICD->IPRIORITYR[24] |= (0x3 << 19); // GICD的优先级设计
GICD->ITARGETSR[24] |= (0x1 << 24);
GICD->ITARGETSR[24] |= (0x1 << 8);
GICD->ITARGETSR[24] |= (0x1 << 16);//设置中断的目标分配寄存器
//全局使能组0中断转发到GICC层
GICD->CTRL |= (0x1 << 0);
//设置GICC层的优先级
GICC->PMR |=(0x5<<3);
GICC->CTRL |=(0x1);
}
void do_irq()
{
unsigned int j=(GICC->IAR &0x3ff);
switch(j)
{
case 99:
printf("key1\n");
GICD->ICPENDR[3] |= (0x1 << 3);
EXTI->FPR1 |=(0x1<<9);
break;
case 97:
printf("key2\n");
GICD->ICPENDR[3] |= (0x1 << 1);
EXTI->FPR1 |=(0x1<<7);
break;
case 98:
printf("key3\n");
GICD->ICPENDR[3] |= (0x1 << 2);
EXTI->FPR1 |=(0x1<<8);
break;
}
GICC->EOIR =j;
}
#include "key.h"
extern void printf(const char *fmt,...);
void delay_ms(int ms)
{
int i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<2000;j++)
{
}
}
}
int main()
{
hal_key1_rcc_gpio_init();
hal_key1_exti_init();
hal_key1_gic_init();
while(1)
{}
return 0;
}