summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2019-08-24 16:40:43 +0200
committerSilvan Jegen <s.jegen@gmail.com>2019-08-24 16:40:43 +0200
commitc3afc9768d110c4dbaa2f0133a3a77167f1f2293 (patch)
tree34fee88e9b92d55870e56fcd3b0bbe7ac9849fac
parent6502be88d94aa1d5e3949832c12f47deb8329a4c (diff)
delay: load/write high and low value
I don't think this should make a difference in practice.
-rw-r--r--software/first/delay.S16
1 files changed, 9 insertions, 7 deletions
diff --git a/software/first/delay.S b/software/first/delay.S
index 656625f..039d924 100644
--- a/software/first/delay.S
+++ b/software/first/delay.S
@@ -4,20 +4,22 @@
.include "memory_map.inc"
-# a0 is delay in milliseconds argument
+# a0 is delay-in-milliseconds argument
delay:
addi sp, sp, -16 # Allocate stack frame
sw ra, 12(sp) # save return address to the stack
li t0, MTIME # load the timer register
- lw t1, 0(t0) # load value of the timer
+ lw t1, 0(t0) # load low value of the timer
+ lw t2, 4(t0) # load high value of the timer
- li t2, MTIME_FREQUENCY # get clock freq (approx.)
- mul t2, t2, a0 # multiply milliseconds with freq
- add t2, t1, t2 # target mtime is now in t2
- li t3, MTIMECMP # load address of MTIMECMP register
- sw t2, 0(t3) # store target time to MTIMECMP register. This only stores 32 bits so I am not sure if that is correct...
+ li t3, MTIME_FREQUENCY # get clock freq (approx.)
+ mul t3, t3, a0 # multiply milliseconds with freq
+ add t4, t1, t3 # target mtime is now in t4
+ li t0, MTIMECMP # load address of MTIMECMP register
+ sw t2, 4(t0) # set higher 32bits of MTIMECMP
+ sw t4, 0(t0) # store target time to MTIMECMP register. This only stores 32 bits so I am not sure if that is correct...
lw ra, 12(sp) # load return address
addi sp, sp, 16 # deallocate stack frame