⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 irq_arm.mac

📁 ARM入门的好帮手.包含了从简单到相对较复杂的程序.
💻 MAC
字号:
;------------------------------------------------------------------------------
;-    ATMEL Microcontroller Software Support  -   ROUSSET -
;------------------------------------------------------------------------------
; The software is delivered "AS IS" without warranty or condition of any
; kind, either express, implied or statutory. This includes without
; limitation any warranty or condition with respect to merchantability or
; fitness for any particular purpose, or against the infringements of
; intellectual property rights of others.
;------------------------------------------------------------------------------
;- File source          : irq_arm.mac
;- Object               : Entry and Exit Macro for IRQ and FIQ.
;-
;- 1.0 13/Feb/03 JPP    : New clean 
;------------------------------------------------------------------------------

;------------------------------------------------------------------------------
;- LISR vector handler for system peripherals
;--------------------------------------------
;- These macro save the context, call the LISR dispatch routine, and restore
;- the context
;------------------------------------------------------------------------------

;--------------------------------
;- ARM Core Mode and Status Bits
;--------------------------------

ARM_MODE_USER           EQU     0x10
ARM_MODE_FIQ            EQU     0x11
ARM_MODE_IRQ            EQU     0x12
ARM_MODE_SVC            EQU     0x13
ARM_MODE_ABORT          EQU     0x17
ARM_MODE_UNDEF          EQU     0x1B
ARM_MODE_SYS            EQU     0x1F

I_BIT                   EQU     0x80
F_BIT                   EQU     0x40
T_BIT                   EQU     0x20


;- IRQ Entry
;- Register initialization
;-      Banked Registers        ; Irq_register
;-      SPSR need to be saved for nested interrupt
;-      R13_irq <- Irq Stack register
;-      R14_irq <- Irq link register
;-      Outpout in ARM_MODE_SVC
;-----------
            MACRO
            IRQ_ENTRY

;- Adjust and save LR_irq in IRQ stack
            sub         lr, lr, #4
            stmfd       sp!, {lr}

;- Write in the IVR to support Protect Mode
;- No effect in Normal Mode
;- De-assert the NIRQ and clear the source in Protect Mode
            ldr         r14, =AT91C_BASE_AIC
            str         r14, [r14, #AIC_IVR]

;- Save SPSR and r0 in IRQ stack
            mrs         r14, SPSR
            stmfd       sp!, {r14}

;- Enable Interrupt and Switch in Supervisor Mode
           msr         CPSR_c, #ARM_MODE_SVC

;- Save scratch/used registers and LR in User Stack
            stmfd       sp!, { r0-r3, r12, r14}

            MEND

;- IRQ Exit
;-----------
            MACRO
     	    IRQ_EXIT
;- Restore scratch/used registers and LR from User Stack
            ldmia       sp!, { r0-r3, r12, r14}

;- Disable Interrupt and switch back in IRQ mode
            msr         CPSR_c, #I_BIT :OR: ARM_MODE_IRQ

;- Mark the End of Interrupt on the AIC
            ldr         r14, =AT91C_BASE_AIC
            str         r14, [r14, #AIC_EOICR]

;- Restore SPSR_irq and r0 from IRQ stack
            ldmia       sp!, {r14}
            msr         SPSR_cxsf, r14

;- Restore adjusted  LR_irq from IRQ stack directly in the PC
            ldmia       sp!, {pc}^

            MEND

;-------------------
;- FIQ Entry Macro -
;-------------------
;- FIQ Entry with no nested (reentrant) interrupt allowed.
;- Register initialization
;-      Banked Registers        ; FIQ_register
;-      SPSR does not need to be save because we do not want nested FIQ
;-      R13_fiq <- Same as above. No need to save it.
;-      R14_irq <- link register
;------------------------------------------------------------------------

            MACRO
            FIQ_ENTRY

;- Switch in SYS/User Mode to allow User Stack access for C code and Disable FIQ and IRQ Interrupt for this mode
; because the FIQ is not yet acknowledged

            msr         CPSR_c, #I_BIT:OR:F_BIT:OR:ARM_MODE_SVC

;- Save scratch/used registers and LR in User Stack
            stmfd       sp!, { r0-r3, r12, lr}
            MEND

;------------
;- FIQ Exit -
;------------
            MACRO
            FIQ_EXIT

;- Restore scratch/used registers and LR from User Stack
            ldmia       sp!, { r0-r3, r12, lr}

;- Leave Interrupts disabled and switch back in FIQ mode
            msr         CPSR_c, #I_BIT :OR: F_BIT :OR: ARM_MODE_FIQ

;- Restore the Program Counter using the LR_fiq directly in the PC
            subs        pc,lr,#4
            
            MEND
            
	    
	END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -