S5PV210有4个向量中断控制器(VIC),每个向量中断控制器包含32个中断源。
当某个中断源产生中断时,CPU会自动的将VICxVECTADDRy(x=0,1,2,3,y=0-31)寄存器的值赋给VICxADDRESS(x=0,1,2,3),因此我们可以把我们的中断处理函数的地址赋给VICxVECTADDRy寄存器,
比如我们有个函数
void key_handle()
{
……
}
我们把key_handle 函数的值赋给VIC0VECTADDR0(外部中断0)
VIC0VECTADDR0 =key_handle;
当外部中断0触发中断时,CPU会自动的将VIC0VECTADDR0的值赋给VIC0ADDRESS,并跳转到这个地址去执行,即执行函数key_handle。
代码如下:
start.S
[cpp] view plaincopy
01..global _start
02..global key_isr
03._start:
04.
05. ldr sp, =0x40000000
06.
07.
08. mrs r0, cpsr
09. bic r0, r0, #0x00000080
10. msr cpsr, r0
11.
12. bl main
13.
14.halt:
15. b halt
16.
17.key_isr:
18.
20. sub lr, lr, #4
21. stmfd sp!, {r0-r12, lr}
22. bl key_handle
23.
24. ldmfd sp!, {r0-r12, pc}^
key.c
[cpp] view plaincopy
01.#define GPC0CON *((volatile unsigned int *)0xE0200060)
02.#define GPC0DAT *((volatile unsigned int *)0xE0200064)
03.
04.#define GPH0CON *((volatile unsigned int *)0xE0200C00)
05.#define GPH0DAT *((volatile unsigned int *)0xE0200C04)
06.
07.#define EXT_INT_0_CON *((volatile unsigned int *)0xE0200E00)
08.#define EXT_INT_0_MASK *((volatile unsigned int *)0xE0200F00)
09.
10.#define VIC0INTSELECT *((volatile unsigned int *)0xF200000C)
11.#define VIC0INTENABLE *((volatile unsigned int *)0xF2000010)
12.
13.#define VIC0VECTADDR0 *((volatile unsigned int *)0xF2000100)
14.#define VIC0VECTADDR1 *((volatile unsigned int *)0xF2000104)
15.
16.#define VIC0ADDRESS *((volatile unsigned int *)0xF2000F00)
17.
18.#define EXT_INT_0_PEND *((volatile unsigned int *)0xE0200F40)
19.
20.extern void key_isr(void);
21.
22.void key_handle()
23.{
24. volatile unsigned char key_code = EXT_INT_0_PEND & 0x3;
25.
26. VIC0ADDRESS = 0;
27. EXT_INT_0_PEND |= 3;
28.
29. if (key_code == 1)
30. GPC0DAT ^= 1 << 3;
31. else if (key_code == 2)
32. GPC0DAT ^= 1 << 4;
33.}
34.
35.int main()
36.{
37. GPC0CON &= ~(0xFF << 12);
38. GPC0CON |= 0x11 << 12;
39. GPH0CON |= 0xFF << 0;
40.
41. EXT_INT_0_CON &= ~(0xFF << 0);
42. EXT_INT_0_CON |= 2 | (2 << 4);
43. EXT_INT_0_MASK &= ~3;
44.
45. VIC0INTSELECT &= ~3;
46.
47. VIC0INTENABLE |= 3;
48.
49. VIC0VECTADDR0 = (int)key_isr;
51. VIC0VECTADDR1 = (int)key_isr;
52.
53. while (1);
54.
55. return 0;
56.}
Makefile
[cpp] view plaincopy
01.key.bin: start.o key.o
02. arm-linux-ld -Ttext 0x20000000 -o key.elf $^
03. arm-linux-objcopy -O binary key.elf $@
04. arm-linux-objdump -D key.elf > key.dis
05.
06.key.o : key.c
07. arm-linux-gcc -c $< -o $@
08.start.o : start.S
09. arm-linux-gcc -c $< -o $@
10.
11.clean:
12. rm *.o *.elf *.bin *.dis
将程序下载到内存运行
按下key1,LED1点亮,再次按下key1,LED1熄灭
按下key2,LED2点亮,再次按下key2,LED2熄灭
当某个中断源产生中断时,CPU会自动的将VICxVECTADDRy(x=0,1,2,3,y=0-31)寄存器的值赋给VICxADDRESS(x=0,1,2,3),因此我们可以把我们的中断处理函数的地址赋给VICxVECTADDRy寄存器,
比如我们有个函数
void key_handle()
{
……
}
我们把key_handle 函数的值赋给VIC0VECTADDR0(外部中断0)
VIC0VECTADDR0 =key_handle;
当外部中断0触发中断时,CPU会自动的将VIC0VECTADDR0的值赋给VIC0ADDRESS,并跳转到这个地址去执行,即执行函数key_handle。
代码如下:
start.S
[cpp] view plaincopy
01..global _start
02..global key_isr
03._start:
04.
05. ldr sp, =0x40000000
06.
07.
08. mrs r0, cpsr
09. bic r0, r0, #0x00000080
10. msr cpsr, r0
11.
12. bl main
13.
14.halt:
15. b halt
16.
17.key_isr:
18.
20. sub lr, lr, #4
21. stmfd sp!, {r0-r12, lr}
22. bl key_handle
23.
24. ldmfd sp!, {r0-r12, pc}^
key.c
[cpp] view plaincopy
01.#define GPC0CON *((volatile unsigned int *)0xE0200060)
02.#define GPC0DAT *((volatile unsigned int *)0xE0200064)
03.
04.#define GPH0CON *((volatile unsigned int *)0xE0200C00)
05.#define GPH0DAT *((volatile unsigned int *)0xE0200C04)
06.
07.#define EXT_INT_0_CON *((volatile unsigned int *)0xE0200E00)
08.#define EXT_INT_0_MASK *((volatile unsigned int *)0xE0200F00)
09.
10.#define VIC0INTSELECT *((volatile unsigned int *)0xF200000C)
11.#define VIC0INTENABLE *((volatile unsigned int *)0xF2000010)
12.
13.#define VIC0VECTADDR0 *((volatile unsigned int *)0xF2000100)
14.#define VIC0VECTADDR1 *((volatile unsigned int *)0xF2000104)
15.
16.#define VIC0ADDRESS *((volatile unsigned int *)0xF2000F00)
17.
18.#define EXT_INT_0_PEND *((volatile unsigned int *)0xE0200F40)
19.
20.extern void key_isr(void);
21.
22.void key_handle()
23.{
24. volatile unsigned char key_code = EXT_INT_0_PEND & 0x3;
25.
26. VIC0ADDRESS = 0;
27. EXT_INT_0_PEND |= 3;
28.
29. if (key_code == 1)
30. GPC0DAT ^= 1 << 3;
31. else if (key_code == 2)
32. GPC0DAT ^= 1 << 4;
33.}
34.
35.int main()
36.{
37. GPC0CON &= ~(0xFF << 12);
38. GPC0CON |= 0x11 << 12;
39. GPH0CON |= 0xFF << 0;
40.
41. EXT_INT_0_CON &= ~(0xFF << 0);
42. EXT_INT_0_CON |= 2 | (2 << 4);
43. EXT_INT_0_MASK &= ~3;
44.
45. VIC0INTSELECT &= ~3;
46.
47. VIC0INTENABLE |= 3;
48.
49. VIC0VECTADDR0 = (int)key_isr;
51. VIC0VECTADDR1 = (int)key_isr;
52.
53. while (1);
54.
55. return 0;
56.}
Makefile
[cpp] view plaincopy
01.key.bin: start.o key.o
02. arm-linux-ld -Ttext 0x20000000 -o key.elf $^
03. arm-linux-objcopy -O binary key.elf $@
04. arm-linux-objdump -D key.elf > key.dis
05.
06.key.o : key.c
07. arm-linux-gcc -c $< -o $@
08.start.o : start.S
09. arm-linux-gcc -c $< -o $@
10.
11.clean:
12. rm *.o *.elf *.bin *.dis
将程序下载到内存运行
按下key1,LED1点亮,再次按下key1,LED1熄灭
按下key2,LED2点亮,再次按下key2,LED2熄灭