主题 : 韦老板_mini2440_2_防不胜防之中断 复制链接 | 浏览器收藏 | 打印
知识改变命运!
级别: 新手上路
UID: 39523
精华: 0
发帖: 7
金钱: 35 两
威望: 7 点
贡献值: 0 点
综合积分: 14 分
注册时间: 2011-03-09
最后登录: 2011-06-16
楼主  发表于: 2011-03-26 10:49

 韦老板_mini2440_2_防不胜防之中断

首先我说下我的修改的地方:
1:在handle_irq处我觉得ldr lr, =int_return没有用,所以删掉
2:K1,K2,K3,K4,都处于REQ5中所以他们的优先级相等
复制代码
  1. /*
  2. time:2011.3.24        editor:kissyyg        filename:main.c
  3. function:the key1,2,3,4 are set as interrupt mode,their priorites
  4.         
  5.          are same and they control led1,2,3,4 one by one
  6. */
  7. int main()
  8. {
  9.     while(1)
  10.         ;
  11.     return 0;
  12. }
  13. /*
  14. time:2011.3.24        editor:kissyyg        filename:eint_handle.c
  15. function:the irq handle function
  16. */
  17. #define INTOFFSET (*(volatile unsigned long*)0x4a000014)  
  18. #define INTPND    (*(volatile unsigned *)0x4a000010)
  19. #define SRCPND    (*(volatile unsigned *)0x4a000000)
  20. #define EINTPND  (*(volatile unsigned *)0x560000a8)
  21. #define GPBDAT *((volatile unsigned long*)0x56000014)
  22. #define EINTPND_8  (1<<8)
  23. #define EINTPND_11 (1<<11)
  24. #define EINTPND_13 (1<<13)
  25. #define EINTPND_14 (1<<14)
  26. #define led1_on     ~(1<<5)
  27. #define led2_on     ~(1<<6)
  28. #define led3_on     ~(1<<7)
  29. #define led4_on     ~(1<<8)
  30. void eint_handle()
  31. {
  32.     unsigned long oft = INTOFFSET;
  33.     unsigned long val;
  34.     
  35.     if(oft==5)                            //int8_11 interrupt happend
  36.     {
  37.         GPBDAT = 0xffff;                //turn down all the led
  38.         val = EINTPND;
  39.         
  40.         if(val & EINTPND_8)            //if k1 is pressed turn on led1 only  
  41.             GPBDAT &= led1_on;
  42.             
  43.         if(val & EINTPND_11)            //if k2 is pressed turn on led2 only
  44.             GPBDAT &= led2_on;
  45.             
  46.         if(val & EINTPND_13)            //if k3 is pressed turn on led3 only
  47.             GPBDAT &= led3_on;            
  48.             
  49.         if(val & EINTPND_14)            //if k4 is pressed turn on led4 only
  50.             GPBDAT &= led4_on;            
  51.         
  52.         //clear the eintpend and  srcpend and intpend in order
  53.         
  54.         EINTPND = (1<<8) | (1<<11) | (1<<13) | (1<<14);
  55.         SRCPND  = 1<<oft;
  56.         INTPND  = 1<<oft;
  57.     
  58.     }
  59.     
  60.     
  61.     
  62. }
  63. /*
  64. time:2011.3.24        editor:kissyyg        filename:disable_watch_dog.c
  65. function: close the watch dog
  66. */
  67. void disable_watch_dog()
  68. {
  69.     __asm
  70.         {
  71.         MOV r0, #0x53000000
  72.         MOV r1, #0x0
  73.         STR r1, [r0]
  74.         }
  75. }
  76. ;time:2011.3.24        editor:kissyyg        filename:head.s
  77. ;function:init the irq vector and the start the operator
  78.     
  79.     
  80.     
  81.     IMPORT main
  82.     
  83.     IMPORT init_led
  84.     
  85.     IMPORT disable_watch_dog
  86.     
  87.     IMPORT init_irq
  88.     
  89.     IMPORT eint_handle
  90.     
  91.     CODE32
  92.     AREA test,CODE,READONLY
  93.     ENTRY
  94.     
  95.     
  96.     B Reset
  97. HANDLE_UNDEFINE
  98.     
  99.     B HANDLE_UNDEFINE
  100.     
  101. HANDLE_SWI
  102.     
  103.     B HANDLE_SWI
  104. HANDLE_PREFETCH_ABORT
  105.     
  106.     B HANDLE_PREFETCH_ABORT
  107.     
  108. HANDLE_DATA_ABORT
  109.     
  110.     B HANDLE_DATA_ABORT
  111.     
  112. HANDLE_NOTUSED
  113.     
  114.     B HANDLE_NOTUSED
  115. HANDLE_IRQ
  116.     
  117.     B handle_irq    
  118. HANDLE_FIQ
  119.     
  120.     B HANDLE_FIQ
  121.     
  122. Reset
  123.     
  124.     LDR SP, =4096
  125.     
  126.     BL disable_watch_dog
  127.     
  128.     MSR CPSR_c, #0xd2
  129.     
  130.     LDR SP, =3072
  131.     
  132.     MSR CPSR_c, #0xdf
  133.     
  134.     BL init_led
  135.     
  136.     BL init_irq
  137.     
  138.     MSR CPSR_c, #0x5f
  139.     
  140.     LDR LR, =halt_loop
  141.     
  142.     LDR PC, =main
  143.     
  144. halt_loop
  145.         
  146.     B halt_loop
  147.     
  148. handle_irq    
  149.         
  150.     SUB LR, LR, #4
  151.     
  152.     STMDB SP!, { R0-R12,LR }    
  153.     
  154.     LDR LR, =INT_RETURN
  155.     
  156.     LDR PC, =eint_handle
  157.     
  158. INT_RETURN
  159.     LDMIA SP!, { R0-R12,PC }^
  160.     
  161.     END
  162. /*
  163. time:2011.3.24        editor:kissyyg        filename:init_led.c
  164. function:init the led's io port as the output mode
  165. */
  166. #define GPBCON *((volatile unsigned long*)0x56000010)
  167. #define GPB5_OUT (1<<(5*2))
  168. #define GPB6_OUT (1<<(6*2))
  169. #define GPB7_OUT (1<<(7*2))
  170. #define GPB8_OUT (1<<(8*2))
  171. void init_led()
  172. {
  173.     GPBCON = GPB5_OUT | GPB6_OUT | GPB7_OUT | GPB8_OUT;
  174.     
  175. }
  176. /*
  177. time:    2011.3.24        editor:kissyyg        filename:init_irq.c
  178. function: init the irq,k1,k2,k3,k4 are related to GPG0,GPG3,GPG5,GPG6
  179.           so as to EINT8EINT11,EINT13,EINT14,they are added to ARB1
  180.           conctroller which is binded to REQ1as they are in the same
  181.           team od REQ1,so their priority are same
  182. */
  183. #define GPGCON   *((volatile unsigned long*)0x56000060)
  184. #define EINTMASK *((volatile unsigned long*)0x560000a4)
  185. #define INTMASK  *((volatile unsigned long*)0x4a000008)
  186. #define PRIORITY *((volatile unsigned long*)0x4a000008)
  187. #define GPG0_EINT (2<<(0*2))
  188. #define GPG3_EINT (2<<(3*2))
  189. #define GPG5_EINT (2<<(5*2))
  190. #define GPG6_EINT (2<<(6*2))
  191. #define EINT8_UNMASK  (~(1<<8))
  192. #define EINT11_UNMASK (~(1<<11))
  193. #define EINT13_UNMASK (~(1<<13))
  194. #define EINT14_UNMASK (~(1<<14))
  195. #define EINT_8TO23_UNMASK (~(1<<5))
  196. void init_irq()
  197. {
  198.     // config the GPGCON and EINTMASK registers
  199.     
  200.     GPGCON = GPG0_EINT | GPG3_EINT | GPG5_EINT | GPG6_EINT;
  201.     EINTMASK &= EINT8_UNMASK & EINT11_UNMASK & EINT13_UNMASK & EINT14_UNMASK;
  202.     
  203.     // config INTMASK register
  204.     
  205.     INTMASK &= EINT_8TO23_UNMASK;
  206.     
  207. }



好了,欢迎大家一起讨论,下篇 时钟和定时器