commit 02dd374f233fbb363b36ac6cde42183127d367a1
parent 2d54d6fd5e90c0006b3a20f0e8cf67f97c771348
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sat, 24 Feb 2024 15:14:02 +0900
try to use timer. wip
Diffstat:
M | ex3/main.s | | | 73 | +++++++++++++++++++++++++++++++++++++++++++++---------------------------- |
1 file changed, 45 insertions(+), 28 deletions(-)
diff --git a/ex3/main.s b/ex3/main.s
@@ -3,8 +3,8 @@
.section .text
reset:
- // unreset gpio, pll_sys, uart0
- ldr r0, =(1 << 22 | 1 << 12 | 1 << 5) // uart0 | pll_sys | io_bank0
+ // unreset gpio, pll_sys, timer, uart0
+ ldr r0, =(1 << 22 | 1 << 21 | 1 << 12 | 1 << 5) // uart0 | timer | pll_sys | io_bank0
ldr r3, resets_base
ldr r1, atomic_clr
str r0, [r3, r1] // RESETS: RESET
@@ -56,11 +56,6 @@ wait_vco:
// setup clock
ldr r3, clocks_base
- // set clk_ref to xosc
- mov r0, #2
- ldr r1, atomic_set
- add r1, r1, #0x30
- str r0, [r3, r1] // CLOCKS: CLK_REF_CTRL
// set system clock clksrc_pll_sys
ldr r0, =(0x0 << 5 | 0x1)
str r0, [r3, #0x3c] // CLOCKS: CLK_SYS_CTRL
@@ -86,32 +81,29 @@ wait_vco:
ldr r0, =(3 << 5 | 1 << 4) // WLEN = 8, FEN = 1
str r0, [r3, #0x2c] // UART: UARTLCR_H
- // set systick timer
+ // enable interrupt
ldr r3, ppb_base
- // clear count
- ldr r1, =0xe018
- str r0, [r3, r1] // M0PLUS: SYST_CVR
- // set reset value
- ldr r0, =0xf23f // 1 sec
- ldr r1, =0xe014
- str r0, [r3, r1] // M0PLUS: SYST_RVR
- // enable systick timer
- sub r1, r1, #4
- ldr r0, =(1 << 1 | 1) // TICKINT | ENABLE
- str r0, [r3, r1] // M0PLUS: SYST_CSR
-
- // setup NMI
- ldr r3, syscfg_base
+ // enable timer_irq_0
+ ldr r1, =0xe100
mov r0, #1
- lsl r0, #14
- str r0, [r3, #0] // SYSCFG: PROC0_NMI_MASK
+ str r0, [r3, r1] // M0PLUS: NVIC_ISER
+
+ // setup timer
+ ldr r3, timer_base
+ // enable alarm_0 interrupt
+ mov r0, #1 // ALARM_0
+ str r0, [r3, #0x38] // TIMER: INTE
+ // set timer
+ ldr r0, =0x20000 //
+ bl set_alarm
- ldr r1, =0x20000000
- mov r0, #0
- str r0, [r1, #0]
loop:
- wfi
+ //ldr r0, =0xdeadbeef
+ //bl printh
svc #0
+ wfi
+ ldr r0, =0xcafecafe
+ bl printh
b loop
// functions
@@ -149,6 +141,28 @@ int_systick:
bl putbyte
pop {pc}
+int_alarm:
+ push {lr}
+ // clear interrupt
+ ldr r3, timer_base
+ ldr r2, atomic_clr
+ mov r1, #0x34
+ add r1, r1, r2
+ mov r0, #1
+ str r0, [r3, r2] // TIMER: INTR
+ // reset timer
+ ldr r0, =0x20000 // 1 sec
+ bl set_alarm
+ pop {pc}
+
+ // set_alarm sets alarm_0 to fire after r0 us.
+set_alarm:
+ ldr r3, timer_base
+ ldr r1, [r3, #0x28] // TIMER: TIMERAWL
+ add r0, r1
+ str r0, [r3, #0x10] // TIMER: ALARM0
+ bx lr
+
// print r0 in hex for debugging.
printh:
push {r4, r5, r6, r7, lr}
@@ -276,6 +290,8 @@ pll_sys_base:
.word 0x40028000
uart0_base:
.word 0x40034000
+timer_base:
+ .word 0x40054000
sio_base:
.word 0xd0000000
ppb_base:
@@ -300,3 +316,4 @@ vectors:
.word (reset+1) // 13
.word (reset+1) // 14
.word (int_systick+1) // 15 systick
+ .word (int_alarm+1) // 16 alarm_0