新聞中心

ARM匯編外部中斷

作者: 時(shí)間:2016-11-20 來源:網(wǎng)絡(luò) 收藏
主要是中斷向量表的設(shè)置和現(xiàn)場保護(hù)。

調(diào)試比較久的原因:使用main: b main時(shí)調(diào)試發(fā)現(xiàn),不能死循環(huán),可能是main標(biāo)簽是保留的

本文引用地址:http://m.butianyuan.cn/article/201611/318691.htm

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

1.關(guān)中斷,并設(shè)置各主要模式的堆棧指針和容量

2寫1清SRCPND,INTPND寄存器

3.配置INTMSK使能相應(yīng)中斷

4.開全局中斷

3)中斷服務(wù)程序中的流程是:

1.屏蔽中斷(硬件自動(dòng)關(guān)irq中斷)

2.執(zhí)行任務(wù)

3.寫1清相應(yīng)SRPND,INTPND等寄存器(可以利用SRPND=SRPND,INTPND來清零,防止出錯(cuò))

4.把屏蔽的中斷使能回來

5.返回

參考u-boot的start.S自己寫了一個(gè)外部中斷程序,mini2440的按鍵K1,按一下LED滅,再按一下LED亮......。硬件原理圖:按鍵引腳對應(yīng)GPIO是PG0,對應(yīng)EINT8,而LED的引腳是PB8,被設(shè)計(jì)為低電平時(shí)燈亮。

.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] @關(guān)看門狗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] @下降沿觸發(fā)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中斷l(xiāng)oop:	b loopirq_server:ldr r0, =EINTPENDldr r1,[r0]tst r1,#0x100 @判斷是否為EINT8beq not_handle ldr r0,=GPBDATldr r1,[r0]tst r1,#0x100 @測試PB8當(dāng)前是高電平還是低電平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


關(guān)鍵詞: ARM匯編外部中

評論


技術(shù)專區(qū)

關(guān)閉