-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.asm
87 lines (72 loc) · 1.4 KB
/
system.asm
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
macro SET_GPIO gpio, value {
mov r0, gpio
mov r1, value
bl set_gpio
}
macro RED_LED_ON {
SET_GPIO LED_RED, #1
}
macro RED_LED_OFF {
SET_GPIO LED_RED, #0
}
macro GREEN_LED_ON {
SET_GPIO LED_GREEN, #1
}
macro GREEN_LED_OFF {
SET_GPIO LED_GREEN, #0
}
macro WAIT time {
m32 r0, time
bl wait
}
macro ERR RED, GREEN {
m32 r0, RED
m32 r1, GREEN
bl error_state
}
; in: r0 = red blinks
; r1 = green blinks
; never returns
error_state:
push {r4, r5, r6, r7}
mov r4, r0
mov r5, r1
err_loop_outer$:
GREEN_LED_OFF
FOR err_loop_red, r6, r4
RED_LED_ON
WAIT $40000
RED_LED_OFF
WAIT $40000
FOR_END err_loop_red, r6
WAIT $80000
RED_LED_OFF
FOR err_loop_green, r7, r5
GREEN_LED_ON
WAIT $40000
GREEN_LED_OFF
WAIT $40000
FOR_END err_loop_green, r7
WAIT $80000
b err_loop_outer$
; in {time to wait in microseconds}
; out {}
wait:
; r0 time to wait
; r1 time left
; r2 start timer
; r3 timer memory location
; r4 current time (small bits)
; r5 current time (big bits)
; TODO: Add Timer offset($3000) to rpi.inc
m32 r3, PERIPHERAL_BASE + $3000
push {r4, r5}
ldrd r4,r5, [r3, #4]
mov r2, r4
wait_loop$:
ldrd r4,r5, [r3, #4]
sub r1, r4,r2
cmp r1, r0
bls wait_loop$
pop {r4, r5}
mov pc, lr