微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > mini6410中断控制器-VIC中断控制器

mini6410中断控制器-VIC中断控制器

时间:11-20 来源:互联网 点击:

  1. sf,#0xd2;切换到中断模式下
  2. ldrsp,=0x51000000;设置中断模式栈指针
  3. msrcpsr_cxsf,#0x13;返回管理模式
  4. IMPORTxmain
  5. blxmain
  6. loop
  7. bloop
  8. ;***********************************************************************
  9. ;中断处理
  10. ;***********************************************************************
  11. ;K1pressirq
  12. EXPORTasm_handle_k1_irq
  13. asm_handle_k1_irq
  14. sublr,lr,#4;修正返回地址
  15. stmdbsp!,{r0-r12,lr};保存程序执行现场
  16. ldrlr,=isr_return;设置中断处理程序返回地址
  17. IMPORT__do_k1_irq
  18. ldrpc,=__do_k1_irq;跳入中断处理程序
  19. ;timer0pressirq
  20. EXPORTasm_handle_tmr0_irq
  21. asm_handle_tmr0_irq
  22. sublr,lr,#4;修正返回地址
  23. stmdbsp!,{r0-r12,lr};保存程序执行现场
  24. ldrlr,=isr_return;设置中断处理程序返回地址
  25. IMPORT__do_tmr0_irq
  26. ldrpc,=__do_tmr0_irq;跳入中断处理程序
  27. isr_return;中断处理返回标签
  28. ldmiasp!,{r0-r12,pc}^;恢复程序执行现场,返回继续执行
  29. END;程序结束符

init.c
//////////////////////////////////////////////////////////////////////////////////

  1. #defineGPNCON(*(volatileunsignedlong*)0x7F008830)
  2. #defineGPNPUD(*(volatileunsignedlong*)0x7F008838)
  3. #defineEINT0CON0(*(volatileunsignedlong*)0x7F008900)
  4. #defineEINT0MASK(*(volatileunsignedlong*)0x7F008920)
  5. #defineVIC0IRQSTATUS(*(volatileunsignedlong*)0x71200004)
  6. #defineVIC0INTSELECT(*(volatileunsignedlong*)0x7120000C)
  7. #defineVIC1INTSELECT(*(volatileunsignedlong*)0x7130000C)
  8. #defineVIC0INTENABLE(*(volatileunsignedlong*)0x71200010)
  9. #defineVIC1INTENABLE(*(volatileunsignedlong*)0x71300010)
  10. #defineVIC0INTENCLEAR(*(volatileunsignedlong*)0x71200014)
  11. #defineVIC1INTENCLEAR(*(volatileunsignedlong*)0x71300014)
  12. #defineVIC0VECTADDR(*(volatileunsignedlong*)0x71200100)
  13. #defineINT_EINT0_BIT0
  14. #defineINT_TIMER0_BIT23
  15. //////////////////////////////////////////////////////////////////////////////////
  16. externvoidasm_handle_k1_irq(void);
  17. externvoidasm_handle_tmr0_irq(void);
  18. typedefvoid(fnc_t)(void);
  19. fnc_t**isr_array=(fnc_t**)0x71200100;
  20. voidirq_init()
  21. {
  22. __asm{
  23. mrcp15,0,r0,c1,c0,0;
  24. orrr0,r0,#(0x1000000);
  25. mcrp15,0,r0,c1,c0,0;
  26. }
  27. //configureGPN0asEINT0
  28. GPNCON&=(~0x2);
  29. GPNCON|=0x2;
  30. GPNPUD&=~(0x3);
  31. //K1,K2fallingedgetrigged
  32. EINT0CON0&=(~0x3);
  33. EINT0CON0|=0x3;
  34. //EnableEINT0irq
  35. EINT0MASK&=(~0x1);
  36. //SelectINT_EINT0modeasirq
  37. VIC0INTSELECT&=(~(1
  38. //inittheisraddr
  39. isr_array[INT_EINT0_BIT]=(fnc_t*)asm_handle_k1_irq;
  40. isr_array[INT_TIMER0_BIT]=(fnc_t*)asm_handle_tmr0_irq;
  41. //enableINT_EINT0
  42. VIC0INTENABLE|=(1
  43. printk("irqinitOK\r\n");
  44. }

handle_irq.c

  1. //====================================================
  2. #defineVIC0ADDRESS(*(volatileunsignedlong*)0x71200F00)
  3. #defineVIC1ADDRESS(*(volatileunsignedlong*)0x71300F00)
  4. #defineEINT0PEND(*(volatileunsignedlong*)0x7F008924)
  5. #defineTINT_CSTAT(*(volatileunsignedlong*)0x7F006044)
  6. externintprintk(char*);
  7. /*系统中断处理函数*/
  8. #defineclear_irq()\
  9. do{\
  10. VIC0ADDRESS=0;\
  11. VIC1ADDRESS=0;\
  12. }while(0)
  13. void__do_k1_irq(void)
  14. {
  15. printk("do_irq\r\n");
  16. //clearK1irq
  17. EINT0PEND=1;
  18. //clearVICADDRESS
  19. clear_irq();
  20. }
  21. void__do_tmr0_irq(void)
  22. {
  23. printk("Timer0irqoccur\r\n");
  24. //cleartimer0irq
  25. TINT_CSTAT|=1<5;
  26. //clearVICADDRESS
  27. clear_irq();
  28. return;
  29. }

main.c

  1. //===================================================
  2. #defineGPKCON(*(volatileunsignedlong*)0x7F008800)
  3. #defineGPKDAT(*(volatileunsignedlong*)0x7F008808)
  4. #defineLED_BIT(1<5|1<6|1<7|1<8)
  5. externvoiduart_init(void);
  6. externvoidirq_init(void);
  7. externvoidtimer0_init(void);
  8. externintprintk(constchar*str);
  9. externvoidled_run(void);
  10. intled_on()
  11. {
  12. GPKCON&=0xFFFF0000;//设置GPB5~8为输出口
  13. GPKCON|=0x11110000;
  14. GPKDAT=0;//令LED亮灯
  15. printk("led_on\n\r");
  16. return0;
  17. }
  18. intxmain(){
  19. uart_init();
  20. printk("uart_initOK\n\r");
  21. led_on();
  22. irq_init();
  23. timer0_init();
  24. led_run();
  25. return0;
  26. }


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top