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

📄 irq.s

📁 蜂鸣器实验beepmusic(arm7平台)
💻 S
字号:
;/*******************************************************************************************************
;** File Name: IRQ.s
;** Descriptions: The irq handle that what allow the interrupt nesting. 
;********************************************************************************************************/


NoInt       EQU 0x80                       ;Bit7,I位

USR32Mode   EQU 0x10                       ;M[4:0]=10000,用户模式
SVC32Mode   EQU 0x13                       ;M[4:0]=10011,管理模式
SYS32Mode   EQU 0x1f                       ;M[4:0]=1ffff,系统模式
IRQ32Mode   EQU 0x12                       ;M[4:0]=10010,IRQ中断模式
FIQ32Mode   EQU 0x11                       ;M[4:0]=10001,快速中断模式

    CODE32

    AREA    IRQ,CODE,READONLY
    
;中断服务程序与C语言的接口的宏定义

    MACRO
$IRQ_Label HANDLER $IRQ_Exception_Function

        EXPORT  $IRQ_Label                      ; 输出的标号
        IMPORT  $IRQ_Exception_Function         ; 引用的外部标号

$IRQ_Label
        SUB     LR, LR, #4                      ; 计算返回地址
        STMFD   SP!, {R0-R3, R12, LR}           ; 保存任务环境
        MRS     R3, SPSR                        ; 保存状态
        STMFD   SP, {R3,LR}^                    ; Protects SPSR and SP in user status, Notice: DO NOT write back.保存SPSR和用户状态的SP,注意不能回写
                                                ; If the SP is written back, it should be adjusted to its appropriate value later.如果回写的是用户的SP,则后面要调整SP
        NOP
        SUB     SP, SP, #4*2

        MSR     CPSR_c, #(NoInt | SYS32Mode)    ; Switch to the System Mode 切换到系统模式 
       
        BL      $IRQ_Exception_Function         ; call the C interrupt handler funtion 调用c语言的中断处理程序

;MSR写状态寄存器指令使得CPSR[7:0]=0b10010010
;作用为关IRQ中断
        MSR     CPSR_c, #(NoInt | IRQ32Mode)    ; Switch bak to IRQ mode 切换回irq模式
        LDMFD   SP, {R3,LR}^                    ; Recover SPSR and SP in user status, Notic: DO NOT write back. 恢复SPSR和用户状态的SP,注意不能回写
                                                ; If the SP is written back, it should be adjusted to its appropriate value later.如果回写的是用户的SP,所以后面要调整SP
        MSR     SPSR_cxsf, R3
        ADD     SP, SP, #4*2                    ; 

        LDMFD   SP!, {R0-R3, R12, PC}^          ;
    MEND

;/* 以下添加中断句柄,用户根据实际情况改变 */
;/* Add interrupt handler here,user could change it as needed */
;定时器0中断(HANDLER宏调用)

;Timer0_Handler  HANDLER Timer0

    END
;/*********************************************************************************************************
;**                            End Of File
;********************************************************************************************************/

⌨️ 快捷键说明

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