From 9b8a8aae83569bb418bc2f5039bfa9d04f33e516 Mon Sep 17 00:00:00 2001 From: Jake <jake.read@cba.mit.edu> Date: Thu, 15 Mar 2018 23:38:41 -0400 Subject: [PATCH] apa fast packets --- circuit/mkrouter/eagle.epf | 56 ++++---- .../mkrouter-v04/.vs/mkrouter-v04/v14/.atsuo | Bin 85504 -> 82944 bytes .../mkrouter-v04/src/apahandler.c | 41 +++++- .../mkrouter-v04/src/apahandler.h | 1 + .../mkrouter-v04/mkrouter-v04/src/apaport.c | 51 ++++--- .../mkrouter-v04/mkrouter-v04/src/apaport.h | 13 +- .../mkrouter-v04/mkrouter-v04/src/hardware.h | 48 ++++--- embedded/mkrouter-v04/mkrouter-v04/src/main.c | 127 ++++++++++-------- 8 files changed, 191 insertions(+), 146 deletions(-) diff --git a/circuit/mkrouter/eagle.epf b/circuit/mkrouter/eagle.epf index 9d05cd1..853ce9a 100644 --- a/circuit/mkrouter/eagle.epf +++ b/circuit/mkrouter/eagle.epf @@ -68,19 +68,19 @@ Layer=21 Package="AYZ0102AGRLC" [Win_2] -Type="Board Editor" +Type="Schematic Editor" Loc="0 0 1919 1016" State=1 -Number=2 -File="mkrouter.brd" -View="-14.045 -4.4575 135.445 78.9618" -WireWidths=" 0.0762 0.1016 0.127 0.15 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.3048 0.2 0.254 0.1524 0.2032" +Number=1 +File="mkrouter.sch" +View="-49.6823 -37.446 410.437 258.349" +WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.2032 0.254 0.3048 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.1524" PadDiameters=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0" -PadDrills=" 0.2 0.25 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6 0.3" +PadDrills=" 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6" ViaDiameters=" 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1 1.05 1.1 1.15 1.2 1.3 0" -ViaDrills=" 0.2 0.4 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.25 0.45 0.35 0.3" -HoleDrills=" 0.2 0.25 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35 0.3" -TextSizes=" 0.254 0.3048 0.4064 0.8128 1.27 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778 1.016 0.6096 1.4224 1.6764" +ViaDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35" +HoleDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35" +TextSizes=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778" PolygonSpacings=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.27" PolygonIsolates=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0" MiterRadiuss=" 0.254 0.3175 0.635 1.27 2.54 1 2 2.5 5 7.5 10 0" @@ -89,14 +89,14 @@ DimensionExtWidths=" 0.127 0.254 0.1 0.13 0.26 0" DimensionExtLengths=" 1.27 2.54 1 2 3 0" DimensionExtOffsets=" 1.27 2.54 1 2 3 0" SmdSizes=" 0.3048 0.1524 0.4064 0.2032 0.6096 0.3048 0.8128 0.4064 1.016 0.508 1.27 0.6604 1.4224 0.7112 1.6764 0.8128 1.778 0.9144 1.9304 0.9652 2.1844 1.0668 2.54 1.27 3.81 1.9304 5.08 2.54 6.4516 3.2512 1.27 0.635" -WireBend=6 -WireBendSet=0 +WireBend=0 +WireBendSet=31 WireCap=1 MiterStyle=0 PadShape=0 ViaShape=1 PolygonPour=0 -PolygonRank=1 +PolygonRank=0 PolygonThermals=1 PolygonOrphans=0 TextRatio=8 @@ -111,22 +111,24 @@ SwapLevel=0 ArcDirection=0 AddLevel=2 PadsSameType=0 -Layer=1 +Layer=91 +Views=" 1: -49.6823 -37.446 410.437 258.349" +Sheet="1" [Win_3] -Type="Schematic Editor" +Type="Board Editor" Loc="0 0 1919 1016" State=1 -Number=1 -File="mkrouter.sch" -View="-49.6823 -37.446 410.437 258.349" -WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.2032 0.254 0.3048 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.1524" +Number=2 +File="mkrouter.brd" +View="-15.8584 -4.26648 133.632 79.1528" +WireWidths=" 0.0762 0.1016 0.127 0.15 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.3048 0.2 0.254 0.1524 0.2032" PadDiameters=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0" -PadDrills=" 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6" +PadDrills=" 0.2 0.25 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6 0.3" ViaDiameters=" 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1 1.05 1.1 1.15 1.2 1.3 0" -ViaDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35" -HoleDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35" -TextSizes=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778" +ViaDrills=" 0.2 0.4 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.25 0.45 0.35 0.3" +HoleDrills=" 0.2 0.25 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35 0.3" +TextSizes=" 0.254 0.3048 0.4064 0.8128 1.27 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778 1.016 0.6096 1.4224 1.6764" PolygonSpacings=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.27" PolygonIsolates=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0" MiterRadiuss=" 0.254 0.3175 0.635 1.27 2.54 1 2 2.5 5 7.5 10 0" @@ -135,14 +137,14 @@ DimensionExtWidths=" 0.127 0.254 0.1 0.13 0.26 0" DimensionExtLengths=" 1.27 2.54 1 2 3 0" DimensionExtOffsets=" 1.27 2.54 1 2 3 0" SmdSizes=" 0.3048 0.1524 0.4064 0.2032 0.6096 0.3048 0.8128 0.4064 1.016 0.508 1.27 0.6604 1.4224 0.7112 1.6764 0.8128 1.778 0.9144 1.9304 0.9652 2.1844 1.0668 2.54 1.27 3.81 1.9304 5.08 2.54 6.4516 3.2512 1.27 0.635" -WireBend=0 -WireBendSet=31 +WireBend=6 +WireBendSet=0 WireCap=1 MiterStyle=0 PadShape=0 ViaShape=1 PolygonPour=0 -PolygonRank=0 +PolygonRank=1 PolygonThermals=1 PolygonOrphans=0 TextRatio=8 @@ -157,9 +159,7 @@ SwapLevel=0 ArcDirection=0 AddLevel=2 PadsSameType=0 -Layer=91 -Views=" 1: -49.6823 -37.446 410.437 258.349" -Sheet="1" +Layer=1 [Win_4] Type="Control Panel" diff --git a/embedded/mkrouter-v04/.vs/mkrouter-v04/v14/.atsuo b/embedded/mkrouter-v04/.v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krouter-v04/src/apahandler.c b/embedded/mkrouter-v04/mkrouter-v04/src/apahandler.c index f89cb7a..b84cfce 100644 --- a/embedded/mkrouter-v04/mkrouter-v04/src/apahandler.c +++ b/embedded/mkrouter-v04/mkrouter-v04/src/apahandler.c @@ -9,11 +9,11 @@ #include "apahandler.h" void apa_handle_packet(uint8_t *packet, uint8_t length){ - // dirty debug reply - uart_sendchars_buffered(&up0, packet, length); + // ack with new packet + apa_return_packet(packet, length); // through packet for(int i = 0; i < length; i ++){ - if(packet[i] == APA_END_ADDR_DELIMITER){ + if(packet[i] == APA_END_ROUTE_DELIMITER){ // data begins // check we have data after addr delimiter if(i + 1 < length){ @@ -25,4 +25,37 @@ void apa_handle_packet(uint8_t *packet, uint8_t length){ } } } -} \ No newline at end of file +} + +void apa_return_packet(uint8_t *packet, uint8_t length){ + uint8_t ackpack[length]; + ackpack[0] = length; + // find route header + int i = 2; + int stop = 0; + while(i < length){ + if(packet[i] == APA_END_ROUTE_DELIMITER){ + stop = i; + break; + } + i ++; + } + // do the business + if(!stop){ + // error if stop == 0 + } else { + // reverse the address header + for(int a = stop - 1, b = 1; a >= 1; a--, b++){ + ackpack[b] = packet[a]; + } + // fill the rest with same packet data + ackpack[stop] = APA_END_ROUTE_DELIMITER; + for(int u = stop; u < length; u ++){ + ackpack[u] = packet[u]; + } + uart_sendchars_buffered(ups[ackpack[1]], ackpack, length); + } +} + +// NOW: test this +// then, also: can we avoid packing ups into apaports, use hardware.h instead? diff --git a/embedded/mkrouter-v04/mkrouter-v04/src/apahandler.h b/embedded/mkrouter-v04/mkrouter-v04/src/apahandler.h index 12673cb..766204e 100644 --- a/embedded/mkrouter-v04/mkrouter-v04/src/apahandler.h +++ b/embedded/mkrouter-v04/mkrouter-v04/src/apahandler.h @@ -12,5 +12,6 @@ #include <asf.h> void apa_handle_packet(uint8_t *packet, uint8_t length); +void apa_return_packet(uint8_t *packet, uint8_t length); #endif /* APAHANDLER_H_ */ \ No newline at end of file diff --git a/embedded/mkrouter-v04/mkrouter-v04/src/apaport.c b/embedded/mkrouter-v04/mkrouter-v04/src/apaport.c index 4748bf3..fc4701b 100644 --- a/embedded/mkrouter-v04/mkrouter-v04/src/apaport.c +++ b/embedded/mkrouter-v04/mkrouter-v04/src/apaport.c @@ -6,14 +6,12 @@ */ #include "apaport.h" +#include "hardware.h" -void apaport_build(apaport_t *apap, uint8_t portnum, uartport_t *uart, uartport_t **uarts, uint8_t numports, pin_t *stlr, pin_t *stlg, pin_t *stlb){ +void apaport_build(apaport_t *apap, uint8_t portnum, uartport_t *uart, pin_t *stlr, pin_t *stlb){ apap->uart = uart; - apap->uarts = uarts; apap->portnum = portnum; - apap->numports = numports; apap->stlr = stlr; - apap->stlg = stlg; apap->stlb = stlb; } @@ -24,7 +22,6 @@ void apaport_reset(apaport_t *apap){ apap->packet_position = 0; pin_set(apap->stlr); - pin_set(apap->stlg); pin_set(apap->stlb); } @@ -57,35 +54,31 @@ void apaport_scan(apaport_t *apap, uint32_t maxpackets){ while(apap->packets_ready > 0){ // the particular packet index uint32_t p = (apap->packet_num + APAPORT_NUM_STATIC_PACKETS - apap->packets_ready) % APAPORT_NUM_STATIC_PACKETS; + // first we shift the old pointer out (p[1] is, at the moment, the port the last node tx'd on) + apapacket_shift_pointer(apap->packets[p], apap->portnum); + // now p[1] is next port // now to handle // [p][0] is length of packet - if(apap->packets[p][1] == APA_ADDR_POINTER){ + if(apap->packets[p][1] == APA_ROUTE_POINTER){ apa_handle_packet(apap->packets[p], apap->packets[p][0]); - } else if(apap->packets[p][1] == APA_ADDR_FLOOD){ + } else if(apap->packets[p][1] == APA_ROUTE_FLOOD){ // loop through bytes to find pointer and increment - apapacket_increment_pointer(apap->packets[p], apap->portnum); // now ship it out on all ports for(int i = 0; i < APAPORT_NUM_PORTS; i ++){ if(i == apap->portnum){ // don't flood back } else { - uart_sendchars_buffered(apap->uarts[i], apap->packets[p], apap->packets[p][0]); + uart_sendchars_buffered(ups[i], apap->packets[p], apap->packets[p][0]); } } } else { // packet is for a particular port, - // we pull that out of the packet now in case the pointer decrements into [1] - uint8_t port = apap->packets[p][1]; - // and check that we're sending it out on a port that exists - if (port >= APAPORT_NUM_PORTS){ - port = APAPORT_NUM_PORTS - 1; + if(apap->packets[p][1] > APAPORT_NUM_PORTS){ + // port does not exist, throw error + // pin_clear(&stlr); + } else { + uart_sendchars_buffered(ups[apap->packets[p][1]], apap->packets[p], apap->packets[p][0]); } - // now we can increment, safely moving pointer - apapacket_increment_pointer(apap->packets[p], apap->portnum); - // send on next port - // HERE: failing on send to other ports? - // double / triple check pointer to pointer - uart_sendchars_buffered(apap->uarts[port], apap->packets[p], apap->packets[p][0]); } // debug reply (at the moment, reply is handled in apa_handle_packet // uart_sendchars_buffered(apap->uart, apap->packets[p], apap->packets[p][0]); @@ -93,14 +86,18 @@ void apaport_scan(apaport_t *apap, uint32_t maxpackets){ } } -void apapacket_increment_pointer(uint8_t *packet, uint8_t portnum){ - for(int i = 2; i < packet[0]; i ++){ - // loop through bytes to find pointer and increment - if(packet[i] == APA_ADDR_POINTER){ - packet[i-1] = APA_ADDR_POINTER; // increment pointer forwards - packet[i] = portnum; // port received on is this one - break; // we can finish scan now, not looping senselessly through rest of packet +void apapacket_shift_pointer(uint8_t *packet, uint8_t portnum){ + int i = 2; + while(i < packet[0]){ // while less than length + if(packet[i] == APA_END_ROUTE_DELIMITER){ + // put our port in tail + packet[i-1] = portnum; + break; + } else { + // shift 'em down + packet[i-1] = packet[i]; } + i ++; } } diff --git a/embedded/mkrouter-v04/mkrouter-v04/src/apaport.h b/embedded/mkrouter-v04/mkrouter-v04/src/apaport.h index 912629e..421a98f 100644 --- a/embedded/mkrouter-v04/mkrouter-v04/src/apaport.h +++ b/embedded/mkrouter-v04/mkrouter-v04/src/apaport.h @@ -20,19 +20,16 @@ #define APAPORT_OUTSIDE_PACKET 0 #define APAPORT_INSIDE_PACKET 1 -#define APA_END_ADDR_DELIMITER 255 -#define APA_ADDR_POINTER 254 -#define APA_ADDR_FLOOD 253 +#define APA_END_ROUTE_DELIMITER 255 +#define APA_ROUTE_POINTER 254 +#define APA_ROUTE_FLOOD 253 typedef struct{ uartport_t *uart; - uartport_t **uarts; // ptr to array of ptrs ? pin_t *stlr; pin_t *stlb; - pin_t *stlg; uint8_t portnum; // which port are we - uint8_t numports; // how many in the array we got uint32_t packet_num; uint32_t packet_position; @@ -41,12 +38,12 @@ typedef struct{ uint8_t packets[APAPORT_NUM_STATIC_PACKETS][256]; // packets for handling by app }apaport_t; -void apaport_build(apaport_t *apap, uint8_t portnum, uartport_t *uart, uartport_t **uarts, uint8_t numports, pin_t *stlr, pin_t *stlg, pin_t *stlb); +void apaport_build(apaport_t *apap, uint8_t portnum, uartport_t *uart, pin_t *stlr, pin_t *stlb); void apaport_reset(apaport_t *apap); void apaport_scan(apaport_t *apap, uint32_t maxpackets); -void apapacket_increment_pointer(uint8_t *packet, uint8_t portnum); +void apapacket_shift_pointer(uint8_t *packet, uint8_t portnum); #endif /* APAPORT_H_ */ \ No newline at end of file diff --git a/embedded/mkrouter-v04/mkrouter-v04/src/hardware.h b/embedded/mkrouter-v04/mkrouter-v04/src/hardware.h index e0cc586..32c55db 100644 --- a/embedded/mkrouter-v04/mkrouter-v04/src/hardware.h +++ b/embedded/mkrouter-v04/mkrouter-v04/src/hardware.h @@ -15,22 +15,22 @@ #include "apaport.h" // status lights -pin_t np0stlr; -pin_t np0stlg; -pin_t np0stlb; +pin_t up0_stlr; +pin_t up0_stlg; +pin_t up0_stlb; -pin_t np1stlr; -pin_t np1stlb; +pin_t up1_stlr; +pin_t up1_stlb; -pin_t np2stlr; -pin_t np2stlb; +pin_t up2_stlr; +pin_t up2_stlb; -pin_t np3stlr; -pin_t np3stlb; +pin_t up3_stlr; +pin_t up3_stlb; -pin_t np4stlr; -pin_t np4stlg; -pin_t np4stlb; +pin_t up4_stlr; +pin_t up4_stlg; +pin_t up4_stlb; // array of ptrs to lights // init in main.c @@ -38,16 +38,16 @@ pin_t np4stlb; pin_t *lights[NUM_LIGHTS]; // ringbuffers -ringbuffer_t up0rbrx; -ringbuffer_t up0rbtx; -ringbuffer_t up1rbrx; -ringbuffer_t up1rbtx; -ringbuffer_t up2rbrx; -ringbuffer_t up2rbtx; -ringbuffer_t up3rbrx; -ringbuffer_t up3rbtx; -ringbuffer_t up4rbrx; -ringbuffer_t up4rbtx; +ringbuffer_t up0_rbrx; +ringbuffer_t up0_rbtx; +ringbuffer_t up1_rbrx; +ringbuffer_t up1_rbtx; +ringbuffer_t up2_rbrx; +ringbuffer_t up2_rbtx; +ringbuffer_t up3_rbrx; +ringbuffer_t up3_rbtx; +ringbuffer_t up4_rbrx; +ringbuffer_t up4_rbtx; // uartports uartport_t up0; @@ -63,6 +63,10 @@ uartport_t *ups[NUM_UPS]; // apaports apaport_t apap0; +apaport_t apap1; +apaport_t apap2; +apaport_t apap3; +apaport_t apap4; #endif /* HARDWARE_H_ */ \ No newline at end of file diff --git a/embedded/mkrouter-v04/mkrouter-v04/src/main.c b/embedded/mkrouter-v04/mkrouter-v04/src/main.c index 324a341..31ac548 100644 --- a/embedded/mkrouter-v04/mkrouter-v04/src/main.c +++ b/embedded/mkrouter-v04/mkrouter-v04/src/main.c @@ -50,34 +50,34 @@ void setupinterrupts(void){ } void lightsetup(void){ - pin_init(&np0stlr, PIOD, PIO_PER_P12); - pin_output(&np0stlr); - pin_init(&np0stlg, PIOA, PIO_PER_P3); - pin_output(&np0stlg); - pin_init(&np0stlb, PIOA, PIO_PER_P2); - pin_output(&np0stlb); - - pin_init(&np1stlr, PIOA, PIO_PER_P11); - pin_output(&np1stlr); - pin_init(&np1stlb, PIOD, PIO_PER_P20); - pin_output(&np1stlb); - - pin_init(&np2stlr, PIOA, PIO_PER_P15); - pin_output(&np2stlr); - pin_init(&np2stlb, PIOD, PIO_PER_P27); - pin_output(&np2stlb); - - pin_init(&np3stlr, PIOA, PIO_PER_P22); - pin_output(&np3stlr); - pin_init(&np3stlb, PIOA, PIO_PER_P8); - pin_output(&np3stlb); - - pin_init(&np4stlr, PIOB, PIO_PER_P0); - pin_output(&np4stlr); - pin_init(&np4stlg, PIOA, PIO_PER_P20); - pin_output(&np4stlg); - pin_init(&np4stlb, PIOB, PIO_PER_P1); - pin_output(&np4stlb); + pin_init(&up0_stlr, PIOD, PIO_PER_P12); + pin_output(&up0_stlr); + pin_init(&up0_stlg, PIOA, PIO_PER_P3); + pin_output(&up0_stlg); + pin_init(&up0_stlb, PIOA, PIO_PER_P2); + pin_output(&up0_stlb); + + pin_init(&up1_stlr, PIOA, PIO_PER_P11); + pin_output(&up1_stlr); + pin_init(&up1_stlb, PIOD, PIO_PER_P20); + pin_output(&up1_stlb); + + pin_init(&up2_stlr, PIOA, PIO_PER_P15); + pin_output(&up2_stlr); + pin_init(&up2_stlb, PIOD, PIO_PER_P27); + pin_output(&up2_stlb); + + pin_init(&up3_stlr, PIOA, PIO_PER_P22); + pin_output(&up3_stlr); + pin_init(&up3_stlb, PIOA, PIO_PER_P8); + pin_output(&up3_stlb); + + pin_init(&up4_stlr, PIOB, PIO_PER_P0); + pin_output(&up4_stlr); + pin_init(&up4_stlg, PIOA, PIO_PER_P20); + pin_output(&up4_stlg); + pin_init(&up4_stlb, PIOB, PIO_PER_P1); + pin_output(&up4_stlb); } void lightstoggle(void){ @@ -88,53 +88,53 @@ void lightstoggle(void){ void initports(void){ // RBs 1 - rb_init(&up0rbrx); - rb_init(&up0rbtx); + rb_init(&up0_rbrx); + rb_init(&up0_rbtx); // UP1 on UART0, RX 9 TX 10 on PIOA - uart_build(&up0, UART0, PIOA, 9, 10, &up0rbrx, &up0rbtx, &np0stlr, &np0stlb); + uart_build(&up0, UART0, PIOA, 9, 10, &up0_rbrx, &up0_rbtx, &up0_stlr, &up0_stlb); uart_init(&up0, 81, UART_IS_PERIPHERAL_A); // RBs 2 - rb_init(&up1rbrx); - rb_init(&up1rbtx); + rb_init(&up1_rbrx); + rb_init(&up1_rbtx); // UP2 on UART1, RX 5 TX 4 on PIOA - uart_build(&up1, UART1, PIOA, 5, 4, &up1rbrx, &up1rbtx, &np1stlr, &np1stlb); + uart_build(&up1, UART1, PIOA, 5, 4, &up1_rbrx, &up1_rbtx, &up1_stlr, &up1_stlb); uart_init(&up1, 81, UART_IS_PERIPHERAL_C); // 81 for FTDI 115200 :| // RBs 3 - rb_init(&up2rbrx); - rb_init(&up2rbtx); + rb_init(&up2_rbrx); + rb_init(&up2_rbtx); // UP3 on UART2, RX 25 TX 26 on PIOD - uart_build(&up2, UART2, PIOD, 25, 26, &up2rbrx, &up2rbtx, &np2stlr, &np2stlb); + uart_build(&up2, UART2, PIOD, 25, 26, &up2_rbrx, &up2_rbtx, &up2_stlr, &up2_stlb); uart_init(&up2, 81, UART_IS_PERIPHERAL_C); // RBs 4 - rb_init(&up3rbrx); - rb_init(&up3rbtx); + rb_init(&up3_rbrx); + rb_init(&up3_rbtx); // UP4 on UART3, RX 28 TX 30 on PIOD - uart_build(&up3, UART3, PIOD, 28, 30, &up3rbrx, &up3rbtx, &np3stlr, &np3stlb); + uart_build(&up3, UART3, PIOD, 28, 30, &up3_rbrx, &up3_rbtx, &up3_stlr, &up3_stlb); uart_init(&up3, 81, UART_IS_PERIPHERAL_A); // RBs 5 - rb_init(&up4rbrx); - rb_init(&up4rbtx); + rb_init(&up4_rbrx); + rb_init(&up4_rbtx); // UP5 on UART4, RX 18 TX 19 on PIOD - uart_build(&up4, UART4, PIOD, 18, 19, &up4rbrx, &up4rbtx, &np4stlr, &np4stlb); + uart_build(&up4, UART4, PIOD, 18, 19, &up4_rbrx, &up4_rbtx, &up4_stlr, &up4_stlb); uart_init(&up4, 81, UART_IS_PERIPHERAL_C); } void listsetup(void){ // array of ptrs to lights - lights[0] = &np0stlr; - lights[1] = &np0stlb; - lights[2] = &np1stlr; - lights[3] = &np1stlb; - lights[4] = &np2stlr; - lights[5] = &np2stlb; - lights[6] = &np3stlr; - lights[7] = &np3stlb; - lights[8] = &np4stlr; - lights[9] = &np4stlb; + lights[0] = &up0_stlr; + lights[1] = &up0_stlb; + lights[2] = &up1_stlr; + lights[3] = &up1_stlb; + lights[4] = &up2_stlr; + lights[5] = &up2_stlb; + lights[6] = &up3_stlr; + lights[7] = &up3_stlb; + lights[8] = &up4_stlr; + lights[9] = &up4_stlb; // array of ptrs to uarts ups[0] = &up0; @@ -153,14 +153,27 @@ int main (void){ initports(); listsetup(); - apaport_build(&apap0, 0, &up0, ups, 5, &np0stlr, &np0stlg, &np0stlb); + apaport_build(&apap0, 0, &up0, &up0_stlr, &up0_stlb); apaport_reset(&apap0); + apaport_build(&apap1, 1, &up1, &up1_stlr, &up1_stlb); + apaport_reset(&apap1); + apaport_build(&apap2, 2, &up2, &up2_stlr, &up2_stlb); + apaport_reset(&apap2); + apaport_build(&apap3, 3, &up3, &up3_stlr, &up3_stlb); + apaport_reset(&apap3); + apaport_build(&apap4, 4, &up4, &up4_stlr, &up4_stlb); + apaport_reset(&apap4); + + pin_set(&up0_stlg); + pin_set(&up4_stlg); while(1){ apaport_scan(&apap0, 2); - pin_toggle(&np4stlg); - - delay_ms(75); + apaport_scan(&apap1, 2); + apaport_scan(&apap2, 2); + apaport_scan(&apap3, 2); + apaport_scan(&apap4, 2); + delay_cycles(1); } } -- GitLab