复制代码- /*
- time:2011.3.24 editor:kissyyg filename:main.c
- function:the key1,2,3,4 are set as interrupt mode,their priorites
-
- are same and they control led1,2,3,4 one by one
- */
- int main()
- {
- while(1)
- ;
- return 0;
- }
- /*
- time:2011.3.24 editor:kissyyg filename:eint_handle.c
- function:the irq handle function
- */
- #define INTOFFSET (*(volatile unsigned long*)0x4a000014)
- #define INTPND (*(volatile unsigned *)0x4a000010)
- #define SRCPND (*(volatile unsigned *)0x4a000000)
- #define EINTPND (*(volatile unsigned *)0x560000a8)
- #define GPBDAT *((volatile unsigned long*)0x56000014)
- #define EINTPND_8 (1<<8)
- #define EINTPND_11 (1<<11)
- #define EINTPND_13 (1<<13)
- #define EINTPND_14 (1<<14)
- #define led1_on ~(1<<5)
- #define led2_on ~(1<<6)
- #define led3_on ~(1<<7)
- #define led4_on ~(1<<8)
- void eint_handle()
- {
- unsigned long oft = INTOFFSET;
- unsigned long val;
-
- if(oft==5) //int8_11 interrupt happend
- {
- GPBDAT = 0xffff; //turn down all the led
- val = EINTPND;
-
- if(val & EINTPND_8) //if k1 is pressed turn on led1 only
- GPBDAT &= led1_on;
-
- if(val & EINTPND_11) //if k2 is pressed turn on led2 only
- GPBDAT &= led2_on;
-
- if(val & EINTPND_13) //if k3 is pressed turn on led3 only
- GPBDAT &= led3_on;
-
- if(val & EINTPND_14) //if k4 is pressed turn on led4 only
- GPBDAT &= led4_on;
-
- //clear the eintpend and srcpend and intpend in order
-
- EINTPND = (1<<8) | (1<<11) | (1<<13) | (1<<14);
- SRCPND = 1<<oft;
- INTPND = 1<<oft;
-
- }
-
-
-
- }
- /*
- time:2011.3.24 editor:kissyyg filename:disable_watch_dog.c
- function: close the watch dog
- */
- void disable_watch_dog()
- {
- __asm
- {
- MOV r0, #0x53000000
- MOV r1, #0x0
- STR r1, [r0]
- }
- }
- ;time:2011.3.24 editor:kissyyg filename:head.s
- ;function:init the irq vector and the start the operator
-
-
-
- IMPORT main
-
- IMPORT init_led
-
- IMPORT disable_watch_dog
-
- IMPORT init_irq
-
- IMPORT eint_handle
-
- CODE32
- AREA test,CODE,READONLY
- ENTRY
-
-
- B Reset
- HANDLE_UNDEFINE
-
- B HANDLE_UNDEFINE
-
- HANDLE_SWI
-
- B HANDLE_SWI
- HANDLE_PREFETCH_ABORT
-
- B HANDLE_PREFETCH_ABORT
-
- HANDLE_DATA_ABORT
-
- B HANDLE_DATA_ABORT
-
- HANDLE_NOTUSED
-
- B HANDLE_NOTUSED
- HANDLE_IRQ
-
- B handle_irq
- HANDLE_FIQ
-
- B HANDLE_FIQ
-
- Reset
-
- LDR SP, =4096
-
- BL disable_watch_dog
-
- MSR CPSR_c, #0xd2
-
- LDR SP, =3072
-
- MSR CPSR_c, #0xdf
-
- BL init_led
-
- BL init_irq
-
- MSR CPSR_c, #0x5f
-
- LDR LR, =halt_loop
-
- LDR PC, =main
-
- halt_loop
-
- B halt_loop
-
- handle_irq
-
- SUB LR, LR, #4
-
- STMDB SP!, { R0-R12,LR }
-
- LDR LR, =INT_RETURN
-
- LDR PC, =eint_handle
-
- INT_RETURN
- LDMIA SP!, { R0-R12,PC }^
-
- END
- /*
- time:2011.3.24 editor:kissyyg filename:init_led.c
- function:init the led's io port as the output mode
- */
- #define GPBCON *((volatile unsigned long*)0x56000010)
- #define GPB5_OUT (1<<(5*2))
- #define GPB6_OUT (1<<(6*2))
- #define GPB7_OUT (1<<(7*2))
- #define GPB8_OUT (1<<(8*2))
- void init_led()
- {
- GPBCON = GPB5_OUT | GPB6_OUT | GPB7_OUT | GPB8_OUT;
-
- }
- /*
- time: 2011.3.24 editor:kissyyg filename:init_irq.c
- function: init the irq,k1,k2,k3,k4 are related to GPG0,GPG3,GPG5,GPG6
- so as to EINT8EINT11,EINT13,EINT14,they are added to ARB1
- conctroller which is binded to REQ1as they are in the same
-
- team od REQ1,so their priority are same
- */
- #define GPGCON *((volatile unsigned long*)0x56000060)
- #define EINTMASK *((volatile unsigned long*)0x560000a4)
- #define INTMASK *((volatile unsigned long*)0x4a000008)
- #define PRIORITY *((volatile unsigned long*)0x4a000008)
- #define GPG0_EINT (2<<(0*2))
- #define GPG3_EINT (2<<(3*2))
- #define GPG5_EINT (2<<(5*2))
- #define GPG6_EINT (2<<(6*2))
- #define EINT8_UNMASK (~(1<<8))
- #define EINT11_UNMASK (~(1<<11))
- #define EINT13_UNMASK (~(1<<13))
- #define EINT14_UNMASK (~(1<<14))
- #define EINT_8TO23_UNMASK (~(1<<5))
- void init_irq()
- {
- // config the GPGCON and EINTMASK registers
-
- GPGCON = GPG0_EINT | GPG3_EINT | GPG5_EINT | GPG6_EINT;
- EINTMASK &= EINT8_UNMASK & EINT11_UNMASK & EINT13_UNMASK & EINT14_UNMASK;
-
- // config INTMASK register
-
- INTMASK &= EINT_8TO23_UNMASK;
-
- }
|