S3C2440 按键中断方式汇编代码

SRCPND EQU 0X4A000000
INTMSK EQU 0X4A000008
INTPND EQU 0X4A000010
EINTMASK EQU 0X560000A4
EINTPEND EQU 0X560000A8
EXTINT1 EQU 0X5600008C
EXTINT2 EQU 0X56000090
INTMOD EQU 0X4A000004


AREA INT_KEY,CODE,READONLY
ENTRY
CODE32
ResetEntry
b   Reset
; //0x04: 未定义指令中止模式的向量地址
HandleUndef
     b   HandleUndef
; //0x08: 管理模式的向量地址,通过SWI指令进入此模式
HandleSWI
     b   HandleSWI
; //0x0c: 指令预取终止导致的异常的向量地址
HandlePrefetchAbort
     b   HandlePrefetchAbort
; //0x10: 数据访问终止导致的异常的向量地址
HandleDataAbort
     b   HandleDataAbort
; //0x14: 保留
HandleNotUsed
     b   HandleNotUsed
; //0x18: 中断模式的向量地址
     b   HandleIRQ
; //0x1c: 快中断模式的向量地址
HandleFIQ
     b   HandleFIQ
Reset
BL Disable_Watch_Dog
msr cpsr_c, #0xd2       ;// 进入中断模式
   ldr sp, =3072 ;// 设置中断模式栈指针


     msr cpsr_c, #0xdf       ;// 进入系统模式
              ;// 设置系统模式栈指针,
                             ;// 其实复位之后,CPU就处于系统模式,
                            
     msr cpsr_c, #0x5f       ;// 设置I-bit=0,开IRQ中断
   
BL Main
halt_loop
B halt_loop
Disable_Watch_Dog ;//关闭看门狗,否则一直重启
LDR R0,=0x53000000
MOV R1,#0x0
STR R1,[R0]
MOV PC, lr ;//返回
Main
BL LED_Init
BL KEY_Init
BL INT_Init

B MAIN_LOOP
MOV PC,LR
MAIN_LOOP
B MAIN_LOOP
LED_Init
LDR R0,=0x56000010
   MOV R1,#0x00015400
   STR R1,[R0]
  
   LDR R0,=0x56000014
   MOV R1,#0x000001E0
   STR R1,[R0]
  
MOV PC,LR
KEY_Init
LDR R0,=0x56000060
     LDR R1,=0x80A882 ;//设置GPG0为扩展功能
     STR R1,[R0]
MOV PC,LR
INT_Init
MOV       r1,#0x20
LDR       r0,=SRCPND
STR       r1,[r0]
LDR R1,=INTMSK
         LDR R0,=0XFFC0
         STR R0,[R1]
         LDR R1,=EXTINT1
         LDR R0,=0X22202002
         STR R0,[R1]
         LDR R1,=EXTINT2
         LDR R0,=0X2000
         STR R0,[R1]
         LDR R1,=EINTMASK;//111101110001011011111111
         LDR R0,=0XF716FF
         STR R0,[R1]
         LDR R1,=INTMOD
         LDR R0,=0X0
         STR R0,[R1]
MOV PC,LR
HandleIRQ
         SUB LR,LR,#4                        ;//计算返回地址
         STMDB SP!,{R0-R12,LR}       ;//保存使用到的寄存器,此时的sp是中断模式的sp,压栈
 
         LDR LR,=INT_RETURN          ;//ISR返回的地址
         LDR PC,=EINT_HANDLE       ;//调用中断服务函数
INT_RETURN
         LDMIA SP!,{R0-R12,PC}^     ;//中断返回,^表示将spsr的值复制到cpsr,出栈
EINT_HANDLE
NOP
LOOP
         LDR R1,=EINTPEND
         LDR R2,[R1]
        
         LDR R3,=0XFFFFF;//清中断
         STR R3,[R1]
        
         LDR R1,=SRCPND        
         LDR R3,=0X3F
         STR R3,[R1]
        
         LDR R1,=INTPND
         LDR R3,=0X3F
         STR R3,[R1]
SWITCH
         LDR R0,=0x56000014
CASE_8
       TST R2,#0X100
         BEQ CASE_11
         LDR R1,=0X1C0
         STR R1,[R0]
         B SWITCH_END
CASE_11
         TST R2,#0X800
         BEQ CASE_13
         LDR R1,=0X1A0
         STR R1,[R0]
         B SWITCH_END
CASE_13
         TST R2,#0X2000
           BEQ CASE_14
         LDR R1,=0X160
         STR R1,[R0]
         B SWITCH_END
CASE_14
         TST R2,#0X4000
         BEQ CASE_15
         LDR R1,=0X0E0
       STR R1,[R0]
       B SWITCH_END
CASE_15
         TST R2,#0X8000
         BEQ CASE_19
         LDR R1,=0X000
       STR R1,[R0]
         B SWITCH_END
CASE_19
         TST R2,#0X80000
         BEQ DEFAULT
         LDR R1,=0X1E0
         STR R1,[R0]
B SWITCH_END
DEFAULT
             LDR R1,=0X1E0
           STR R1,[R0]
SWITCH_END
           NOP 
         MOV PC,LR
  END

linux

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwzgpj.html