diff --git a/embedded/README.md b/embedded/README.md index 6b147e36cff313b8aa94c6f6efcd0dfeae257af4..ce67d76ba1969be463f9c407890956acb4e8f5cf 100644 --- a/embedded/README.md +++ b/embedded/README.md @@ -1,11 +1,10 @@ # 'API' -Currently: test packet parsing w/ 'real' packet ... try py terminal? loop return - - need healthy tx transmit side of ringbuffer output... - - need to increment hop count ... in packet handler? +[start][destination][destination][hopcount][source][source][#bytestotal][byte_7][byte_6]...[byte_n] 0-255 bytes +Packet Loops ... -[start][destination][destination][hopcount][source][source][#bytestotal][byte_7][byte_6]...[byte_n] 0-255 bytes +do Packet Handle cleanup / integrate with new node-> incl. ports # Interrupts diff --git a/embedded/atsams70-tinyrouter/.vs/atsams70-tinyrouter/v14/.atsuo b/embedded/atsams70-tinyrouter/.vs/atsams70-tinyrouter/v14/.atsuo index edbe47cf14888b7b780a959c3b96a96b3d0fc492..1d7b2859a7922a00d97e2b43467f0c7ca1707b89 100644 Binary files a/embedded/atsams70-tinyrouter/.vs/atsams70-tinyrouter/v14/.atsuo and b/embedded/atsams70-tinyrouter/.vs/atsams70-tinyrouter/v14/.atsuo differ diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/main.c b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/main.c index bd0add52ef8533cc1358d455e8feb64cfc3c4fef..91ee4d104d9ec788d664e41a7bb39142f6f5dc32 100644 --- a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/main.c +++ b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/main.c @@ -203,21 +203,7 @@ void setallstatus(void){ pin_set(&p4lb); } -int main (void){ - /* - node_t* n = (node_t*)malloc(sizeof(node_t)); - n->myAddress = ADDRESS; - n->portBufferSizes = (uint8_t*)malloc(32); - for (int port = 0; port < 4; port++) { - n->portBufferSizes[port] = 0; - } - n->LUT = (uint8_t**)malloc(4096); - for (int i = 0; i < 4; i++) { - for (int port = 0; port < 4; port++) { - n->LUT[i][port] = 255; - } - } - */ +int main (void){ board_init(); // asf sysclk_init(); // asf clock @@ -236,8 +222,6 @@ int main (void){ tp_init(&tp3); tp_init(&tp4); - tinyport_t ports[4] = {tp1, tp2, tp3, tp4}; - setupinterrupts(); // turns interrupt NVICs on setallstatus(); // lights off @@ -248,6 +232,23 @@ int main (void){ tp_testlights(&tp3); tp_testlights(&tp2); tp_testlights(&tp4); + + tinyport_t ports[4] = {tp1, tp2, tp3, tp4}; + + /* + node_t* n;// = (node_t*)malloc(sizeof(node_t)); + n->myAddress = ADDRESS; + n->portBufferSizes = (uint8_t*)malloc(32); + for (int port = 0; port < 4; port++) { + n->portBufferSizes[port] = 0; + } + n->LUT = (uint8_t**)malloc(4096); + for (int i = 0; i < 1024; i++) { + for (int port = 0; port < 4; port++) { + n->LUT[i][port] = 255; // MD w/ malloc ? we want [1024][4], no? + } + } + */ packet_t packetlooper; @@ -266,12 +267,12 @@ int main (void){ packet_clean(&ports[i].packet); // reset packet states ports[i].haspacket = TP_NO_PACKET; - tp_putdata(&ports[i], packetlooper.raw, packetlooper.size + 1); // non-blocking put + //handle_packet(n, &packetlooper, i); + tp_putdata(&ports[i], packetlooper.raw, packetlooper.size); // non-blocking put packet_clean(&packetlooper); - pin_set(ports[i].stlb); // for debugging: we have seen a packet on this port + pin_set(ports[i].stlb); - //handle_packet(); } } } // end while @@ -285,7 +286,6 @@ void UART2_Handler(){ if(UART2->UART_SR & UART_SR_RXRDY){ tp_rxhandler(&tp1); } - if(UART2->UART_SR & UART_SR_TXRDY){ tp_txhandler(&tp1); } @@ -295,16 +295,25 @@ void UART0_Handler(){ if(UART0->UART_SR & UART_SR_RXRDY){ tp_rxhandler(&tp2); } + if(UART0->UART_SR & UART_SR_TXRDY){ + tp_txhandler(&tp2); + } } void UART1_Handler(){ if(UART1->UART_SR & UART_SR_RXRDY){ tp_rxhandler(&tp3); } + if(UART1->UART_SR & UART_SR_TXRDY){ + tp_txhandler(&tp3); + } } void UART4_Handler(){ if(UART4->UART_SR & UART_SR_RXRDY){ tp_rxhandler(&tp4); } + if(UART4->UART_SR & UART_SR_TXRDY){ + tp_txhandler(&tp4); + } } diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/packet_handling.c b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/packet_handling.c index 0a2246526bc4c1aef51583e73425723f8a63b1b4..45502befd9343297813a5d64fe9f78dee0be1381 100644 --- a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/packet_handling.c +++ b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/packet_handling.c @@ -15,7 +15,7 @@ void update_LUT(node_t* n, uint16_t src, uint8_t hopCount, uint8_t port) { } void send_packet(packet_t* p, uint8_t port) { - // TODO: + //tp_putdata() // need global ports[]; } void broadcast_packet(packet_t* p, uint8_t exclude) { @@ -32,7 +32,7 @@ int in_table(node_t* n, uint8_t dest) { void handle_packet(node_t* n, packet_t* p, uint8_t port) { if (p->hopcount > MAX_HOPCOUNT) { - //free((void*)p); + free((void*)p); return; } diff --git a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/tinyport.c b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/tinyport.c index fbf2ae9fa6e58daddd15cddd245ba2171e22c57b..523879363c71b39764fa055583447f3006fe13a5 100644 --- a/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/tinyport.c +++ b/embedded/atsams70-tinyrouter/atsams70-tinyrouter/src/tinyport.c @@ -94,7 +94,7 @@ void tp_packetparser(tinyport_t *tp){ // writing to packet // check for size byte // check for end of packet w/ counter (counter is _current_ byte, is incremented at end of handle) - if(tp->packet.counter >= tp->packet.size){ // check counter against packet size to see if @ end of packet + if(tp->packet.counter >= tp->packet.size - 1){ // check counter against packet size to see if @ end of packet tp->haspacket = TP_HAS_PACKET; // this data is final byte, we have packet, this will be last tick in loop tp->packetstate = TP_PACKETSTATE_OUTSIDE; // and we're outside again pin_clear(tp->stlb); @@ -114,11 +114,11 @@ void tp_packetparser(tinyport_t *tp){ void tp_txhandler(tinyport_t *tp){ if(!rb_empty(tp->rbtx)){ - pin_clear(tp->stlr); + pin_clear(tp->stlg); tp->uart->UART_THR = rb_get(tp->rbtx); } else { tp->uart->UART_IDR = UART_IER_TXRDY; // if nothing left to tx, turn isr off - pin_set(tp->stlr); + pin_set(tp->stlg); } //while(!(tp->uart->UART_SR & UART_SR_TXRDY)); // blocking } diff --git a/js/serialterminal.js b/js/serialterminal.js index dc3f52075d999f76ee7fe2b847533241a275e06f..445afd2ec5ebb32ee6dba0b9a51e60486d1c9b71 100644 --- a/js/serialterminal.js +++ b/js/serialterminal.js @@ -17,7 +17,7 @@ const rl = readline.createInterface({ rl.on('line', parseLineIn); // [type][destination][destination][hopcount][source][source][#bytestotal][byte_7][byte_6]...[byte_n] -var buf = Buffer.from([255,1,2,3,4,5,9,10,11,12]) +var buf = Buffer.from([255,2,3,4,5,6,12,8,9,10,11,12]) function parseLineIn(data) { if (debug) {