当前位置:   article > 正文

0703_ARM7

0703_ARM7

练习:

封装exti,cic初始化函数
 

  1. //EXTI初始化
  2. void hal_key_exti_init(int id,int exticr,int mode){
  3. //获取偏移地址
  4. int address_offset = (id%4)*8;
  5. //获取寄存器编号
  6. int re_ser = (id/4)+1;
  7. //
  8. printf("address_offset=%d,re_ser=%d\n",address_offset,re_ser);
  9. //1.设置外部中断选择寄存器进行连接
  10. if(re_ser==1){
  11. EXTI->EXTICR1 &= ~(0xff<<address_offset);
  12. EXTI->EXTICR1 |= (exticr<<address_offset);
  13. }else if(re_ser==2){
  14. EXTI->EXTICR2 &= ~(0xff<<address_offset);
  15. EXTI->EXTICR2 |= (exticr<<address_offset);
  16. }else if(re_ser==3){
  17. EXTI->EXTICR3 &= ~(0xff<<address_offset);
  18. EXTI->EXTICR3 |= (exticr<<address_offset);
  19. }else if(re_ser==4){
  20. EXTI->EXTICR4 &= ~(0xff<<address_offset);
  21. EXTI->EXTICR4 |= (exticr<<address_offset);
  22. }
  23. //2.设置触发方式
  24. if(mode==1){
  25. EXTI->FTSR1 &= ~(0x1<<id);
  26. EXTI->RTSR1 |= (0x1<<id);
  27. }else if(mode==0){
  28. EXTI->RTSR1 &= ~(0x1<<id);
  29. EXTI->FTSR1 |= (0x1<<id);
  30. }
  31. //3.设置EXTI层中断不屏蔽
  32. EXTI->C1IMR1 |= (0x1<<id);
  33. }
  34. //GIC初始化
  35. void hal_key_gic_init(int id,int interrupt_lv){
  36. //获取中断id对应使能寄存器偏移量
  37. int address_offset = id%32;
  38. //获取中断id对应使能寄存器
  39. int re_enable = id/32;
  40. //
  41. printf("address_offset=%d,re_enable=%d\n",address_offset,re_enable);
  42. //GICD
  43. //1.使能GICD组0
  44. GICD->CTRL |= (0x1<<0);
  45. //2.设置对应中断号使能
  46. GICD->ISENABLER[re_enable] |= (0x1<<address_offset);
  47. //2.设置GICD层中断优先级
  48. GICD->IPRIORITYR[re_enable*8] &= (~(interrupt_lv<<(address_offset*8+3)));
  49. //3.设置GICD层中断分配
  50. GICD->ITARGETSR[re_enable*8] &= (~(0x3<<(address_offset*8)));
  51. GICD->ITARGETSR[re_enable*8] |= (0x1<<(address_offset*8));
  52. //1.设置GICC层组0使能
  53. GICC->CTRL |= (0x1<<0);
  54. //2.设置GICC层中断优先级
  55. GICC->PMR &= (~(0x1f<<3));
  56. GICC->PMR |= (0x1f<<3);
  57. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/804355
推荐阅读
相关标签
  

闽ICP备14008679号