soft_uart: allow manually flushing the receive buffer

Change-Id: Id600a2db99e6cb84866cbdcfcd4f78265e067291
Related: OS#4396
This commit is contained in:
Vadim Yanitskiy 2023-11-18 00:29:08 +07:00
parent c9fc77f541
commit 03f0ed78ef
3 changed files with 9 additions and 6 deletions

View File

@ -92,3 +92,4 @@ int osmo_soft_uart_rx_ubits(struct osmo_soft_uart *suart, const ubit_t *ubits, s
int osmo_soft_uart_tx_ubits(struct osmo_soft_uart *suart, ubit_t *ubits, size_t n_ubits); 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); 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);

View File

@ -448,6 +448,7 @@ osmo_soft_uart_set_tx;
osmo_soft_uart_rx_ubits; osmo_soft_uart_rx_ubits;
osmo_soft_uart_tx_ubits; osmo_soft_uart_tx_ubits;
osmo_soft_uart_set_status; osmo_soft_uart_set_status;
osmo_soft_uart_flush_rx;
osmo_stat_item_dec; osmo_stat_item_dec;
osmo_stat_item_flush; osmo_stat_item_flush;
osmo_stat_item_for_each_group; osmo_stat_item_for_each_group;

View File

@ -72,8 +72,9 @@ const struct osmo_soft_uart_cfg osmo_soft_uart_default_cfg = {
* Receiver * Receiver
*************************************************************************/ *************************************************************************/
/* flush the receive buffer + allocate new one, as needed */ /*! Flush the receive buffer, passing ownership of the msgb to the .rx_cb().
static void suart_flush_rx(struct osmo_soft_uart *suart) * \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) { if ((suart->rx.msg && msgb_length(suart->rx.msg)) || suart->rx.flags) {
osmo_timer_del(&suart->rx.timer); osmo_timer_del(&suart->rx.timer);
@ -101,7 +102,7 @@ static void suart_rx_ch(struct osmo_soft_uart *suart, uint8_t ch)
osmo_timer_schedule(&suart->rx.timer, suart->cfg.rx_timeout_ms / 1000, osmo_timer_schedule(&suart->rx.timer, suart->cfg.rx_timeout_ms / 1000,
(suart->cfg.rx_timeout_ms % 1000) * 1000); (suart->cfg.rx_timeout_ms % 1000) * 1000);
} else if (msg_len >= suart->cfg.rx_buf_size || suart->rx.flags) { } 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 inline void osmo_uart_rx_bit(struct osmo_soft_uart *suart, const ubit_t b
static void suart_rx_timer_cb(void *data) static void suart_rx_timer_cb(void *data)
{ {
struct osmo_soft_uart *suart = 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. /*! Feed a number of unpacked bits into the soft-UART receiver.
@ -349,7 +350,7 @@ int osmo_soft_uart_configure(struct osmo_soft_uart *suart, const struct osmo_sof
if (suart->cfg.rx_buf_size > cfg->rx_buf_size || if (suart->cfg.rx_buf_size > cfg->rx_buf_size ||
suart->cfg.rx_timeout_ms > cfg->rx_timeout_ms) { suart->cfg.rx_timeout_ms > cfg->rx_timeout_ms) {
suart_flush_rx(suart); osmo_soft_uart_flush_rx(suart);
} }
suart->cfg = *cfg; suart->cfg = *cfg;
@ -366,7 +367,7 @@ int osmo_soft_uart_configure(struct osmo_soft_uart *suart, const struct osmo_sof
int osmo_soft_uart_set_rx(struct osmo_soft_uart *suart, bool enable) int osmo_soft_uart_set_rx(struct osmo_soft_uart *suart, bool enable)
{ {
if (!enable && suart->rx.running) { if (!enable && suart->rx.running) {
suart_flush_rx(suart); osmo_soft_uart_flush_rx(suart);
suart->rx.running = false; suart->rx.running = false;
suart->rx.flow_state = SUART_FLOW_ST_IDLE; suart->rx.flow_state = SUART_FLOW_ST_IDLE;
} else if (enable && !suart->rx.running) { } else if (enable && !suart->rx.running) {