作业
实验现象,主函数每一秒循环字符m,当按下按键1,则串口输出1,按下按键2,串口输出2,按下按键3,串口输出3
main.c
#include "uart4.h"
#include "led.h"
#include "key_in.h"
int main()
{
uart4_init();
all_led_init();
key1_init();
key2_init();
key3_init();
while(1)
{
putchar('m');
delay(1000);
}
return 0;
}
do_irq.c
#include "stm32mp1xx_gic.h"
#include "stm32mp1xx_exti.h"
#include "uart4.h"
extern void printf(const char *fmt, ...);
unsigned int i = 0;
void do_irq(void)
{
uart4_init();
unsigned int irqno=GICC->IAR&0x3ff;
switch(irqno)
{
case 99:
putchar('1');
GICD->ICPENDR[3] |=(0x1<<3);
EXTI->FPR1 |=(0x1<<9);
break;
case 97:
putchar('2');
GICD->ICPENDR[3] |=(0x1<<1);
EXTI->FPR1 |=(0x1<<7);
break;
case 98:
putchar('3');
GICD->ICPENDR[3] |=(0x1<<2);
EXTI->FPR1 |=(0x1<<8);
break;
default:
break;
}
GICC->EOIR |=irqno;
}
key_in.c
#include "key_in.h"
void key1_init()
{
//使能GPIOF外设时钟
RCC->MP_AHB4ENSETR |=(0x1<< 5);
//将pf9设为输出模式
GPIOF->MODER &=(~(0x3<<18));
//设置pf9管脚产生exti9事件
EXTI->EXTICR3 &=(~(0xff<<8));
EXTI->EXTICR3 |=(0x05<<8);
//通过下降沿判断事件9是否产生
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_init()
{
//使能GPIOF外设时钟
RCC->MP_AHB4ENSETR |=(0x1<< 5);
//将pf7设为输出模式
GPIOF->MODER &=(~(0x3<<14));
//设置pf7管脚产生exti7事件
EXTI->EXTICR2 &=(~(0xff<<24));
EXTI->EXTICR2 |=(0x05<<24);
//通过下降沿判断事件7是否产生
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_init()
{
//使能GPIOF外设时钟
RCC->MP_AHB4ENSETR |=(0x1<< 5);
//将pf8设为输出模式
GPIOF->MODER &=(~(0x3<<16));
//设置pf8管脚产生exti8事件
EXTI->EXTICR3 &=(~(0xff));
EXTI->EXTICR3 |=(0x05);
//通过下降沿判断事件8是否产生
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;
}