Skip to content
Snippets Groups Projects
Commit ad51e494 authored by Jake Read's avatar Jake Read
Browse files

ready to packet handle integrate

parent a0001db1
No related branches found
No related tags found
No related merge requests found
# '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
......
No preview for this file type
......@@ -204,20 +204,6 @@ void setallstatus(void){
}
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;
}
}
*/
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
......@@ -249,6 +233,23 @@ int main (void){
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;
while(1){
......@@ -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);
}
}
......@@ -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;
}
......
......@@ -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
}
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment