Skip to content

Commit e49e516

Browse files
committed
Made use of the timer to control the time it blinks in microseconds
1 parent ebf3fe9 commit e49e516

File tree

6 files changed

+104
-29
lines changed

6 files changed

+104
-29
lines changed

kernel.img

44 Bytes
Binary file not shown.

kernel.list

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,32 @@ Disassembly of section .text:
5858
8098: e3a00010 mov r0, #16 ; 0x10
5959
809c: e3a01000 mov r1, #0 ; 0x0
6060
80a0: ebffffeb bl 8054 <SetGpio>
61-
80a4: e3a0283f mov r2, #4128768 ; 0x3f0000
61+
80a4: e3a00001 mov r0, #1 ; 0x1
62+
80a8: e1a00800 lsl r0, r0, #16
63+
80ac: eb000009 bl 80d8 <Wait>
64+
80b0: e3a00010 mov r0, #16 ; 0x10
65+
80b4: e3a01001 mov r1, #1 ; 0x1
66+
80b8: ebffffe5 bl 8054 <SetGpio>
67+
80bc: e3a00001 mov r0, #1 ; 0x1
68+
80c0: e1a00980 lsl r0, r0, #19
69+
80c4: eb000003 bl 80d8 <Wait>
70+
80c8: eafffff2 b 8098 <mainloop$>
6271

