參考資料:
http://nano.lichee.pro/
https://mangopi.org/mangopi_r
Work Flow
暫存器
中斷
Timer2時間
Ticks = LOSC / (TMR2_CLK_PRES * TMR2_INTV_VALUE_REG) = 32KHz / (128 * 256) = 1Hz
main.s
.global _start .equiv GPIO_BASE, 0x01c20800 .equiv TIMER_BASE, 0x01c20c00 .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 .equiv TMR_IRQ_EN_REG, 0x00 .equiv TMR_IRQ_STA_REG, 0x04 .equiv TMR2_CTRL_REG, 0x30 .equiv TMR2_INTV_VALUE_REG, 0x34 .equiv TMR2_CUR_VALUE_REG, 0x38 .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)] 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 << 15) str r1, [r0, #INTC_EN_REG0] ldr r1, =~(1 << 15) 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)] ldr r0, =TIMER_BASE ldr r1, =0x5000000 str r1, [r0, #TMR2_INTV_VALUE_REG] ldr r1, =(7 << 4) | (1 << 2) | (1 << 1) | 1 str r1, [r0, #TMR2_CTRL_REG] ldr r1, =4 str r1, [r0, #TMR_IRQ_EN_REG] str r1, [r0, #TMR_IRQ_STA_REG] b . .end
完成