diff options
Diffstat (limited to 'c/elevator')
| -rw-r--r-- | c/elevator/Makefile | 20 | ||||
| -rw-r--r-- | c/elevator/elevator.c | 230 | ||||
| -rwxr-xr-x | c/elevator/elevator.elf | bin | 0 -> 8748 bytes | |||
| -rw-r--r-- | c/elevator/elevator.hex | 135 | ||||
| -rw-r--r-- | c/elevator/elevator.o | bin | 0 -> 12580 bytes | |||
| -rw-r--r-- | c/elevator/rvcontroller.ld | 45 | ||||
| -rw-r--r-- | c/elevator/states.h | 14 |
7 files changed, 444 insertions, 0 deletions
diff --git a/c/elevator/Makefile b/c/elevator/Makefile new file mode 100644 index 0000000..875cd3b --- /dev/null +++ b/c/elevator/Makefile @@ -0,0 +1,20 @@ +all: elevator.hex + +elevator.o: elevator.c + clang -target riscv32-none-elf -I../rvcontroller-libraries -march=rv32imacb_zicntr_zicond_zicsr_zifencei_zihintpause_zilsd_zclsd_zabha_zacas_zbkb_zbkx_zcb_zcmp_zcmt -ffreestanding -O3 -c -o elevator.o elevator.c + +elevator.elf: ../rvcontroller-libraries/rvcontroller-init.o ../rvcontroller-libraries/rvcontroller-ecalls.o elevator.o + riscv32-none-elf-ld -T rvcontroller.ld --no-warn-rwx-segments -o elevator.elf ../rvcontroller-libraries/rvcontroller-init.o elevator.o ../rvcontroller-libraries/rvcontroller-ecalls.o + +dump: elevator.elf + riscv32-none-elf-objdump -d elevator.elf + +elevator.hex: elevator.elf + riscv32-none-elf-objcopy -O ihex elevator.elf elevator.hex + +load: elevator.hex + bash -c "wl-copy < elevator.hex" + +clean: + rm -f elevator.bin elevator.elf elevator.o init.o + diff --git a/c/elevator/elevator.c b/c/elevator/elevator.c new file mode 100644 index 0000000..845a57e --- /dev/null +++ b/c/elevator/elevator.c @@ -0,0 +1,230 @@ +/* Conway's Game of Life for RVController + * A product of Advanced Mesecons Devices, a Cheapie Systems company + * This is free and unencumbered software released into the public domain. + * See http://unlicense.org/ for more information */ + +#include <stdint.h> +#include <stdbool.h> +#include "rvcontroller-ecalls.h" +#include "states.h" + +int state = STATE_INIT; +bool sensor1state = false; +bool sensor2state = false; +bool sensor3state = false; +bool call1state = false; +bool call2state = false; +bool call3state = false; +int direction = DIRECTION_UP; +int timer; + +char channelbuf[16]; +char msgbuf[64]; + +bool streq(char *a, char *b) { + for (int i=0;a[i] != 0 || b[i] != 0;i++) { + if (a[i] != b[i]) { + return false; + } + } + return true; +} + +void sleep(uint32_t delay) { + //This will start having problems after about 130 years + //of uptime, but that's probably acceptable + uint32_t endtime = rdtime() + delay; + while (rdtime() < endtime) {} + return; +} + +void sendSensorGetMessages(void) { + digiline_send("sensor1","GET"); + digiline_send("sensor2","GET"); + digiline_send("sensor3","GET"); +} + +void processDigilinesMessages(void) { + while (digiline_bufferlevel() > 0) { + digiline_receive(channelbuf,16,msgbuf,64); + if (streq(channelbuf,"sensor1")) { + sensor1state = (streq(msgbuf,"mesecons_movestones:movestone_vertical")); + } else if (streq(channelbuf,"sensor2")) { + sensor2state = (streq(msgbuf,"mesecons_movestones:movestone_vertical")); + } else if (streq(channelbuf,"sensor3")) { + sensor3state = (streq(msgbuf,"mesecons_movestones:movestone_vertical")); + } else if (streq(channelbuf,"button1") && (state != STATE_TIMING_1) && (state != STATE_IDLE_1)) { + call1state = true; + digiline_send("button1","light_on"); + } else if (streq(channelbuf,"button2") && (state != STATE_TIMING_2) && (state != STATE_IDLE_2)) { + call2state = true; + digiline_send("button2","light_on"); + } else if (streq(channelbuf,"button3") && (state != STATE_TIMING_3) && (state != STATE_IDLE_3)) { + call3state = true; + digiline_send("button3","light_on"); + } + } +} + +void main(void) { + while (true) { + sendSensorGetMessages(); + processDigilinesMessages(); + switch (state) { + case STATE_INIT: + printstr("\nElevator Controller\nfor RVController\nInitializing"); + digiline_send("door1","extend"); + digiline_send("door2","extend"); + digiline_send("door3","extend"); + digiline_send("sel","extend"); + digiline_send("down","extend"); + digiline_send("up","retract_sticky"); + digiline_send("button1","light_off"); + digiline_send("button2","light_off"); + digiline_send("button3","light_off"); + printstr("\nBottom Floor Demand"); + state = STATE_BOTTOM_FLOOR_DEMAND; + break; + case STATE_BOTTOM_FLOOR_DEMAND: + if (sensor1state) { + printstr("\nBFD Complete"); + digiline_send("down","retract_sticky"); + digiline_send("door1","retract_sticky"); + state = STATE_TIMING_1; + timer = 5; + } + break; + case STATE_TIMING_1: + timer--; + if (timer <= 0) { + printstr("\nIdle at 1"); + state = STATE_IDLE_1; + } + break; + case STATE_TIMING_2: + timer--; + if (timer <= 0) { + printstr("\nIdle at 2"); + state = STATE_IDLE_2; + } + break; + case STATE_TIMING_3: + timer--; + if (timer <= 0) { + printstr("\nIdle at 3"); + state = STATE_IDLE_3; + } + break; + case STATE_IDLE_1: + if (call2state) { + direction = DIRECTION_UP; + printstr("\nMoving to 2"); + state = STATE_MOVING_2; + digiline_send("door1","extend"); + digiline_send("sel","retract_sticky"); + digiline_send("up","extend"); + } else if (call3state) { + direction = DIRECTION_UP; + printstr("\nMoving to 3"); + state = STATE_MOVING_3; + digiline_send("door1","extend"); + digiline_send("sel","extend"); + digiline_send("up","extend"); + } + break; + case STATE_IDLE_2: + if (direction == DIRECTION_UP) { + if (call3state) { + direction = DIRECTION_UP; + printstr("\nMoving to 3"); + state = STATE_MOVING_3; + digiline_send("door2","extend"); + digiline_send("sel","extend"); + digiline_send("up","extend"); + } else if (call1state) { + direction = DIRECTION_DOWN; + printstr("\nMoving to 1"); + state = STATE_MOVING_1; + digiline_send("door2","extend"); + digiline_send("sel","extend"); + digiline_send("down","extend"); + } + } else { + if (call1state) { + direction = DIRECTION_DOWN; + printstr("\nMoving to 1"); + state = STATE_MOVING_1; + digiline_send("door2","extend"); + digiline_send("sel","extend"); + digiline_send("down","extend"); + } else if (call3state) { + direction = DIRECTION_UP; + printstr("\nMoving to 3"); + state = STATE_MOVING_3; + digiline_send("door2","extend"); + digiline_send("sel","extend"); + digiline_send("up","extend"); + } + } + break; + case STATE_IDLE_3: + if (call2state) { + direction = DIRECTION_DOWN; + printstr("\nMoving to 2"); + state = STATE_MOVING_2; + digiline_send("door3","extend"); + digiline_send("sel","retract_sticky"); + digiline_send("down","extend"); + } else if (call1state) { + direction = DIRECTION_DOWN; + printstr("\nMoving to 1"); + state = STATE_MOVING_1; + digiline_send("door3","extend"); + digiline_send("sel","extend"); + digiline_send("down","extend"); + } + break; + case STATE_MOVING_1: + if (sensor1state) { + printstr("\nArrived at 1"); + digiline_send("button1","light_off"); + direction = DIRECTION_UP; + digiline_send("down","retract_sticky"); + digiline_send("door1","retract_sticky"); + timer = 5; + state = STATE_TIMING_1; + call1state = false; + } + break; + case STATE_MOVING_2: + if (sensor2state) { + printstr("\nArrived at 2"); + digiline_send("button2","light_off"); + digiline_send("up","retract_sticky"); + digiline_send("down","retract_sticky"); + digiline_send("door2","retract_sticky"); + timer = 5; + state = STATE_TIMING_2; + call2state = false; + } + break; + case STATE_MOVING_3: + if (sensor3state) { + printstr("\nArrived at 3"); + digiline_send("button3","light_off"); + direction = DIRECTION_DOWN; + digiline_send("up","retract_sticky"); + digiline_send("door3","retract_sticky"); + timer = 5; + state = STATE_TIMING_3; + call3state = false; + } + break; + } + if ((state == STATE_IDLE_1) || (state == STATE_IDLE_2) || (state == STATE_IDLE_3)) { + lightweight_mode(1); + sleep(1); + lightweight_mode(0); + } + } +} diff --git a/c/elevator/elevator.elf b/c/elevator/elevator.elf Binary files differnew file mode 100755 index 0000000..9b5cafc --- /dev/null +++ b/c/elevator/elevator.elf diff --git a/c/elevator/elevator.hex b/c/elevator/elevator.hex new file mode 100644 index 0000000..2da4185 --- /dev/null +++ b/c/elevator/elevator.hex @@ -0,0 +1,135 @@ +:10000000370101008124A948730000008280148117
+:10001000988133E6E60009C685050505E389E6FE15
+:1000200013351600828052B82A84C92B2A94F923EA
+:10003000E36F85FE52BE46B822E422E00145130577
+:100040000068014413048068A285512B0145130503
+:10005000C068A2856923014513054069A285226411
+:10006000026446BAADAB4EB822F44AF052EC5AE8FC
+:1000700062E46AE0952B6300051C014B130BC07E04
+:10008000814B930B0068014C130CC069814C014DEE
+:10009000130DC068814D930D4069814A930A306CFD
+:1000A0000949014A130A406D81499309C06D9304BF
+:1000B0004B0113044B0201A813B516002306A07EC2
+:1000C0002523630A0516C14593060004268522866A
+:1000D0000D23FEAC1D4614813367D6003DC39881C5
+:1000E0007D1685050505E388E6FE1D45A6856A861D
+:1000F00094813367D5002DC718827D1505068505C7
+:10010000E388E6FE13054B019D456E86148133E7B7
+:10011000D50035CB1882FD1505060505E388E6FEFA
+:1001200013054B019D455686148133E7D50041C325
+:100130001882FD1505060505E388E6FE03258B00FC
+:10014000B5A813056002A28562869881B366E500B2
+:10015000A5D61C827D1505068505E308F7FEA9BF17
+:1001600013056002A28562869881B366E50099C690
+:100170001C827D1505068505E308F7FE13B51600FC
+:10018000A306A07E35BF13054B029305600262866D
+:100190001881B3E6E50099C61C82FD150506050524
+:1001A000E308F7FE13B516002307A07E11BF032551
+:1001B0008B006305250195456311B50693054B0139
+:1001C0001D46D2869881B367E60081CB9C827D165E
+:1001D00085068505E308F7FE39A099456305B50056
+:1001E0008D456311B50493054B011D46CE8698815C
+:1001F000B367E60081CB9C827D1685068505E30802
+:10020000F7FE7DBD9145E30DB5EA9D45E30AB5EAEC
+:100210000545A302AB004E8511A80545A307A07EA6
+:10022000568529A005452302AB00528581459305DB
+:10023000B06C752671B522740279626A426B226CC9
+:10024000026D4EBE4EB822F44AF052EC5AE862E417
+:100250006AE0014913090068814493048068814978
+:100260009309C068814C930C4069014C130CC07E0B
+:10027000A94A894D0544014D130D4065014B130BEF
+:10028000D071014A130AC07366AD912EE6AD812E7E
+:100290006685A685A926C13B03258C0063E5AA30A7
+:1002A0003345A5210841028501451305406E052609
+:1002B000014513057071DA851D260145130540724D
+:1002C000DA85312E01451305A072DA85092E014524
+:1002D00013050073DA852126014513054073DA857D
+:1002E000FD2C014513059073D285D52C01451305CE
+:1002F000306C01441304B074A285D5240145130564
+:10030000406DA285E92C01451305C06DA285054409
+:10031000F9240145130550755D2C23248C0061A43C
+:1003200003250C019305F5FF2328BC00634DA4268B
+:1003300001451305E078612C1D452324AC00A5A4DC
+:1003400001450345D07E6300052601451305E07C89
+:10035000BD2C01451305406D81459305B0744124C2
+:10036000014513059073D2859D2C014513054073FB
+:10037000D285B524014513054072D2858D24230210
+:100380000C000D4535A203250C019305F5FF23282C
+:10039000BC00634AA4200145130580770D2C154548
+:1003A0002324AC0009A403250C019305F5FF2328A1
+:1003B000BC00634AA41E014513053078092C194579
+:1003C0002324AC00CDA203454C000589630A051225
+:1003D00023268C00014513059079D52A2545232431
+:1003E000AC0001451305A072DA85D52A0145130535
+:1003F0000073D2855DA201450345C07E0589630473
+:10040000051A01451305A076D9220145130540734D
+:10041000D285F122014513057071D285C922D9A870
+:1004200003454C000589630E050E23260C0001458B
+:1004300013059079692A25452324AC00014513054D
+:100440007071DA85692A014513050073D28519AAEE
+:100450000325CC006306050E01450345F07E631CB1
+:10046000051003455C006300051423260C00E1A879
+:1004700001450345E07E0589630705120145130523
+:10048000C07DB12201451305C06D81459305B0744F
+:10049000B92223268C00014513059073D285812251
+:1004A00001451305A072D2851D2AA3020C00114537
+:1004B0002324AC0091A001450345C07E0589630457
+:1004C000050E01451305007C192201451305306C0A
+:1004D00081459305B074212223260C0001451305A4
+:1004E0004073D285ED28014513057071D285C5286A
+:1004F000A3010C002324BC0115452328AC0065A0F2
+:1005000001450345F07E45C123268C0001451305B6
+:10051000307B752821452324AC0001451305A072CA
+:10052000BDA003455C0041C123260C000145130515
+:10053000607A712823245C0101451305707129A894
+:1005400003455C000DC501451305607A492023244D
+:100550005C01014513054072DA8551200145130500
+:100560000073DA85AD280145130590731DA8014578
+:100570000345F07E0DC923268C0001451305307B11
+:10058000B92021452324AC00014513054072DA85CA
+:10059000B920014513050073DA8591200145130543
+:1005A0004073DA852D2803258C006D15E3EEADCC64
+:1005B00005458520A120930B15008920E36F75FF69
+:1005C00001458128D1B1854873000000828091489F
+:1005D000730000008280AD487300000082809308A1
+:1005E0001008730000008280930850087300000018
+:1005F000828093087008730000008280732510C009
+:100600008280732500C08280930860087300000018
+:1006100082800589F322008093920248B3E2A2000F
+:100620007390028082809548730000008280930856
+:100630000008730000008280A148730000008280DF
+:10064000930830087300000082809308400873000C
+:1006500000008280A8020000F6030000860300006C
+:10066000A603000020030000200400005004000046
+:10067000C6030000B6040000400300007004000040
+:1006800073656E736F7231004745540073656E7306
+:100690006F72320073656E736F7233006D657365D0
+:1006A000636F6E735F6D6F766573746F6E65733AAB
+:1006B0006D6F766573746F6E655F7665727469636E
+:1006C000616C00627574746F6E31006C6967687478
+:1006D0005F6F6E00627574746F6E32006275747451
+:1006E0006F6E33000A456C657661746F7220436FDC
+:1006F0006E74726F6C6C65720A666F72205256432C
+:100700006F6E74726F6C6C65720A496E69746961A0
+:100710006C697A696E6700646F6F72310065787416
+:10072000656E6400646F6F723200646F6F723300C5
+:1007300073656C00646F776E00757000726574721B
+:100740006163745F737469636B79006C6967687463
+:100750005F6F6666000A426F74746F6D20466C6F3F
+:100760006F722044656D616E64000A424644204306
+:100770006F6D706C657465000A49646C6520617406
+:100780002031000A49646C652061742032000A49F6
+:10079000646C652061742033000A4D6F76696E6762
+:1007A00020746F2032000A4D6F76696E6720746F77
+:1007B0002033000A4D6F76696E6720746F20310018
+:1007C0000A417272697665642061742031000A41C1
+:1007D0007272697665642061742032000A41727217
+:0A07E000697665642061742033001F
+:1007EC0000000000000000000000000000000000FD
+:1007FC0000000000000000000000000000000000ED
+:10080C0000000000000000000000000000000000DC
+:10081C0000000000000000000000000000000000CC
+:10082C0000000000000000000000000000000000BC
+:10083C0000000000000000000000000000000000AC
+:04084C0000000000A8
+:00000001FF
diff --git a/c/elevator/elevator.o b/c/elevator/elevator.o Binary files differnew file mode 100644 index 0000000..834800b --- /dev/null +++ b/c/elevator/elevator.o diff --git a/c/elevator/rvcontroller.ld b/c/elevator/rvcontroller.ld new file mode 100644 index 0000000..985892b --- /dev/null +++ b/c/elevator/rvcontroller.ld @@ -0,0 +1,45 @@ +/* Thanks https://github.com/darklife/darkriscv */ + __heap_size = 0x200; /* required amount of heap */ + __stack_size = 0x800; /* required amount of stack */ + ENTRY(_start); + MEMORY + { + RAM (rwx) : ORIGIN = 0x00000000, LENGTH = 0x10000 + } + SECTIONS + { + .text : + { + *(.text.startup) + *(.text) + *(.text) + *(.rodata*) + } > RAM + .data : + { + *(.sbss) + *(.data) + *(.bss) + *(.rela*) + *(COMMON) + } > RAM + + .heap : + { + . = ALIGN(4); + PROVIDE ( end = . ); + _sheap = .; + . = . + __heap_size; + . = ALIGN(4); + _eheap = .; + } >RAM + + .stack : + { + . = ALIGN(4); + _estack = .; + . = . + __stack_size; + . = ALIGN(4); + _sstack = .; + } >RAM + } diff --git a/c/elevator/states.h b/c/elevator/states.h new file mode 100644 index 0000000..27fb4d2 --- /dev/null +++ b/c/elevator/states.h @@ -0,0 +1,14 @@ +#define STATE_INIT 0 +#define STATE_BOTTOM_FLOOR_DEMAND 1 +#define STATE_TIMING_1 2 +#define STATE_TIMING_2 3 +#define STATE_TIMING_3 4 +#define STATE_IDLE_1 5 +#define STATE_IDLE_2 6 +#define STATE_IDLE_3 7 +#define STATE_MOVING_1 8 +#define STATE_MOVING_2 9 +#define STATE_MOVING_3 10 + +#define DIRECTION_UP 0 +#define DIRECTION_DOWN 1 |
