summaryrefslogtreecommitdiff
path: root/software/first/set_LED.S
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2019-07-22 23:04:17 +0200
committerSilvan Jegen <s.jegen@gmail.com>2019-07-22 23:04:17 +0200
commitf5e284223d25ee5beab98de95cd74e3ac72a39a6 (patch)
tree33d6b2b3a0e5fa5b1d0b3094108bac78bd84bda0 /software/first/set_LED.S
parent4bc2e5141c68e82f2f6d7c8f71051fe93dd96d18 (diff)
Implement first superblink version
Diffstat (limited to 'software/first/set_LED.S')
-rw-r--r--software/first/set_LED.S46
1 files changed, 46 insertions, 0 deletions
diff --git a/software/first/set_LED.S b/software/first/set_LED.S
new file mode 100644
index 0000000..e436615
--- /dev/null
+++ b/software/first/set_LED.S
@@ -0,0 +1,46 @@
+.section .text
+.align 2
+.global set_LED
+.include "memory_map.inc"
+.include "gpio.inc"
+
+.equ NOERROR, 0x0
+.equ ERROR, 0x1
+.equ LEDON, 0x1
+
+# a0 contains LED to set, desired LED state in a1
+# a0 is also the return value...
+
+set_LED:
+ addi sp, sp, -16 # Allocate stack frame
+ sw ra, 12(sp) # save return address to the stack
+
+ li t0, GPIO_CTRL_ADDR # load base GPIO address
+ lw t1, GPIO_OUTPUT_VAL(t0) # load state
+
+ beqz a1, ledOff # branch if == 0
+ li t2, LEDON # load up on val into t2
+
+ beq a1, t2, ledOn # branch if on requested
+ li a0, ERROR # bad status request, return error
+ j exit
+
+
+ledOn:
+ or t1, t1, a0 # only change the value of the requested LED (xor in the video)
+ sw t1, GPIO_OUTPUT_VAL(t0) # write new LED values to the right address
+ li a0, NOERROR # success
+ j exit
+
+
+ledOff:
+ xor a0, a0, 0xffffffff # invert bits so off bits are off
+ and t1, t1, a0 # turn of LEDs
+ sw t1, GPIO_OUTPUT_VAL(t0) # write new LED values to the right address
+ li a0, NOERROR # success
+
+
+exit:
+ lw ra, 12(sp) # load return address
+ addi sp, sp, 16 # deallocate stack frame
+ ret