微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > ARM汇编外部中断

ARM汇编外部中断

时间:11-20 来源:互联网 点击:
主要是中断向量表的设置和现场保护。

调试比较久的原因:使用main: b main时调试发现,不能死循环,可能是main标签是保留的

1)在主程序中的步骤一般是:

1.关中断,并设置各主要模式的堆栈指针和容量

2写1清SRCPND,INTPND寄存器

3.配置INTMSK使能相应中断

4.开全局中断

3)中断服务程序中的流程是:

1.屏蔽中断(硬件自动关irq中断)

2.执行任务

3.写1清相应SRPND,INTPND等寄存器(可以利用SRPND=SRPND,INTPND来清零,防止出错)

4.把屏蔽的中断使能回来

5.返回

参考u-boot的start.S自己写了一个外部中断程序,mini2440的按键K1,按一下LED灭,再按一下LED亮......。硬件原理图:按键引脚对应GPIO是PG0,对应EINT8,而LED的引脚是PB8,被设计为低电平时灯亮。

.equ    NOINT,      0xc0  .equ    DISABLE_IRQ,0x80.equ    SYS_MOD,    0x1f.equ    IRQ_MOD,    0x12.equ	USR_MOD,    0x10.equ    WTCON,    0x53000000.equ    GPBCON,   0x56000010.equ    GPBDAT,   0x56000014.equ    GPBUP,    0x56000018.equ    GPGCON,   0x56000060.equ    EINTMASK, 0x560000a4  .equ    EXTINT1,  0x5600008c .equ    EINTPEND, 0x560000a8  .equ    INTMSK,   0x4A000008  .equ    SRCPND,   0X4A000000  .equ    INTPND,   0X4A000010  .equ    USE_Stack, 4096.equ    IRQ_Stack, 2048.text.code 32.global _start_start: b resetldr     pc, _undefined_instruction  ldr     pc, _software_interrupt  ldr 	pc, _prefetch_abort  ldr	pc, _data_abort  ldr 	pc, _not_used  ldr     pc, _irq ldr     pc, _fiq_undefined_instruction:     .word undefined_instruction  _software_interrupt:        .word software_interrupt  _prefetch_abort:            .word prefetch_abort  _data_abort:                .word data_abort  _not_used:                  .word not_used  _irq:                       .word irq  _fiq:                       .word fiq.balignl 16,0xdeadbeefreset:ldr r0,=WTCONmov r1,#0x0str r1,[r0] @关看门狗ldr r0,=GPBCONldr r1,=0x10000str r1,[r0] @PB8输出ldr r0,=GPBDATmov r1,#0x000str r1,[r0] @低电平msr cpsr_c,#(IRQ_MOD|NOINT)ldr sp,=IRQ_Stackmsr cpsr_c,#(SYS_MOD|NOINT)ldr sp,=USE_Stackldr r0,=GPGCONmov r1,#0x02str r1,[r0] @使能外部中断8ldr r0,=EXTINT1mov r1,#0x03str r1,[r0] @下降沿触发ldr r0, =EINTPEND ldr r1,=0x00fffff0str r1,[r0]@ 清EINTPEND,写1清零ldr r0,=EINTMASKldr r1,=0xfffffeffstr r1,[r0] @使能外部中断8,0为使能ldr r0, =SRCPND ldr r1,=0xffffffffstr r1,[r0]@ 清SRCPND,写1清零ldr r0, =INTPND ldr r1,=0xffffffff str r1,[r0]@ 清INTPND,写1清零ldr r0,=INTMSKldr r1,=0xffffffdfstr r1,[r0] @使能外部中断EINT8-23mrs r1, cpsr  bic r1, r1, #DISABLE_IRQmsr cpsr_c, r1 @开全局IRQ中断loop:	b loopirq_server:ldr r0, =EINTPENDldr r1,[r0]tst r1,#0x100 @判断是否为EINT8beq not_handle ldr r0,=GPBDATldr r1,[r0]tst r1,#0x100 @测试PB8当前是高电平还是低电平ldreq r1,=0x100movne r1,#0x0str r1,[r0]not_handle:ldr r0, =EINTPEND ldr r1,[r0] @ldr r1,=0x100str r1,[r0] @清EINTPENDldr r0, =SRCPND ldr r1,[r0] @ldr r1,=0x20str r1,[r0] @清SRCPNDldr r0, =INTPND ldr r1,[r0] @ldr r1,=0x20str r1,[r0] @清INTPNDmov pc,lrundefined_instruction:  nop  software_interrupt:  nop  prefetch_abort:   nop  data_abort:  nop  not_used:  nop  irq:  sub     lr,lr,#4  stmfd   sp!,{r0-r12,lr}  bl irq_server  ldmfd  sp!,{r0-r12,pc}^fiq:  nop

链接脚本命名为“int.lds”:
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") OUTPUT_ARCH(arm)ENTRY(_start)  SECTIONS{  . = 0x00000000;  .text : { *(.text)   }  .data ALIGN(4): {  *(.data)  }  .bss ALIGN(4): {  *(.bss)  }  }  

Makefile是:
led_off.bin : led_off.Sarm-linux-gcc -nostdlib -nostartfiles -g -c -o led_off.o led_off.Sarm-linux-ld -Tint.lds led_off.o -o led_off_elfarm-linux-objcopy -O binary -S led_off_elf led_off.binclean:rm -f  led_off.bin led_off_elf *.o

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

网站地图

Top