-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtimer.s
More file actions
28 lines (25 loc) · 712 Bytes
/
timer.s
File metadata and controls
28 lines (25 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#
# Example demonstrating how to handle interupts generated by "Timer Tool" of RARS.
#
.eqv CUR 0xFFFF0018 # current time
.eqv NEW 0xFFFF0020 # time for new interrupt
.macro timer(%timeout)
lw t0, CUR
addi t0, t0, %timeout
sw t0, NEW, t1
.end_macro
.text
j main
handler:
timer 2000 # generate new timer interrupt after 2000 ms.
uret # return to uepc
main:
la t0, handler
csrrw zero, utvec, t0 # set utvec to the handlers address
csrrsi zero, ustatus, 0x1 # set interrupt enable bit in ustatus
csrrsi zero, uie, 0x10 # timer interrupts are enabled (UTIE bit)
timer 2000 # generate new timer interupt after 2000 ms.
loop:
wfi
j loop
nop