1 #include "key1.h"2 //封装EXTI章节函数3 void hal_exti_init(int exti,unsigned int i)4 {5 switch(exti)6 {7 case 9:8 //使能GPIOF外设时钟9 RCC->MP_AHB4ENSETR |= (0x1<<5);10 //将PF9设置为输出模式11 GPIOF->MODER &= (~(0x3<<(exti*2)));12 13 //选择PF9产生EXTI9事件 14 EXTI->EXTICR3 &= (~(0xff<<(exti%4)*8));15 EXTI->EXTICR3 |= (i<<(exti%4)*8);16 //设置下降沿检测EXTI9事件17 EXTI->FTSR1 |= (0x1<<exti);18 //取消EXTI9事件中断屏蔽19 EXTI->C1IMR1 |= (0x1<<exti);20 break;21 case 7:22 //使能GPIOF外设时钟23 RCC->MP_AHB4ENSETR |= (0x1<<5);24 //将PF9设置为输出模式25 GPIOF->MODER &= (~(0x3<<(exti*2)));26 27 //选择PF9产生EXTI9事件 28 EXTI->EXTICR2 &= (~(0xff<<(exti%4)*8));29 EXTI->EXTICR2 |= (i<<(exti%4)*8);30 //设置下降沿检测EXTI9事件31 EXTI->FTSR1 |= (0x1<<exti);32 //取消EXTI9事件中断屏蔽33 EXTI->C1IMR1 |= (0x1<<exti);34 break; 35 case 8:36 //使能GPIOF外设时钟37 RCC->MP_AHB4ENSETR |= (0x1<<5);38 //将PF9设置为输出模式39 GPIOF->MODER &= (~(0x3<<(exti*2)));40 41 //选择PF9产生EXTI9事件 42 EXTI->EXTICR3 &= (~(0xff<<(exti%4)*8));43 EXTI->EXTICR3 |= (i<<(exti%4)*8);44 //设置下降沿检测EXTI9事件45 EXTI->FTSR1 |= (0x1<<exti);46 //取消EXTI9事件中断屏蔽47 EXTI->C1IMR1 |= (0x1<<exti);48 break;49 }50 }51 52 //封装GIC章节函数53 void hal_gic_init(int uart_num,unsigned int i)54 {55 //使能99号中断56 GICD->ISENABLER[uart_num/32] |= (0x1<<(uart_num%32));57 //设置99号中断优先级58 GICD->IPRIORITYR[uart_num/4] &= (~(i<<(uart_num%4*8+3)));59 //设置99号的中断目标处理器60 GICD->ITARGETSR[uart_num/4] &= (~(0x3<<(uart_num%4*8)));61 GICD->ITARGETSR[uart_num/4] |= (0x1<<(uart_num%4*8));62 63 //全局使能组0中断被转发到GICC层64 GICD->CTRL |= 0x1;65 //设置中断的优先级掩码66 GICC->PMR |= (0x1f<<3);67 //全局使能组0中断被转发到处理器68 GICC->CTRL |= 0x1;69 }
~