掌機 - TRIMUI - Assembly - INTC



參考資料:
http://nano.lichee.pro/
https://mangopi.org/mangopi_r

F1C200S分成FIQ、IRQ兩種中斷,EXT_INT是FIQ中斷,其餘都是IRQ中斷,比較特別的地方是可以透過設定INT_FORCE(INTC_FF_REG),強制觸發IRQ中斷


暫存器


Number代表第幾個bit,如:UART2是3,因此,要Enable UART2中斷的話,則需要設定bit-3(INTC_EN_REG0|= (1 << 3)),Vector代表中斷觸發的來源,也就是儲存在INTC_VECTOR_REG的數值,如:UART2是0x000c,因此,UART2中斷觸發後,INTC_VECTOR_REG內容就是0x000c


main.s

    .global _start

    .equiv GPIO_BASE,  0x01c20800 
    .equiv INTC_BASE,  0x01c20400

    .equiv PE,         (0x24 * 4)
    .equiv PORT_CFG0,  0x00
    .equiv PORT_DATA,  0x10

    .equiv INTC_BASE_ADDR_REG, 0x04
    .equiv INTC_PEND_REG0,     0x10
    .equiv INTC_PEND_REG1,     0x14
    .equiv INTC_EN_REG0,       0x20
    .equiv INTC_EN_REG1,       0x24
    .equiv INTC_MASK_REG0,     0x30
    .equiv INTC_MASK_REG1,     0x34
    .equiv INTC_RESP_REG0,     0x40
    .equiv INTC_RESP_REG1,     0x44
    .equiv INTC_FF_REG0,       0x50
    .equiv INTC_FF_REG1,       0x54

    .arm
    .text
_start:
    .long 0xea000016
    .byte 'e', 'G', 'O', 'N', '.', 'B', 'T', '0'
    .long 0, __spl_size
    .byte 'S', 'P', 'L', 2
    .long 0, 0
    .long 0, 0, 0, 0, 0, 0, 0, 0
    .long 0, 0, 0, 0, 0, 0, 0, 0
  
_vector:
    b reset
    b .
    b .
    b .
    b .
    b .
    ldr pc, _irq
    b .

_irq: .word irq_handler

irq_handler:
    ldr r0, =GPIO_BASE
    ldr r1, =0x00
    str r1, [r0, #(PE + PORT_DATA)]

    ldr r0, =INTC_BASE
    ldr r1, =0x00000000
    str r1, [r0, #INTC_FF_REG0]
    ldr r1, =0xffffffff
    str r1, [r0, #INTC_PEND_REG0]
    subs pc, lr, #4

reset:
    mrc p15, 0, r0, c1, c0, 0
    bic r0, #(1 << 13)
    mcr p15, 0, r0, c1, c0, 0

    adr r0, _vector
    mrc p15, 0, r2, c1, c0, 0
    ands r2, r2, #(1 << 13)
    ldreq r1, =0x00000000
    ldrne r1, =0xffff0000
    ldmia r0!, {r2-r8, r10}
    stmia r1!, {r2-r8, r10}
    ldmia r0!, {r2-r8, r10}
    stmia r1!, {r2-r8, r10}

    mrs r0, cpsr
    bic r0, #0x80
    msr cpsr_c, r0

    ldr r0, =INTC_BASE
    ldr r1, =(1 << 3)
    str r1, [r0, #INTC_EN_REG0]
    ldr r1, =0x00000000
    str r1, [r0, #INTC_MASK_REG0]

    ldr r0, =GPIO_BASE
    ldr r1, =0x100000
    str r1, [r0, #(PE + PORT_CFG0)]
    ldr r1, =0x20
    str r1, [r0, #(PE + PORT_DATA)]

0:
    ldr r0, =GPIO_BASE
    ldr r1, =0x20
    str r1, [r0, #(PE + PORT_DATA)] 
    ldr r0, =500000
1:
    subs r0, #1
    bne 1b

    ldr r0, =INTC_BASE
    ldr r1, =(1 << 3)
    str r1, [r0, #INTC_FF_REG0]
    ldr r0, =500000
1:
    subs r0, #1
    bne 1b

    b 0b
    .end

完成