练习:
封装exti,cic初始化函数
//EXTI初始化
void hal_key_exti_init(int id,int exticr,int mode){//获取偏移地址int address_offset = (id%4)*8;//获取寄存器编号int re_ser = (id/4)+1;//printf("address_offset=%d,re_ser=%d\n",address_offset,re_ser);//1.设置外部中断选择寄存器进行连接if(re_ser==1){EXTI->EXTICR1 &= ~(0xff<<address_offset);EXTI->EXTICR1 |= (exticr<<address_offset);}else if(re_ser==2){EXTI->EXTICR2 &= ~(0xff<<address_offset);EXTI->EXTICR2 |= (exticr<<address_offset);}else if(re_ser==3){EXTI->EXTICR3 &= ~(0xff<<address_offset);EXTI->EXTICR3 |= (exticr<<address_offset);}else if(re_ser==4){EXTI->EXTICR4 &= ~(0xff<<address_offset);EXTI->EXTICR4 |= (exticr<<address_offset);}//2.设置触发方式if(mode==1){EXTI->FTSR1 &= ~(0x1<<id);EXTI->RTSR1 |= (0x1<<id);}else if(mode==0){EXTI->RTSR1 &= ~(0x1<<id);EXTI->FTSR1 |= (0x1<<id);}//3.设置EXTI层中断不屏蔽EXTI->C1IMR1 |= (0x1<<id);
}//GIC初始化
void hal_key_gic_init(int id,int interrupt_lv){//获取中断id对应使能寄存器偏移量int address_offset = id%32;//获取中断id对应使能寄存器int re_enable = id/32;//printf("address_offset=%d,re_enable=%d\n",address_offset,re_enable);//GICD//1.使能GICD组0GICD->CTRL |= (0x1<<0);//2.设置对应中断号使能GICD->ISENABLER[re_enable] |= (0x1<<address_offset);//2.设置GICD层中断优先级GICD->IPRIORITYR[re_enable*8] &= (~(interrupt_lv<<(address_offset*8+3)));//3.设置GICD层中断分配GICD->ITARGETSR[re_enable*8] &= (~(0x3<<(address_offset*8)));GICD->ITARGETSR[re_enable*8] |= (0x1<<(address_offset*8));//1.设置GICC层组0使能GICC->CTRL |= (0x1<<0);//2.设置GICC层中断优先级GICC->PMR &= (~(0x1f<<3));GICC->PMR |= (0x1f<<3);
}