-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from mauri870/feature/ok05
Add ok05 exercise
- Loading branch information
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# OK05 - Flash the SOS morse code using the OK/ACT led | ||
|
||
The OK05 lesson builds on OK04 using it to flash the SOS Morse Code pattern. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@; | ||
@; Counter functions to be used by this exercise | ||
@; | ||
|
||
.section .text | ||
.global delay | ||
delay: | ||
ldr r1, =0x3F000000 @; pi peripheral address | ||
orr r1, r1, #0x3000 @; r1 = r1 | 0x3000 = 0x3F003000 timer base address | ||
ldr r2, [r1, #0x4] @; time in microseconds given by the timer | ||
delay1$: | ||
ldr r3, [r1, #0x4] @; get timer in microseconds in each iteration | ||
sub r3, r3, r2 @; current timer - initial timer | ||
cmp r3, r0 @; compare time elapsed with desired timer | ||
blt delay1$ @; if elapsed time < desired timer repeat the loop | ||
mov pc, lr @; return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
@; | ||
@; Functions to interact with the leds | ||
@; | ||
|
||
.section .text | ||
.global set_led_state | ||
set_led_state: | ||
push {lr} @; save address the function should return to | ||
mov r1, r0 @; move the led state to r1 | ||
ldr r0, =message @; load the message into r0 | ||
mov r2, #0 | ||
str r2, [r0, #0x4] @; reset request code | ||
str r2, [r0, #0x10] @; reset request/response size | ||
mov r2, #130 | ||
str r2, [r0, #0x14] @; reset pin number | ||
|
||
str r1, [r0, #0x18] @; overwrite the led state | ||
add r0, #8 @; add the channel 8 as the last 4 bits of the message | ||
bl mailbox_write | ||
pop {pc} @; return | ||
|
||
.section .data | ||
.align 4 @; last 4 bits of the next label set to 0 (16-byte alligned) | ||
message: | ||
.int size @; message header contains the size of the message | ||
.int 0 @; request code 0 | ||
|
||
.int 0x00038041 @; header tag ID | ||
.int 8 @; size of tag data | ||
.int 0 @; request/response size | ||
|
||
.int 130 @; pin number | ||
.int 1 @; pin state | ||
.int 0 @; signal the GPU that the message is over | ||
size: | ||
.int . - message @; size of the message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@; | ||
@; Functions to interact with the mailbox | ||
@; | ||
|
||
.section .text | ||
.global mailbox_write | ||
mailbox_write: | ||
ldr r1, =0x3f00b880 @; load the hex number =0x3f00b880 into register r1 | ||
@; this is the base address of the mailboxes | ||
wait$: | ||
ldr r2, [r1, #0x18] @; load r2 with the address of the offset 0x18 for mailbox 0 (read mailbox) | ||
tst r2, #0x80000000 @; check if the full flag is set | ||
bne wait$ @; branch to wait$ label if the full flag is not set | ||
|
||
str r0, [r1, #0x20] @; put the message into mailbox 1 write register, which is at offset 0x20 from the base address | ||
mov pc, lr @; return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
@; | ||
@; A simple program to flash the SOS message in Morse using the OK/ACT led | ||
@; | ||
|
||
.section .init @; kernel initialization code must be on 0x8000 | ||
.global _start @; define _start label globally available for the linker | ||
_start: | ||
mov sp, #0x8000 @; set up the stack pointer | ||
b _main @; branch to main routine | ||
|
||
.section .text | ||
_main: | ||
ldr r2, =sos @; load the address of the sos data | ||
ldr r2, [r2] @; load the binary content into r2 | ||
mov r3, #0 @; use r3 to keep track of the position | ||
|
||
loop$: @; main loop | ||
mov r0, #1 @; r0 start value | ||
lsl r0, r3 @; left shift r3 one place to the left | ||
and r0, r2 @; and between the r0 value and the current message place | ||
|
||
bl set_led_state @; set led state | ||
|
||
ldr r0, =0x7A120 @; delay in microseconds (0.5s) | ||
bl delay @; branch to delay function | ||
|
||
add r3, #1 @; increment our position tracker | ||
and r3, #0b11111 @; reset the sequence to 0 if >= 32 | ||
|
||
b loop$ @; branch to main loop$ | ||
|
||
.section .data | ||
.align 2 | ||
sos: | ||
.int 0b11111111101010100010001000101010 |