summaryrefslogtreecommitdiff
path: root/assembly/rrxing
diff options
context:
space:
mode:
authorcheapie <cheapiephp@gmail.com>2026-05-30 08:58:29 -0500
committercheapie <cheapiephp@gmail.com>2026-05-30 08:58:29 -0500
commitd609dcb35dafebeafced9c40d92ddd5da630aa54 (patch)
treebe5b1083f2f12173dbe936306e46a11cff4d62ea /assembly/rrxing
parent28be6fac111899c930c8072cd42bcbd7be6f5d40 (diff)
downloadrvcontroller-d609dcb35dafebeafced9c40d92ddd5da630aa54.tar
rvcontroller-d609dcb35dafebeafced9c40d92ddd5da630aa54.tar.gz
rvcontroller-d609dcb35dafebeafced9c40d92ddd5da630aa54.tar.bz2
rvcontroller-d609dcb35dafebeafced9c40d92ddd5da630aa54.tar.xz
rvcontroller-d609dcb35dafebeafced9c40d92ddd5da630aa54.zip
Organize files better and include binaries for assembly samples
Diffstat (limited to 'assembly/rrxing')
-rw-r--r--assembly/rrxing/Makefile24
-rw-r--r--assembly/rrxing/rrxing.S198
-rwxr-xr-xassembly/rrxing/rrxing.elfbin0 -> 6404 bytes
-rw-r--r--assembly/rrxing/rrxing.hex35
-rw-r--r--assembly/rrxing/rrxing.obin0 -> 4372 bytes
l---------assembly/rrxing/rvcontroller.ld1
6 files changed, 258 insertions, 0 deletions
diff --git a/assembly/rrxing/Makefile b/assembly/rrxing/Makefile
new file mode 100644
index 0000000..1f19256
--- /dev/null
+++ b/assembly/rrxing/Makefile
@@ -0,0 +1,24 @@
+MARCH ?= rv32imacbzicntr_zicond_zicsr_zifencei_zihintpause_zilsd_zclsd_zabha_zacas_zbkb_zbkx_zcb_zcmp_zcmt
+
+.PHONY: all dump load clean
+
+all: rrxing.hex
+
+rrxing.o: rrxing.S
+ riscv32-none-elf-as -I../rvcontroller-libraries -march=${MARCH} -o rrxing.o rrxing.S
+
+rrxing.elf: rrxing.o
+ riscv32-none-elf-ld -T rvcontroller.ld --no-warn-rwx-segments -o rrxing.elf rrxing.o
+
+dump: rrxing.elf
+ riscv32-none-elf-objdump -d rrxing.elf
+
+rrxing.hex: rrxing.elf
+ riscv32-none-elf-objcopy -O ihex rrxing.elf rrxing.hex
+
+load: rrxing.hex
+ bash -c "wl-copy < rrxing.hex"
+
+clean:
+ rm -f rrxing.bin rrxing.elf rrxing.o
+
diff --git a/assembly/rrxing/rrxing.S b/assembly/rrxing/rrxing.S
new file mode 100644
index 0000000..61fb41c
--- /dev/null
+++ b/assembly/rrxing/rrxing.S
@@ -0,0 +1,198 @@
+li a7,134 # Clear digilines buffer
+ecall
+
+restart:
+# Hardware initialization
+
+# Make sure light is off
+li a7,129 # Send digilines message
+la a0,lightchannel
+la a1,lightoffmsg
+ecall
+
+# Make sure bell is off
+li a7,129 # Send digilines message
+la a0,bellchannel
+la a1,belloffmsg
+ecall
+
+# Make sure gate is up
+li a7,129 # Send digilines message
+la a0,gatechannel
+la a1,gateupmsg
+ecall
+
+receiveloop:
+li a7,133 # Get digilines buffer level
+ecall
+beq a0,x0,receiveloop # If no messages yet, restart the loop
+
+li a7,135 # Read digilines message
+la a0,channelbuf
+li a1,16 # Channel buffer size
+la a2,msgbuf
+li a3,16 # Message buffer size
+ecall
+
+# Check if it's the right channel
+la a0,channelbuf
+la a1,detectchannel
+call strcmp
+beq a0,x0,receiveloop # Not the right channel, ignore it
+
+# Turn the light yellow
+li a7,129 # Send digilines message
+la a0,lightchannel
+la a1,lightyellowmsg
+ecall
+
+# Wait 1 second
+li a0,1
+call sleep
+
+# Turn the bell on
+li a7,129 # Send digilines message
+la a0,bellchannel
+la a1,bellonmsg
+ecall
+
+# Wait 2 seconds
+li a0,2
+call sleep
+
+# Turn the light red
+li a7,129 # Send digilines message
+la a0,lightchannel
+la a1,lightredmsg
+ecall
+
+# Wait 3 seconds
+li a0,3
+call sleep
+
+# Lower the gate
+li a7,129 # Send digilines message
+la a0,gatechannel
+la a1,gatedownmsg
+ecall
+
+# Wait 5 seconds
+li a0,5
+call sleep
+
+# Turn the bell off
+li a7,129 # Send digilines message
+la a0,bellchannel
+la a1,belloffmsg
+ecall
+
+waitlonger:
+
+# Wait 10 seconds
+li a0,10
+call sleep
+
+# Check if any more trains have been detected
+receiveloop2:
+li a7,133 # Get digilines buffer level
+ecall
+beq a0,x0,raise # If no messages yet, go ahead with timing out
+
+# If there is a message, check if it's a train
+
+li a7,135 # Read digilines message
+la a0,channelbuf
+li a1,16 # Channel buffer size
+la a2,msgbuf
+li a3,16 # Message buffer size
+ecall
+
+# Check if it's the right channel
+la a0,channelbuf
+la a1,detectchannel
+call strcmp
+beq a0,x0,receiveloop2 # Not the right channel, ignore this message and go on to the next
+
+# If it is the right channel, then get rid of the rest of the messages (if any)
+li a7,134 # Clear digilines buffer
+ecall
+
+j waitlonger # And go wait another 10 seconds
+
+raise:
+
+# Raise the gate
+li a7,129 # Send digilines message
+la a0,gatechannel
+la a1,gateupmsg
+ecall
+
+# Wait 2 seconds
+li a0,2
+call sleep
+
+# Turn the light off
+li a7,129 # Send digilines message
+la a0,lightchannel
+la a1,lightoffmsg
+ecall
+
+# And go wait for the next train
+j restart
+
+sleep:
+ # Expects a number of seconds in a0
+ # Uses t0
+ rdtime t0
+ add a0,t0,a0
+ sleep_loop:
+ rdtime t0
+ bltu t0,a0,sleep_loop
+ret
+
+strcmp:
+ # Expects string pointers in a0 and a1
+ # Compares until a NUL is reached on the first string
+ # Uses t0, t1, and t2
+ # Returns a0=1 if strings match, a0=0 otherwise
+ li t0,0 # t0 is the loop counter
+ strcmp_loop:
+ # Calculate addresses
+ add t1,a0,t0 # t1 is the pointer for the first string
+ add t2,a1,t0 # t2 is the pointer for the second string
+
+ # Read the bytes from each string
+ lb t1,0(t1)
+ lb t2,0(t2)
+
+ # Increment the loop counter
+ addi t0,t0,1
+
+ # And compare
+ bne t1,t2,strcmp_mismatch
+
+ # Check if a terminator was reached yet, keep going otherwise
+ li t2,0
+ bne t1,t2,strcmp_loop
+
+ # If we got here they match
+ li a0,1
+ ret
+
+ strcmp_mismatch:
+ li a0,0
+ ret
+
+channelbuf: .ascii " "
+msgbuf: .ascii " "
+lightchannel: .asciz "light"
+bellchannel: .asciz "bell"
+gatechannel: .asciz "gate"
+lightoffmsg: .asciz "OFF"
+lightyellowmsg: .asciz "YELLOW"
+lightredmsg: .asciz "RED"
+bellonmsg: .asciz "on"
+belloffmsg: .asciz "off"
+gateupmsg: .asciz "up"
+gatedownmsg: .asciz "down"
+detectchannel: .asciz "detect"
diff --git a/assembly/rrxing/rrxing.elf b/assembly/rrxing/rrxing.elf
new file mode 100755
index 0000000..cab0bf9
--- /dev/null
+++ b/assembly/rrxing/rrxing.elf
Binary files differ
diff --git a/assembly/rrxing/rrxing.hex b/assembly/rrxing/rrxing.hex
new file mode 100644
index 0000000..7283fa9
--- /dev/null
+++ b/assembly/rrxing/rrxing.hex
@@ -0,0 +1,35 @@
+:1000000093086008730000009308100817050000AB
+:100010001305A51D970500009385251E730000009C
+:1000200093081008170500001305851C97050000AC
+:100030009385C51D73000000930810081705000084
+:100040001305551B970500009385851C7300000060
+:10005000930850087300000065DD930870081705C9
+:10006000000013058516C145170600001306E616A5
+:10007000C14673000000170500001305051597051C
+:10008000000093856519292A61D593081008170582
+:10009000000013058515970500009385451673002C
+:1000A00000000545F520930810081705000013050A
+:1000B0002514970500009385351573000000094548
+:1000C000C1289308100817050000130505129705AD
+:1000D000000093853513730000000D4555289308E3
+:1000E0001008170500001305F5109705000093850B
+:1000F0005512730000001545612893081008170574
+:1001000000001305E50E9705000093852510730088
+:1001100000002945B528930850087300000015CD4C
+:1001200093087008170500001305250AC145170636
+:1001300000001306860AC146730000001705000080
+:100140001305A508970500009385050D912861D535
+:1001500093086008730000006DBF9308100817052E
+:10016000000013053509970500009385650A7300A3
+:1001700000000945312893081008170500001305F1
+:10018000C506970500009385450773000000ADBDC7
+:10019000F32210C01695F32210C0E3EEA2FE828077
+:1001A000814233035500B383550003030300838367
+:1001B00003008502631773008143E31473FE054552
+:1001C00082800145828020202020202020202020A5
+:1001D000202020202020202020202020202020201F
+:1001E0002020202020206C696768740062656C6C98
+:1001F0000067617465004F46460059454C4C4F57A7
+:1002000000524544006F6E006F66660075700064B2
+:0C0210006F776E00646574656374000015
+:00000001FF
diff --git a/assembly/rrxing/rrxing.o b/assembly/rrxing/rrxing.o
new file mode 100644
index 0000000..09193ef
--- /dev/null
+++ b/assembly/rrxing/rrxing.o
Binary files differ
diff --git a/assembly/rrxing/rvcontroller.ld b/assembly/rrxing/rvcontroller.ld
new file mode 120000
index 0000000..bc01402
--- /dev/null
+++ b/assembly/rrxing/rvcontroller.ld
@@ -0,0 +1 @@
+../../rvcontroller.ld \ No newline at end of file