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
This commit is contained in:
Vadim Yanitskiy 2023-11-16 15:17:37 +07:00
parent b72625d40e
commit cdde67186b
3 changed files with 20 additions and 10 deletions

View File

@ -77,7 +77,8 @@ struct osmo_soft_uart;
struct osmo_soft_uart *osmo_soft_uart_alloc(void *ctx, const char *name);
void osmo_soft_uart_free(struct osmo_soft_uart *suart);
int osmo_soft_uart_configure(struct osmo_soft_uart *suart, const struct osmo_soft_uart_cfg *cfg);
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);
int osmo_soft_uart_set_tx(struct osmo_soft_uart *suart, bool enable);
int osmo_soft_uart_rx_ubits(struct osmo_soft_uart *suart, const 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);

View File

@ -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;

View File

@ -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;
}