Serial buffers

This commit is contained in:
Mark Qvist 2020-06-01 13:45:26 +02:00
parent c95547b910
commit 66662866e2
4 changed files with 22 additions and 20 deletions

View File

@ -5,7 +5,7 @@
// Version info // Version info
#define MAJ_VERSION 0x01 #define MAJ_VERSION 0x01
#define MIN_VERSION 0x02 #define MIN_VERSION 0x03
// CPU settings // CPU settings
#define TARGET_CPU m1284p #define TARGET_CPU m1284p

View File

@ -26,8 +26,8 @@ void serial_init(Serial *serial) {
serial->uart0 = uart0_fd; serial->uart0 = uart0_fd;
serial->uart1 = uart1_fd; serial->uart1 = uart1_fd;
fifo_init(&uart0FIFO, uart0Buf, sizeof(uart0Buf)); fifo_init(&uart0FIFO, uart0Buf, CONFIG_UART0_BUFFER_SIZE);
fifo_init(&uart1FIFO, uart1Buf, sizeof(uart1Buf)); fifo_init(&uart1FIFO, uart1Buf, CONFIG_UART1_BUFFER_SIZE);
} }
@ -82,7 +82,7 @@ ISR(USART0_RX_vect) {
LED_COM_ON(); LED_COM_ON();
if (!fifo_isfull(&uart0FIFO)) { if (!fifo_isfull(&uart0FIFO)) {
char c = uart0_getchar_nowait(); char c = uart0_getchar_nowait();
fifo_push(&uart0FIFO, c); fifo_push_locked(&uart0FIFO, c);
} else { } else {
uart0_getchar_nowait(); uart0_getchar_nowait();
} }

View File

@ -15,10 +15,10 @@ typedef struct Serial {
} Serial; } Serial;
FIFOBuffer uart0FIFO; FIFOBuffer uart0FIFO;
uint8_t uart0Buf[CONFIG_UART0_BUFFER_SIZE]; uint8_t uart0Buf[CONFIG_UART0_BUFFER_SIZE+1];
FIFOBuffer uart1FIFO; FIFOBuffer uart1FIFO;
uint8_t uart1Buf[CONFIG_UART1_BUFFER_SIZE]; uint8_t uart1Buf[CONFIG_UART1_BUFFER_SIZE+1];
void serial_init(Serial *serial); void serial_init(Serial *serial);
bool serial_available(uint8_t index); bool serial_available(uint8_t index);

View File

@ -460,24 +460,26 @@ void kiss_serialCallback(uint8_t sbyte) {
if (IN_FRAME && sbyte == FEND && command == CMD_DATA) { if (IN_FRAME && sbyte == FEND && command == CMD_DATA) {
IN_FRAME = false; IN_FRAME = false;
if (queue_height < CONFIG_QUEUE_MAX_LENGTH && queued_bytes < CONFIG_QUEUE_SIZE) { ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
size_t s = current_packet_start; if (!fifo16_isfull(&packet_starts) && queued_bytes < CONFIG_QUEUE_SIZE) {
size_t e = queue_cursor-1; if (e == -1) e = CONFIG_QUEUE_SIZE-1; size_t s = current_packet_start;
size_t l; size_t e = queue_cursor-1; if (e == -1) e = CONFIG_QUEUE_SIZE-1;
size_t l;
if (s != e) { if (s != e) {
l = (s < e) ? e - s + 1 : CONFIG_QUEUE_SIZE - s + e + 1; l = (s < e) ? e - s + 1 : CONFIG_QUEUE_SIZE - s + e + 1;
} else { } else {
l = 1; l = 1;
} }
if (l >= AX25_MIN_PAYLOAD) { if (l >= AX25_MIN_PAYLOAD) {
queue_height++; queue_height++;
fifo16_push_locked(&packet_starts, s); fifo16_push(&packet_starts, s);
fifo16_push_locked(&packet_lengths, l); fifo16_push(&packet_lengths, l);
current_packet_start = queue_cursor; current_packet_start = queue_cursor;
}
} }
} }