fixeria has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/35064?usp=email )


Change subject: soft_uart: allow manually flushing the receive buffer
......................................................................

soft_uart: allow manually flushing the receive buffer

Change-Id: Id600a2db99e6cb84866cbdcfcd4f78265e067291
Related: OS#4396
---
M include/osmocom/core/soft_uart.h
M src/core/libosmocore.map
M src/core/soft_uart.c
3 files changed, 19 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/64/35064/1

diff --git a/include/osmocom/core/soft_uart.h b/include/osmocom/core/soft_uart.h
index 2e5b215..028f029 100644
--- a/include/osmocom/core/soft_uart.h
+++ b/include/osmocom/core/soft_uart.h
@@ -94,3 +94,4 @@
 int osmo_soft_uart_tx_ubits(struct osmo_soft_uart *suart, ubit_t *ubits, 
size_t n_ubits);

 int osmo_soft_uart_set_status(struct osmo_soft_uart *suart, unsigned int 
status);
+void osmo_soft_uart_flush_rx(struct osmo_soft_uart *suart);
diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map
index e6a1866..ae8a068 100644
--- a/src/core/libosmocore.map
+++ b/src/core/libosmocore.map
@@ -448,6 +448,7 @@
 osmo_soft_uart_rx_ubits;
 osmo_soft_uart_tx_ubits;
 osmo_soft_uart_set_status;
+osmo_soft_uart_flush_rx;
 osmo_stat_item_dec;
 osmo_stat_item_flush;
 osmo_stat_item_for_each_group;
diff --git a/src/core/soft_uart.c b/src/core/soft_uart.c
index cf6e3be..d8be0c0 100644
--- a/src/core/soft_uart.c
+++ b/src/core/soft_uart.c
@@ -72,8 +72,9 @@
  * Receiver
  *************************************************************************/

-/* flush the receive buffer + allocate new one, as needed */
-static void suart_flush_rx(struct osmo_soft_uart *suart)
+/*! Flush the receive buffer, passing ownership of the msgb to the .rx_cb().
+ * \param[in] suart soft-UART instance holding the receive buffer. */
+void osmo_soft_uart_flush_rx(struct osmo_soft_uart *suart)
 {
        if ((suart->rx.msg && msgb_length(suart->rx.msg)) || suart->rx.flags) {
                osmo_timer_del(&suart->rx.timer);
@@ -101,7 +102,7 @@
                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) {
-               suart_flush_rx(suart);
+               osmo_soft_uart_flush_rx(suart);
        }
 }

@@ -173,7 +174,7 @@
 static void suart_rx_timer_cb(void *data)
 {
        struct osmo_soft_uart *suart = data;
-       suart_flush_rx(suart);
+       osmo_soft_uart_flush_rx(suart);
 }

 /*! Feed a number of unpacked bits into the soft-UART receiver.
@@ -349,7 +350,7 @@

        if (suart->cfg.rx_buf_size > cfg->rx_buf_size ||
            suart->cfg.rx_timeout_ms > cfg->rx_timeout_ms) {
-               suart_flush_rx(suart);
+               osmo_soft_uart_flush_rx(suart);
        }

        suart->cfg = *cfg;
@@ -366,7 +367,7 @@
 int osmo_soft_uart_set_rx(struct osmo_soft_uart *suart, bool enable)
 {
        if (!enable && suart->rx.running) {
-               suart_flush_rx(suart);
+               osmo_soft_uart_flush_rx(suart);
                suart->rx.running = false;
                suart->rx.flow_state = SUART_FLOW_ST_IDLE;
        } else if (enable && !suart->rx.running) {

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35064?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Id600a2db99e6cb84866cbdcfcd4f78265e067291
Gerrit-Change-Number: 35064
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanits...@sysmocom.de>
Gerrit-MessageType: newchange

Reply via email to