-
Notifications
You must be signed in to change notification settings - Fork 0
/
led.s
113 lines (96 loc) · 1.83 KB
/
led.s
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
.equ gpio_ctrl, 0xf2200000
.section .text
.globl led_mode_write
.globl led_on
.globl led_off
.globl led_status
.globl led_pattern
led_mode_read:
ldr r0, =gpio_ctrl
mov r1, #0
str r1, [r0, #0x04]
bx lr
led_mode_write:
ldr r0, =gpio_ctrl
mov r1, #1
lsl r1, #18
str r1, [r0, #0x04]
bx lr
led_on:
ldr r0, =gpio_ctrl
mov r1, #1
lsl r1, #16
str r1, [r0, #0x28]
bx lr
led_off:
ldr r0, =gpio_ctrl
mov r1, #1
lsl r1, #16
str r1, [r0, #0x1c]
bx lr
led_status:
ldr r1, =gpio_ctrl
ldr r0, [r1, #0x34]
cmp r0, #0
moveq r0, #1
movne r0, #0
bx lr
/* Make the led blink in a specified pattern
* r0: bit pattern, 0 = off and 1 = on
* r1: number of bits in the pattern
* r2: delay between each bit
* r3: number of times the pattern must repeat, or 0 if it should repeat forever
*/
led_pattern:
push {r4-r11, lr}
mov r4, r0
mov r5, r1
mov r6, r2
mov r7, r3
// Limit r5 to 32
cmp r5, #32
movhi r5, #32
// Get the current led status
bl led_mode_read
bl led_status
mov r8, r0
bl led_mode_write
led_pattern$loop:
mov r10, #1 // bitmask
mov r11, r5 // iterator
led_pattern$nextbit:
ands r9, r4, r10
beq led_pattern$off
led_pattern$on:
cmp r8, #0
bleq led_on
b led_pattern$endbit
led_pattern$off:
cmp r8, #0
blne led_off
led_pattern$endbit:
mov r8, r9
subs r11, r11, #1
beq led_pattern$endloop
mov r0, r6
bl _wait
lsl r10, #1
b led_pattern$nextbit
led_pattern$endloop:
cmp r7, #1
beq led_pattern$end
cmp r7, #0
subne r7, r7, #1
mov r0, r6
bl _wait
b led_pattern$loop
led_pattern$end:
pop {r4-r11, pc}
/* Waste some time
* r0: number of iterations
*/
_wait:
cmp r0, #0
bxeq lr
sub r0, r0, #1
b _wait