add an offset to packet_t to compensate for the added length byte on

reception
This commit is contained in:
Mariano Alvira 2010-03-07 17:04:30 -05:00
parent 8421031d4a
commit 024448e65e
5 changed files with 10 additions and 4 deletions

View file

@ -12,6 +12,10 @@ struct packet {
uint8_t length; uint8_t length;
volatile struct packet * left; volatile struct packet * left;
volatile struct packet * right; 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 */ uint8_t data[MAX_PACKET_SIZE+1]; /* + 1 since maca returns the length as the first byte */
}; };
typedef struct packet packet_t; typedef struct packet packet_t;

View file

@ -167,7 +167,7 @@ void post_tx(void) {
last_post = TX_POST; last_post = TX_POST;
dma_tx = tx_head; dma_tx = tx_head;
*MACA_TXLEN = (uint32_t)((dma_tx->length) + 2); *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) { if(dma_rx == 0) {
dma_rx = get_free_packet(); dma_rx = get_free_packet();
if (dma_rx == 0) if (dma_rx == 0)
@ -257,6 +257,7 @@ void add_to_rx(volatile packet_t *p) {
safe_irq_disable(MACA); safe_irq_disable(MACA);
if(!p) { PRINTF("add_to_rx passed packet 0\n\r"); return; } if(!p) { PRINTF("add_to_rx passed packet 0\n\r"); return; }
p->offset = 1; /* first byte is the length */
if(rx_head == 0) { if(rx_head == 0) {
/* start a new queue if empty */ /* start a new queue if empty */
rx_end = p; rx_end = p;

View file

@ -47,7 +47,7 @@ uint32_t get_time(void) {
#define random_short_addr() (*MACA_RANDOM & ones(sizeof(short_addr_t)*8)) #define random_short_addr() (*MACA_RANDOM & ones(sizeof(short_addr_t)*8))
void build_session_req(volatile packet_t *p) { void build_session_req(volatile packet_t *p) {
p->length = 4; p->length = 4; p->offset = 0;
p->data[0] = 0x01; p->data[0] = 0x01;
p->data[1] = 0x02; p->data[1] = 0x02;
p->data[2] = 0x03; p->data[2] = 0x03;

View file

@ -14,6 +14,7 @@ void fill_packet(volatile packet_t *p) {
static volatile uint8_t count=0; static volatile uint8_t count=0;
volatile uint8_t i; volatile uint8_t i;
p->length = PAYLOAD_LEN; p->length = PAYLOAD_LEN;
p->offset = 0;
for(i=0; i<PAYLOAD_LEN; i++) { for(i=0; i<PAYLOAD_LEN; i++) {
p->data[i] = count++; p->data[i] = count++;
} }

View file

@ -35,7 +35,7 @@ void print_packet(volatile packet_t *p) {
for(j=0, k=0; j <= ((p->length)%PER_ROW); j++) { for(j=0, k=0; j <= ((p->length)%PER_ROW); j++) {
for(i=0; i < PER_ROW; i++, k++) { for(i=0; i < PER_ROW; i++, k++) {
if(k >= (p->length + 1) ) { goto out; } /* + 1 since first byte is len+2 */ 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"); printf("\n\r");
} }