Commit Graph

14 Commits

Author SHA1 Message Date
Vadim Yanitskiy d8070f57d7 soft_uart: demonstrate a problem with inefficient polling
As outlined in the test case, we pull a total of 50 bits from the
transmitter in two rounds, pulling 25 bits at a time.  In the default
8-N-1 configuration, 50 bits should ideally comprise 5 characters.
However, as observed, only a total of 4 characters are retrieved
from the application, leaving the remaining 10 bits (5 + 5) unused.

Change-Id: Ic2539681a4adf6c1822e0bc256e4c829813d0e21
2023-12-11 20:49:24 +00:00
Vadim Yanitskiy b392099602 soft_uart: demonstrate a problem with manual flush()ing
This problem can only happen if the user is flush()ing the Rx buffer
manually by calling osmo_soft_uart_flush_rx().  Let's demonstrate it
in the unit test, so that we don't forget about it (add FIXME).

Change-Id: Iad932a505d6fd98360f90510651501f8708ff5d2
2023-12-11 20:49:24 +00:00
Vadim Yanitskiy d76cc3704e soft_uart: fix the Rx flushing logic, add a unit test
Coverity tells us that with the current logic it's possible (in theory)
that we may dereference NULL pointer in osmo_soft_uart_flush_rx().  This
is highly unlikely, because the Rx buffer gets allocated once when the
Rx is enabled and remains even after the Rx gets disabled.  The Rx flags
cannot be anything than 0x00 before the Rx gets enabled.

Even though this NULL pointer dereference is unlikely, the Rx flushing
logic is still not entirely correct.  As can be seen from the unit test
output, the Rx callback of the application may be called with an empty
msgb if the following conditions are both met:

a) the osmo_soft_uart_flush_rx() is invoked manually, and
b) a parity and/or a framing error has occurred previously.

We should not be checking suart->rx.flags in osmo_soft_uart_flush_rx(),
since this is already done in suart_rx_ch(), which is calling it.
Removing this check also eliminates a theoretical possibility of the
NULL pointer dereference, so we're killing two birds with one stone.

- Do not check suart->rx.flags in osmo_soft_uart_flush_rx().
- Add a unit test for various flush()ing scenarios.

Change-Id: I5179f5fd2361e4e96ac9bf48e80b99e53a7e4712
Fixes: CID#336545
2023-12-11 20:49:24 +00:00
Vadim Yanitskiy d0b575c059 tests/soft_uart: cosmetic: improve readability of the test output
Change-Id: Icf5410f0b292d41532e0cbd17e6ca0509c76cbd5
2023-12-10 11:20:40 +00:00
Vadim Yanitskiy c460deb2f1 tests/soft_uart: assert that osmo_soft_uart_rx_ubits() returns 0
According to Coverity, we check return value of this function in
all other cases except this one (9 out of 10 times), so let's add
the missing assert(), just to be sure.

Change-Id: I675f4089cc990be5fcda792276b6808742f6f0d7
Fixes: CID#336557
2023-12-10 11:20:40 +00:00
Vadim Yanitskiy 6587dd0abb soft_uart: implement modem status lines and flow control
Change-Id: I26b93ce76f2f6b6fbf017f2684312007db3c6d48
Related: OS#4396
2023-12-04 04:23:07 +07:00
Vadim Yanitskiy ffb8d5e026 soft_uart: osmo_soft_uart_tx_ubits(): return number of bits pulled
This is a partial revert of 0887188c6b.

We actually want to return number of bits pulled, because in the upcoming
commit implementing the flow control we want to be able to signal to the
caller that the buffer was not completely filled, but only partly.

Change-Id: I47a56f0fc36f2bc8f5a797d7fec64dfb56842388
Related: OS#4396
2023-12-04 03:17:34 +07:00
Vadim Yanitskiy 811638c005 soft_uart: check Rx/Tx state once in osmo_soft_uart_{rx,tx}_ubits()
Check it once rather than doing this in a loop.  Return -EAGAIN if
Rx or Tx is not enabled when calling osmo_soft_uart_{rx,tx}_ubits().

This [theoretically] improves performance by reducing the number of
conditional statements in loops.  In the Tx path, this also prevents
calling the .tx_cb() when the transmitter is disabled, so that we
don't loose the application data.

Change-Id: I70f93b3655eb21c2323e451052c40cd305c016c8
Related: OS#4396
2023-12-03 02:19:33 +00:00
Vadim Yanitskiy ffdd99779d soft_uart: fix pulling a small number of Tx bits
Change-Id: I454c8786697a6f2389d56b350e6e20ca953fe859
Related: OS#4396
2023-11-21 20:17:11 +07:00
Vadim Yanitskiy dab6629f1c soft_uart: demonstrate a problem with osmo_soft_uart_tx_ubits()
As can be seen, pulling a small number of bits at a time (smaller
than a single UART frame would fit into) results in calling the
.tx_cb() with a msgb having no room at all, and thus pulling the
stop bits instead of the actual data.

Change-Id: Icfee378f0fdc5e32fe9ce0afab5f75bc278653a9
Related: OS#4396
2023-11-21 20:17:11 +07:00
Vadim Yanitskiy 0d78a00b9f soft_uart: implement OSMO_SUART_PARITY_{MARK,SPACE}
Change-Id: I4c8fe5bfdcc2f4eb52c259d1e62d06684cd8f823
Related: OS#4396
2023-11-21 20:17:11 +07:00
Vadim Yanitskiy 2d2ce49e52 soft_uart: fix handling of num_data_bits < 8
Change-Id: Ife13b1f2d9063ba7253d01523ca9ecb15e9eaf07
Related: OS#4396
2023-11-21 20:17:11 +07:00
Vadim Yanitskiy bf95f82291 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
2023-11-21 20:17:11 +07:00
Vadim Yanitskiy 9ef304dd25 soft_uart: add unit tests for the receiver and transmitter
Change-Id: Icdfa0c644548964d37940c32dc9dcfcfc53c3a19
Related: OS#4396
2023-11-21 20:17:11 +07:00