soft_uart: fix Rx buffer flushing logic in suart_rx_ch()
Whenever we encounter a parity and/or a framing error, we should
call the .rx_cb() immediately, even if this was the first
character in the receive buffer.
Change-Id: I73fab1a5c196d2dbdfe98b0c20d8dadbd22f4f64
Related: OS#4396
diff --git a/src/core/soft_uart.c b/src/core/soft_uart.c
index 400ce5a..058512d 100644
--- a/src/core/soft_uart.c
+++ b/src/core/soft_uart.c
@@ -97,12 +97,13 @@
msgb_put_u8(suart->rx.msg, ch);
msg_len = msgb_length(suart->rx.msg);
- /* first character in new message: start timer */
- if (msg_len == 1) {
+ if (msg_len >= suart->cfg.rx_buf_size || suart->rx.flags) {
+ /* either the buffer is full, or we hit a parity and/or a framing error */
+ osmo_soft_uart_flush_rx(suart);
+ } else if (msg_len == 1) {
+ /* first character in new message: start timer */
osmo_timer_schedule(&suart->rx.timer, suart->cfg.rx_timeout_ms / 1000,
(suart->cfg.rx_timeout_ms % 1000) * 1000);
- } else if (msg_len >= suart->cfg.rx_buf_size || suart->rx.flags) {
- osmo_soft_uart_flush_rx(suart);
}
}
diff --git a/tests/soft_uart/soft_uart_test.ok b/tests/soft_uart/soft_uart_test.ok
index 7453d66..e670a0e 100644
--- a/tests/soft_uart/soft_uart_test.ok
+++ b/tests/soft_uart/soft_uart_test.ok
@@ -18,7 +18,8 @@
test_rx_exec() @ 96: flush the Rx buffer
suart_rx_cb(flags=00): 4f
======== test_rx(): testing 8-N-1 (framing errors)
-suart_rx_cb(flags=01): 00 aa
+suart_rx_cb(flags=01): 00
+suart_rx_cb(flags=01): aa
test_rx_exec() @ 41: flush the Rx buffer
suart_rx_cb(flags=00): ff
======== test_rx(): testing 8-N-2 (HELLO)
@@ -38,22 +39,28 @@
test_rx_exec() @ 112: flush the Rx buffer
suart_rx_cb(flags=00): 4f
======== test_rx(): testing 8-N-2 (framing errors)
-suart_rx_cb(flags=01): 00 aa
+suart_rx_cb(flags=01): 00
+suart_rx_cb(flags=01): aa
+suart_rx_cb(flags=01): 55
test_rx_exec() @ 57: flush the Rx buffer
-suart_rx_cb(flags=00): 55 ff
+suart_rx_cb(flags=00): ff
======== test_rx(): testing 8-E-1 (invalid parity)
-suart_rx_cb(flags=02): 00 01
-test_rx_exec() @ 49: flush the Rx buffer
+suart_rx_cb(flags=02): 00
+suart_rx_cb(flags=02): 01
suart_rx_cb(flags=02): ff
+test_rx_exec() @ 49: flush the Rx buffer
+suart_rx_cb(flags=02):
======== test_rx(): testing 8-E-1 (valid parity)
test_rx_exec() @ 63: flush the Rx buffer
suart_rx_cb(flags=00): 00 ff aa 55
test_rx_exec() @ 120: flush the Rx buffer
suart_rx_cb(flags=00): 80 e0 f8 fe
======== test_rx(): testing 8-O-1 (invalid parity)
-suart_rx_cb(flags=02): 00 01
-test_rx_exec() @ 42: flush the Rx buffer
+suart_rx_cb(flags=02): 00
+suart_rx_cb(flags=02): 01
suart_rx_cb(flags=02): ff
+test_rx_exec() @ 42: flush the Rx buffer
+suart_rx_cb(flags=02):
======== test_rx(): testing 8-O-1 (valid parity)
test_rx_exec() @ 63: flush the Rx buffer
suart_rx_cb(flags=00): 00 ff aa 55