Fixed bug in the circular data queue

This commit is contained in:
Edvard Pettersen 2018-07-23 09:37:23 +02:00
parent 824296cbc0
commit abe82f3d8e
4 changed files with 27 additions and 20 deletions

View File

@ -84,9 +84,9 @@ rx_bufs_init(void)
data_entry->config.lenSz = rx_data_queue.lensz;
data_entry->length = RX_BUF_SIZE - sizeof(data_entry_t); /* TODO: is this sizeof sound? */
/* Point to fist entry if this is last entry, else point to next entry */
data_entry->pNextEntry = (i == (RX_BUF_CNT - 1))
data_entry->pNextEntry = ((i + 1) == RX_BUF_CNT)
? rx_data_queue.bufs[0].buf
: rx_data_queue.bufs[i].buf;
: rx_data_queue.bufs[i+1].buf;
}
}
/*---------------------------------------------------------------------------*/

View File

@ -518,21 +518,24 @@ read(void *buf, unsigned short buf_len)
if (data_entry->status != DATA_ENTRY_FINISHED) {
/* No available data */
return 0;
return -1;
}
/*
* First byte in the data entry is the length.
* lensz bytes (1) in the data entry are the length of the received frame.
* Data frame is on the following format:
* Length (1) + Payload (N) + FCS (2) + RSSI (1) + Status (1) + Timestamp (4)
* Data frame DOES NOT contain the following:
* no PHY Header bytes
* no Source Index bytes
* +--------+---------+---------+--------+--------+-----------+
* | 1 byte | N bytes | 2 bytes | 1 byte | 1 byte | 4 bytes |
* +--------+---------+---------+--------+--------+-----------+
* | Length | Payload | FCS | RSSI | Status | Timestamp |
* +--------+---------+---------+--------+--------+-----------+
* Visual representation of frame format:
*
* +--------+---------+---------+--------+--------+-----------+
* | 1 byte | N bytes | 2 bytes | 1 byte | 1 byte | 4 bytes |
* +--------+---------+---------+--------+--------+-----------+
* | Length | Payload | FCS | RSSI | Status | Timestamp |
* +--------+---------+---------+--------+--------+-----------+
*
* Length bytes equal total length of entire frame excluding itself,
* Length = N + FCS (2) + RSSI (1) + Status (1) + Timestamp (4)
* Length = N + 8

View File

@ -376,22 +376,25 @@ read(void *buf, unsigned short buf_len)
if (data_entry->status != DATA_ENTRY_FINISHED) {
/* No available data */
return 0;
return -1;
}
/*
* First 2 bytes in the data entry are the length.
* lensz bytes (2) in the data entry are the length of the received frame.
* Data frame is on the following format:
* Length (2) + Payload (N) + RSSI (1) + Status (1)
* Data frame DOES NOT contain the following:
* no Header/PHY bytes
* no appended Received CRC bytes
* no Timestamp bytes
* +---------+---------+--------+--------+
* | 2 bytes | N bytes | 1 byte | 1 byte |
* +---------+---------+--------+--------+
* | Length | Payload | RSSI | Status |
* +---------+---------+--------+--------+
* Visual representation of frame format:
*
* +---------+---------+--------+--------+
* | 2 bytes | N bytes | 1 byte | 1 byte |
* +---------+---------+--------+--------+
* | Length | Payload | RSSI | Status |
* +---------+---------+--------+--------+
*
* Length bytes equal total length of entire frame excluding itself,
* Length = N + RSSI (1) + Status (1)
* = N + 2

View File

@ -115,8 +115,8 @@ static inline clock_time_t
synth_recal_interval(void)
{
/*
* Add jitter centered around SYNTH_RECAL_INTERVAL,
* giving a +- jitter halved.
* Add jitter centered around SYNTH_RECAL_INTERVAL, giving a plus/minus
* jitter seconds halved.
*/
return SYNTH_RECAL_INTERVAL + (random_rand() % SYNTH_RECAL_JITTER) - (SYNTH_RECAL_JITTER / 2);
}
@ -519,7 +519,7 @@ ble_sched_beacon(RF_Callback cb, RF_EventMask bm_event)
return RF_RESULT_OK;
}
/*---------------------------------------------------------------------------*/
PROCESS(rf_sched_process, "RF Core Process");
PROCESS(rf_sched_process, "RF Scheduler Process");
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(rf_sched_process, ev, data)
{
@ -562,7 +562,8 @@ PROCESS_THREAD(rf_sched_process, ev, data)
NETSTACK_MAC.input();
}
} while(len > 0);
/* Only break when we receive -1 => No available data */
} while(len >= 0);
}
/* Scheduling CMD_FS will re-calibrate the synth. */