掌機 - TRIMUI - Assembly - Watchdog



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

Work Flow


暫存器


main.s

    .global _start

    .equiv GPIO_BASE,  0x01c20800 
    .equiv TIMER_BASE, 0x01c20c00

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

    .equiv WDOG_IRQ_EN_REG,  0xa0
    .equiv WDOG_IRQ_STA_REG, 0xa4
    .equiv WDOG_CTRL_REG,    0xb0
    .equiv WDOG_CFG_REG,     0xb4
    .equiv WDOG_MODE_REG,    0xb8

    .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 .
    b .
    b .
 
reset:
    ldr r0, =GPIO_BASE
    ldr r1, =0x100000
    str r1, [r0, #(PE + PORT_CFG0)]
    ldr r1, =0x20
    str r1, [r0, #(PE + PORT_DATA)]

    ldr r0, =TIMER_BASE
    ldr r1, =(0xa57 << 1) | 1
    str r1, [r0, #WDOG_CTRL_REG]
    ldr r1, =1
    str r1, [r0, #WDOG_CFG_REG]
    ldr r1, =(1 << 4) | 1
    str r1, [r0, #WDOG_MODE_REG]
0:
    nop
    b 0b
    .end

P.S. 熄滅LED後,等待Watchdog(1秒)去重啟系統,不過由於程式是從RAM執行,因此,Reset後,不會有後續動作(LED亮)

完成