diff --git a/lib/include/packet.h b/lib/include/packet.h index cf336458f..ea9fb0ca0 100644 --- a/lib/include/packet.h +++ b/lib/include/packet.h @@ -12,6 +12,10 @@ struct packet { uint8_t length; volatile struct packet * left; volatile struct packet * right; + /* offset into data for first byte of the packet payload */ + /* On TX this should be 0 */ + /* On RX this should be 1 since the maca puts the length as the first byte*/ + uint8_t offset; uint8_t data[MAX_PACKET_SIZE+1]; /* + 1 since maca returns the length as the first byte */ }; typedef struct packet packet_t; diff --git a/lib/maca.c b/lib/maca.c index 93e216c2f..fe0d54ab2 100644 --- a/lib/maca.c +++ b/lib/maca.c @@ -167,7 +167,7 @@ void post_tx(void) { last_post = TX_POST; dma_tx = tx_head; *MACA_TXLEN = (uint32_t)((dma_tx->length) + 2); - *MACA_DMATX = (uint32_t)&(dma_tx->data[0]); + *MACA_DMATX = (uint32_t)&(dma_tx->data[ 0 + dma_tx->offset]); if(dma_rx == 0) { dma_rx = get_free_packet(); if (dma_rx == 0) @@ -255,8 +255,9 @@ void free_tx_head(void) { void add_to_rx(volatile packet_t *p) { safe_irq_disable(MACA); - + if(!p) { PRINTF("add_to_rx passed packet 0\n\r"); return; } + p->offset = 1; /* first byte is the length */ if(rx_head == 0) { /* start a new queue if empty */ rx_end = p; diff --git a/tests/per.c b/tests/per.c index 826ba640f..82e9f8ffb 100644 --- a/tests/per.c +++ b/tests/per.c @@ -47,7 +47,7 @@ uint32_t get_time(void) { #define random_short_addr() (*MACA_RANDOM & ones(sizeof(short_addr_t)*8)) void build_session_req(volatile packet_t *p) { - p->length = 4; + p->length = 4; p->offset = 0; p->data[0] = 0x01; p->data[1] = 0x02; p->data[2] = 0x03; diff --git a/tests/rftest-tx.c b/tests/rftest-tx.c index fb5b3dbe1..84bdfb638 100644 --- a/tests/rftest-tx.c +++ b/tests/rftest-tx.c @@ -14,6 +14,7 @@ void fill_packet(volatile packet_t *p) { static volatile uint8_t count=0; volatile uint8_t i; p->length = PAYLOAD_LEN; + p->offset = 0; for(i=0; idata[i] = count++; } diff --git a/tests/tests.c b/tests/tests.c index f9a56eeef..e5442ed3a 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -35,7 +35,7 @@ void print_packet(volatile packet_t *p) { for(j=0, k=0; j <= ((p->length)%PER_ROW); j++) { for(i=0; i < PER_ROW; i++, k++) { if(k >= (p->length + 1) ) { goto out; } /* + 1 since first byte is len+2 */ - printf("%02x ",p->data[j*PER_ROW+i]); + printf("%02x ",p->data[j*PER_ROW + i + p->offset]); } printf("\n\r"); }