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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
.macro digiline_send channel msg
la a0,(\channel)
la a1,(\msg)
li a7,129
ecall
.endm
.macro set_timeri time
li t0,0x80
csrs mie,t0 # unmask timer interrupt
ld t1,2(gp) # read mtime
li t0,(\time)
add t1,t1,t0 # calculate target value (lower half)
sltu t0,t1,t0 # check if it overflowed
add t2,t2,t0 # add the overflow into the high half if there was any
sd t1,10(gp) # set mtimecmp to the target value
.endm
.macro stop_timer
li t1,0xffffffff
li t2,0xffffffff
sd t1,10(gp) # set mtime to far in the future
li t1,0x80
csrc mie,t1 # mask timer interrupt
.endm
.macro set_timer_to label
cm.push {ra},-16
la a0,(\label)
lbu a0,0(a0)
call set_timer
cm.pop {ra},16
.endm
set_timer:
li t0,0x80
csrs mie,t0 # unmask timer interrupt
ld t1,2(gp) # read mtime
add t1,t1,a0 # calculate target value (lower half)
sltu t0,t1,a0 # check if it overflowed
add t2,t2,t0 # add the overflow into the high half if there was any
sd t1,10(gp) # set mtimecmp to the target value
ret
|