63-
000080a8 <wait1$>:
64-
80a8: e2422001 sub r2, r2, #1 ; 0x1
65-
80ac: e3520000 cmp r2, #0 ; 0x0
66-
80b0: 1afffffc bne 80a8 <wait1$>
67-
80b4: e3a00010 mov r0, #16 ; 0x10
68-
80b8: e3a01001 mov r1, #1 ; 0x1
69-
80bc: ebffffe4 bl 8054 <SetGpio>
70-
80c0: e3a0283f mov r2, #4128768 ; 0x3f0000
72+
000080cc <GetCounterValue>:
73+
80cc: e59f0028 ldr r0, [pc, #40] ; 80fc <waitLoop$+0x10>
74+
80d0: e1c000d4 ldrd r0, [r0, #4]
75+
80d4: e1a0f00e mov pc, lr
7176

72-
000080c4 <wait2$>:
73-
80c4: e2422001 sub r2, r2, #1 ; 0x1
74-
80c8: e3520000 cmp r2, #0 ; 0x0
75-
80cc: 1afffffc bne 80c4 <wait2$>
76-
80d0: eafffff0 b 8098 <mainloop$>
77+
000080d8 <Wait>:
78+
80d8: e92d4000 push {lr}
79+
80dc: e92d0001 push {r0}
80+
80e0: ebfffff9 bl 80cc <GetCounterValue>
81+
80e4: e8bd0002 pop {r1}
82+
80e8: e0802001 add r2, r0, r1
83+
84+
000080ec <waitLoop$>:
85+
80ec: ebfffff6 bl 80cc <GetCounterValue>
86+
80f0: e1500002 cmp r0, r2
87+
80f4: 9afffffc bls 80ec <waitLoop$>
88+
80f8: e8bd8000 pop {pc}
89+
80fc: 20003000 .word 0x20003000

kernel.map

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ Discarded input sections
2121
.janus_2cc_veneer
2222
0x00000000 0x0 build/main.o
2323
.v4_bx 0x00000000 0x0 build/main.o
24+
.data 0x00000000 0x0 build/timer.o
25+
.bss 0x00000000 0x0 build/timer.o
26+
.ARM.attributes
27+
0x00000000 0x0 build/timer.o
28+
.glue_7 0x00000000 0x0 build/timer.o
29+
.glue_7t 0x00000000 0x0 build/timer.o
30+
.vfp11_veneer 0x00000000 0x0 build/timer.o
31+
.janus_2cc_veneer
32+
0x00000000 0x0 build/timer.o
33+
.v4_bx 0x00000000 0x0 build/timer.o
2434

2535
Memory Configuration
2636

@@ -31,19 +41,23 @@ Linker script and memory map
3141

3242
LOAD build/gpio.o
3343
LOAD build/main.o
44+
LOAD build/timer.o
3445

3546
.init 0x00008000 0x4
3647
*(.init)
3748
.init 0x00008000 0x4 build/main.o
3849
0x00008000 _start
3950

40-
.text 0x00008004 0xd0
51+
.text 0x00008004 0xfc
4152
*(.text)
4253
.text 0x00008004 0x84 build/gpio.o
4354
0x0000800c SetGpioFunction
4455
0x00008004 GetGpioAddress
4556
0x00008054 SetGpio
46-
.text 0x00008088 0x4c build/main.o
57+
.text 0x00008088 0x44 build/main.o
58+
.text 0x000080cc 0x34 build/timer.o
59+
0x000080cc GetCounterValue
60+
0x000080d8 Wait
4761

4862
/DISCARD/
4963
*(*)

src/gpio.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
@ == r[1..3]
2727
GetGpioAddress:
2828
ldr r0, =GPIO_ADDR
29-
mov pc, lr
29+
mov pc, lr @ < Return
3030

3131
@
3232
@ Apply a GPIO function to a pin.

src/main.s

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ mainloop$:
3131
.unreq pinNum
3232
.unreq pinVal
3333

34-
@ Wait a few time
35-
mov r2,#0x3F0000
36-
wait1$:
37-
sub r2,#1
38-
cmp r2,#0
39-
bne wait1$
34+
@ Wait ~1/20 second
35+
nbUsec .req r0
36+
mov nbUsec, #1
37+
lsl nbUsec, #16
38+
bl Wait
39+
.unreq nbUsec
4040

4141
@ Turn on the pin to turn off the ACT LED
4242
pinNum .req r0
@@ -47,12 +47,12 @@ mainloop$:
4747
.unreq pinNum
4848
.unreq pinVal
4949

50-
@ Wait a few time
51-
mov r2,#0x3F0000
52-
wait2$:
53-
sub r2,#1
54-
cmp r2,#0
55-
bne wait2$
50+
@ Wait ~1/2 second
51+
nbUsec .req r0
52+
mov nbUsec, #1
53+
lsl nbUsec, #19
54+
bl Wait
55+
.unreq nbUsec
5656

5757
b mainloop$
5858

src/timer.s

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@ Distributed under the terms of the GNU General Public License v2
2+
.globl TIMER_ADDR
3+
.globl GetCounterValue
4+
.globl Wait
5+
6+
.equiv TIMER_ADDR , 0x20003000
7+
8+
@
9+
@ Load the counter value in memory
10+
@ => r0: 4 lowest bits
11+
@ => r1: 4 highest bits
12+
@ == r[2..3]
13+
GetCounterValue:
14+
counterValLo .req r0
15+
counterValHi .req r1
16+
ldr r0, =TIMER_ADDR
17+
ldrd counterValLo, counterValHi, [r0,#4]
18+
mov pc, lr @ < Return
19+
20+
@
21+
@ Wait for nbUsec microseconds
22+
@ == r3
23+
Wait:
24+
nbUsec .req r0 @ <- number of microseconds to wait [0, 2^32[
25+
26+
push {lr}
27+
28+
@ Retrieve the current value of the counter
29+
push {nbUsec}
30+
.unreq nbUsec
31+
bl GetCounterValue
32+
nbUsec .req r1
33+
pop {nbUsec}
34+
counterVal .req r0
35+
36+
@ Set the gap to wait
37+
gapToWait .req r2
38+
add gapToWait, counterVal, nbUsec
39+
.unreq nbUsec
40+
41+
@ And finally, wait
42+
waitLoop$:
43+
bl GetCounterValue
44+
cmp counterVal, gapToWait
45+
bls waitLoop$
46+
47+
pop {pc} @ < Return
48+

0 commit comments

Comments
 (0)