mirror of
https://github.com/markqvist/OpenModem.git
synced 2024-10-01 03:15:46 -04:00
Reworked buffering system
This commit is contained in:
parent
3e43786dd1
commit
e43cb2f543
@ -106,13 +106,13 @@ void AFSK_init(Afsk *afsk) {
|
||||
afsk->silentSamples = 0;
|
||||
|
||||
// Initialise FIFO buffers
|
||||
fifo_init(&afsk->delayFifo, (uint8_t *)afsk->delayBuf, sizeof(afsk->delayBuf));
|
||||
fifo_init(&afsk->rxFifo, afsk->rxBuf, sizeof(afsk->rxBuf));
|
||||
fifo_init(&afsk->txFifo, afsk->txBuf, sizeof(afsk->txBuf));
|
||||
fifo_init(&afsk->delayFifo, (uint8_t *)afsk->delayBuf, sizeof(afsk->delayBuf)-1);
|
||||
fifo_init(&afsk->rxFifo, afsk->rxBuf, CONFIG_AFSK_RX_BUFLEN);
|
||||
fifo_init(&afsk->txFifo, afsk->txBuf, CONFIG_AFSK_TX_BUFLEN);
|
||||
|
||||
// Fill delay FIFO with zeroes
|
||||
for (int i = 0; i<ADC_SAMPLESPERBIT / 2; i++) {
|
||||
fifo_push(&afsk->delayFifo, 0);
|
||||
while (fifo_isfull(&afsk->delayFifo)) {
|
||||
fifo_push_locked(&afsk->delayFifo, 0);
|
||||
}
|
||||
|
||||
AFSK_hw_init();
|
||||
|
@ -182,18 +182,18 @@ typedef struct Afsk
|
||||
// Demodulation values
|
||||
FIFOBuffer delayFifo; // Delayed FIFO for frequency discrimination
|
||||
#if BITRATE == 1200
|
||||
int8_t delayBuf[ADC_SAMPLESPERBIT / 2 + 1]; // Actual data storage for said FIFO
|
||||
int8_t delayBuf[(ADC_SAMPLESPERBIT / 2 - 1) + 1]; // Actual data storage for said FIFO
|
||||
#elif BITRATE == 2400
|
||||
int8_t delayBuf[7 + 1];
|
||||
int8_t delayBuf[(7) + 1];
|
||||
#elif BITRATE == 300
|
||||
int8_t delayBuf[9 + 1];
|
||||
int8_t delayBuf[(9) + 1];
|
||||
#endif
|
||||
|
||||
FIFOBuffer rxFifo; // FIFO for received data
|
||||
uint8_t rxBuf[CONFIG_AFSK_RX_BUFLEN]; // Actual data storage for said FIFO
|
||||
uint8_t rxBuf[CONFIG_AFSK_RX_BUFLEN+1]; // Actual data storage for said FIFO
|
||||
|
||||
FIFOBuffer txFifo; // FIFO for transmit data
|
||||
uint8_t txBuf[CONFIG_AFSK_TX_BUFLEN]; // Actual data storage for said FIFO
|
||||
uint8_t txBuf[CONFIG_AFSK_TX_BUFLEN+1]; // Actual data storage for said FIFO
|
||||
|
||||
int16_t iirX[2]; // IIR Filter X cells
|
||||
int16_t iirY[2]; // IIR Filter Y cells
|
||||
|
@ -84,7 +84,7 @@ ISR(USART0_RX_vect) {
|
||||
char c = uart0_getchar_nowait();
|
||||
fifo_push(&uart0FIFO, c);
|
||||
} else {
|
||||
uart0_getchar_nowait();
|
||||
//uart0_getchar_nowait();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -95,7 +95,7 @@ ISR(USART1_RX_vect) {
|
||||
char c = uart1_getchar_nowait();
|
||||
fifo_push(&uart1FIFO, c);
|
||||
} else {
|
||||
uart1_getchar_nowait();
|
||||
//uart1_getchar_nowait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,10 +53,10 @@ void kiss_init(AX25Ctx *ax25, Afsk *afsk, Serial *ser) {
|
||||
|
||||
memset(packet_queue, 0, sizeof(packet_queue));
|
||||
|
||||
memset(packet_starts_buf, 0, sizeof(packet_starts));
|
||||
memset(packet_starts_buf, 0, sizeof(packet_starts_buf));
|
||||
fifo16_init(&packet_starts, packet_starts_buf, CONFIG_QUEUE_MAX_LENGTH);
|
||||
|
||||
memset(packet_lengths_buf, 0, sizeof(packet_lengths));
|
||||
memset(packet_lengths_buf, 0, sizeof(packet_lengths_buf));
|
||||
fifo16_init(&packet_lengths, packet_lengths_buf, CONFIG_QUEUE_MAX_LENGTH);
|
||||
}
|
||||
|
||||
@ -340,7 +340,7 @@ void kiss_flushQueue(void) {
|
||||
queue_flushing = true;
|
||||
|
||||
size_t processed = 0;
|
||||
for (size_t n = 0; n < queue_height; n++) {
|
||||
while (!fifo16_isempty_locked(&packet_starts)) {
|
||||
size_t start = fifo16_pop_locked(&packet_starts);
|
||||
size_t length = fifo16_pop_locked(&packet_lengths);
|
||||
|
||||
@ -460,7 +460,6 @@ void kiss_serialCallback(uint8_t sbyte) {
|
||||
if (IN_FRAME && sbyte == FEND && command == CMD_DATA) {
|
||||
IN_FRAME = false;
|
||||
|
||||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
||||
if (!fifo16_isfull(&packet_starts) && queued_bytes < CONFIG_QUEUE_SIZE) {
|
||||
size_t s = current_packet_start;
|
||||
size_t e = queue_cursor-1; if (e == -1) e = CONFIG_QUEUE_SIZE-1;
|
||||
@ -481,7 +480,6 @@ void kiss_serialCallback(uint8_t sbyte) {
|
||||
current_packet_start = queue_cursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else if (sbyte == FEND) {
|
||||
IN_FRAME = true;
|
||||
@ -501,7 +499,7 @@ void kiss_serialCallback(uint8_t sbyte) {
|
||||
if (sbyte == TFESC) sbyte = FESC;
|
||||
ESCAPE = false;
|
||||
}
|
||||
if (queue_height < CONFIG_QUEUE_MAX_LENGTH && queued_bytes < CONFIG_QUEUE_SIZE) {
|
||||
if (!fifo16_isfull(&packet_starts) && queued_bytes < CONFIG_QUEUE_SIZE) {
|
||||
queued_bytes++;
|
||||
packet_queue[queue_cursor++] = sbyte;
|
||||
if (queue_cursor == CONFIG_QUEUE_SIZE) queue_cursor = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user