diff options
author | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2023-11-16 15:17:37 +0700 |
---|---|---|
committer | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2023-11-21 00:58:53 +0700 |
commit | cdde67186b6b46ca102b6a13fc4a202a622fea57 (patch) | |
tree | 998400e378113474bb60c19b2ffc7b394e838c37 /src | |
parent | b72625d40e890bc42a3074b9af18a77ef0f568d3 (diff) |
soft_uart: split osmo_soft_uart_enable()
The problem with a single function controlling both Rx and Tx is
that enabling/disabling one of the directions requires knowing
state of the other one. In other words, disabling Tx requires
knowing the state of Rx, which may be inconvenient.
Change-Id: Ieacc7e639304eeb14fdb298c7e14d772c136ca6e
Related: OS#4396
Diffstat (limited to 'src')
-rw-r--r-- | src/core/libosmocore.map | 3 | ||||
-rw-r--r-- | src/core/soft_uart.c | 24 |
2 files changed, 18 insertions, 9 deletions
diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map index 142e4c42..e2aef390 100644 --- a/src/core/libosmocore.map +++ b/src/core/libosmocore.map @@ -442,7 +442,8 @@ osmo_sock_unix_init_ofd; osmo_soft_uart_alloc; osmo_soft_uart_free; osmo_soft_uart_configure; -osmo_soft_uart_enable; +osmo_soft_uart_set_rx; +osmo_soft_uart_set_tx; osmo_soft_uart_rx_ubits; osmo_soft_uart_tx_ubits; osmo_soft_uart_tx; diff --git a/src/core/soft_uart.c b/src/core/soft_uart.c index e6dfe3dd..2f098457 100644 --- a/src/core/soft_uart.c +++ b/src/core/soft_uart.c @@ -281,26 +281,34 @@ int osmo_soft_uart_configure(struct osmo_soft_uart *suart, const struct osmo_sof return 0; } -/*! Enable/disable receiver and/or transmitter of the given soft-UART. +/*! Enable/disable receiver of the given soft-UART. * \param[in] suart soft-UART instance to be re-configured. - * \param[in] rx enable/disable state of the receiver. - * \param[in] tx enable/disable state of the transmitter. + * \param[in] enable enable/disable state of the receiver. * \returns 0 on success; negative on error. */ -int osmo_soft_uart_enable(struct osmo_soft_uart *suart, bool rx, bool tx) +int osmo_soft_uart_set_rx(struct osmo_soft_uart *suart, bool enable) { - if (!rx && suart->rx.running) { + if (!enable && suart->rx.running) { suart_flush_rx(suart); suart->rx.running = false; - } else if (rx && !suart->rx.running) { + } else if (enable && !suart->rx.running) { if (!suart->rx.msg) suart->rx.msg = msgb_alloc_c(suart, suart->cfg.rx_buf_size, "soft_uart rx"); suart->rx.running = true; } - if (!tx && suart->tx.running) { + return 0; +} + +/*! Enable/disable transmitter of the given soft-UART. + * \param[in] suart soft-UART instance to be re-configured. + * \param[in] enable enable/disable state of the transmitter. + * \returns 0 on success; negative on error. */ +int osmo_soft_uart_set_tx(struct osmo_soft_uart *suart, bool enable) +{ + if (!enable && suart->tx.running) { /* FIXME: Tx */ suart->tx.running = false; - } else if (tx && !suart->tx.running) { + } else if (enable && !suart->tx.running) { suart->tx.running = true; } |