Serial buffers
This commit is contained in:
parent
c95547b910
commit
66662866e2
2
device.h
2
device.h
|
@ -5,7 +5,7 @@
|
|||
|
||||
// Version info
|
||||
#define MAJ_VERSION 0x01
|
||||
#define MIN_VERSION 0x02
|
||||
#define MIN_VERSION 0x03
|
||||
|
||||
// CPU settings
|
||||
#define TARGET_CPU m1284p
|
||||
|
|
|
@ -26,8 +26,8 @@ void serial_init(Serial *serial) {
|
|||
serial->uart0 = uart0_fd;
|
||||
serial->uart1 = uart1_fd;
|
||||
|
||||
fifo_init(&uart0FIFO, uart0Buf, sizeof(uart0Buf));
|
||||
fifo_init(&uart1FIFO, uart1Buf, sizeof(uart1Buf));
|
||||
fifo_init(&uart0FIFO, uart0Buf, CONFIG_UART0_BUFFER_SIZE);
|
||||
fifo_init(&uart1FIFO, uart1Buf, CONFIG_UART1_BUFFER_SIZE);
|
||||
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ ISR(USART0_RX_vect) {
|
|||
LED_COM_ON();
|
||||
if (!fifo_isfull(&uart0FIFO)) {
|
||||
char c = uart0_getchar_nowait();
|
||||
fifo_push(&uart0FIFO, c);
|
||||
fifo_push_locked(&uart0FIFO, c);
|
||||
} else {
|
||||
uart0_getchar_nowait();
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ typedef struct Serial {
|
|||
} Serial;
|
||||
|
||||
FIFOBuffer uart0FIFO;
|
||||
uint8_t uart0Buf[CONFIG_UART0_BUFFER_SIZE];
|
||||
uint8_t uart0Buf[CONFIG_UART0_BUFFER_SIZE+1];
|
||||
|
||||
FIFOBuffer uart1FIFO;
|
||||
uint8_t uart1Buf[CONFIG_UART1_BUFFER_SIZE];
|
||||
uint8_t uart1Buf[CONFIG_UART1_BUFFER_SIZE+1];
|
||||
|
||||
void serial_init(Serial *serial);
|
||||
bool serial_available(uint8_t index);
|
||||
|
|
|
@ -460,24 +460,26 @@ void kiss_serialCallback(uint8_t sbyte) {
|
|||
if (IN_FRAME && sbyte == FEND && command == CMD_DATA) {
|
||||
IN_FRAME = false;
|
||||
|
||||
if (queue_height < CONFIG_QUEUE_MAX_LENGTH && 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;
|
||||
size_t l;
|
||||
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;
|
||||
size_t l;
|
||||
|
||||
if (s != e) {
|
||||
l = (s < e) ? e - s + 1 : CONFIG_QUEUE_SIZE - s + e + 1;
|
||||
} else {
|
||||
l = 1;
|
||||
}
|
||||
if (s != e) {
|
||||
l = (s < e) ? e - s + 1 : CONFIG_QUEUE_SIZE - s + e + 1;
|
||||
} else {
|
||||
l = 1;
|
||||
}
|
||||
|
||||
if (l >= AX25_MIN_PAYLOAD) {
|
||||
queue_height++;
|
||||
if (l >= AX25_MIN_PAYLOAD) {
|
||||
queue_height++;
|
||||
|
||||
fifo16_push_locked(&packet_starts, s);
|
||||
fifo16_push_locked(&packet_lengths, l);
|
||||
fifo16_push(&packet_starts, s);
|
||||
fifo16_push(&packet_lengths, l);
|
||||
|
||||
current_packet_start = queue_cursor;
|
||||
current_packet_start = queue_cursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue