laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35204?usp=email )
Change subject: soft_uart: osmo_soft_uart_tx_ubits(): return number of bits pulled
......................................................................
soft_uart: osmo_soft_uart_tx_ubits(): return number of bits pulled
This is a partial revert of 0887188c6b133b69142965d65e1be8a0696a6272.
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
---
M src/core/soft_uart.c
M tests/soft_uart/soft_uart_test.c
2 files changed, 20 insertions(+), 4 deletions(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
osmith: Looks good to me, but someone else must approve
diff --git a/src/core/soft_uart.c b/src/core/soft_uart.c
index a1888d6..5750282 100644
--- a/src/core/soft_uart.c
+++ b/src/core/soft_uart.c
@@ -277,7 +277,7 @@
* \param[in] suart soft-UART instance to pull the bits from.
* \param[out] ubits pointer to a buffer where to store pulled bits.
* \param[in] n_ubits number of unpacked bits to be pulled.
- * \returns 0 on success; negative on error.
+ * \returns number of bits pulled; negative on error.
* -EAGAIN indicates that the transmitter is disabled. */
int osmo_soft_uart_tx_ubits(struct osmo_soft_uart *suart, ubit_t *ubits, size_t n_ubits)
{
@@ -318,7 +318,7 @@
ubits[i] = suart_tx_bit(suart, msg);
msgb_free(msg);
- return 0;
+ return n_ubits;
}
/*! Set the modem status lines of the given soft-UART.
diff --git a/tests/soft_uart/soft_uart_test.c b/tests/soft_uart/soft_uart_test.c
index 276ffe1..ef64855 100644
--- a/tests/soft_uart/soft_uart_test.c
+++ b/tests/soft_uart/soft_uart_test.c
@@ -217,7 +217,7 @@
int rc;
rc = osmo_soft_uart_tx_ubits(suart, &tx_buf[0], n_bits_total);
- OSMO_ASSERT(rc == 0);
+ OSMO_ASSERT(rc == n_bits_total);
rc = osmo_soft_uart_rx_ubits(suart, &tx_buf[0], n_bits_total);
OSMO_ASSERT(rc == 0);
@@ -332,7 +332,7 @@
printf("======== %s(): pulling %lu bits (%u at a time)\n", __func__, sizeof(tx_buf), n);
for (unsigned int i = 0; i < sizeof(tx_buf); i += n) {
rc = osmo_soft_uart_tx_ubits(suart, &tx_buf[i], n);
- OSMO_ASSERT(rc == 0);
+ OSMO_ASSERT(rc == n);
}
printf("%s\n", osmo_ubit_dump(&tx_buf[0], sizeof(tx_buf)));
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35204?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: I47a56f0fc36f2bc8f5a797d7fec64dfb56842388
Gerrit-Change-Number: 35204
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-MessageType: merged
laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35203?usp=email )
Change subject: soft_uart: improve doxygen documentation
......................................................................
soft_uart: improve doxygen documentation
Change-Id: I415a5e5392a7f91da4bf117d59694278779acc94
Related: OS#4396
---
M include/osmocom/core/soft_uart.h
1 file changed, 55 insertions(+), 24 deletions(-)
Approvals:
Jenkins Builder: Verified
osmith: Looks good to me, but someone else must approve
laforge: Looks good to me, approved
diff --git a/include/osmocom/core/soft_uart.h b/include/osmocom/core/soft_uart.h
index 7b7c394..17a7c67 100644
--- a/include/osmocom/core/soft_uart.h
+++ b/include/osmocom/core/soft_uart.h
@@ -25,19 +25,22 @@
#include <osmocom/core/bits.h>
#include <osmocom/core/msgb.h>
+/*! Parity mode.
+ * https://en.wikipedia.org/wiki/Parity_bit */
enum osmo_soft_uart_parity_mode {
- OSMO_SUART_PARITY_NONE,
- OSMO_SUART_PARITY_EVEN,
- OSMO_SUART_PARITY_ODD,
- OSMO_SUART_PARITY_MARK, /* always 1 */
- OSMO_SUART_PARITY_SPACE, /* always 0 */
+ OSMO_SUART_PARITY_NONE, /*!< No parity bit */
+ OSMO_SUART_PARITY_EVEN, /*!< Even parity */
+ OSMO_SUART_PARITY_ODD, /*!< Odd parity */
+ OSMO_SUART_PARITY_MARK, /*!< Always 1 */
+ OSMO_SUART_PARITY_SPACE, /*!< Always 0 */
_OSMO_SUART_PARITY_NUM
};
+/*! Flags passed to the application. */
enum osmo_soft_uart_flags {
- OSMO_SUART_F_FRAMING_ERROR = (1 << 0),
- OSMO_SUART_F_PARITY_ERROR = (1 << 1),
- OSMO_SUART_F_BREAK = (1 << 2),
+ OSMO_SUART_F_FRAMING_ERROR = (1 << 0), /*!< Framing error occurred */
+ OSMO_SUART_F_PARITY_ERROR = (1 << 1), /*!< Parity error occurred */
+ OSMO_SUART_F_BREAK = (1 << 2), /*!< Break condition (not implemented) */
};
#if 0
@@ -47,35 +50,53 @@
};
#endif
-/* configuration for a soft-uart */
+/*! Configuration for a soft-UART. */
struct osmo_soft_uart_cfg {
- /*! number of data bits (typically 5, 6, 7 or 8) */
+ /*! Number of data bits (typically 5, 6, 7 or 8). */
uint8_t num_data_bits;
- /*! number of stop bits (typically 1 or 2) */
+ /*! Number of stop bits (typically 1 or 2). */
uint8_t num_stop_bits;
- /*! parity mode (none, even, odd) */
+ /*! Parity mode (none, even, odd, space, mark). */
enum osmo_soft_uart_parity_mode parity_mode;
- /*! size of receive buffer; UART will buffer up to that number of characters
- * before calling the receive call-back */
+ /*! Size of the receive buffer; UART will buffer up to that number
+ * of characters before calling the receive call-back. */
unsigned int rx_buf_size;
- /*! receive timeout; UART will flush receive buffer via the receive call-back
- * after indicated number of milliseconds even if it is not full yet */
+ /*! Receive timeout; UART will flush the receive buffer via the receive call-back
+ * after indicated number of milliseconds, even if it is not full yet. */
unsigned int rx_timeout_ms;
- /*! opaque application-private data; passed to call-backs */
+ /*! Opaque application-private data; passed to call-backs. */
void *priv;
- /*! receive call-back. Either rx_buf_size characters were received or rx_timeout_ms
- * expired, or an error flag was detected (related to last byte received).
- * 'flags' is a bit-mask of osmo_soft_uart_flags, */
+ /*! Receive call-back of the application.
+ *
+ * Called if at least one of the following conditions is met:
+ * a) rx_buf_size characters were received (Rx buffer is full);
+ * b) rx_timeout_ms expired and Rx buffer is not empty;
+ * c) a parity or framing error is occurred.
+ *
+ * \param[in] priv opaque application-private data.
+ * \param[in] rx_data msgb holding the received data.
+ * Must be free()ed by the application.
+ * \param[in] flags bit-mask of OSMO_SUART_F_*. */
void (*rx_cb)(void *priv, struct msgb *rx_data, unsigned int flags);
- /*! transmit call-back. The implementation is expected to provide at most
- * tx_data->data_len characters (the actual amount is determined by the
- * number of requested bits and the effective UART configuration). */
+ /*! Transmit call-back of the application.
+ *
+ * The implementation is expected to provide at most tx_data->data_len
+ * characters (the actual amount is determined by the number of requested
+ * bits and the effective UART configuration).
+ *
+ * \param[in] priv opaque application-private data.
+ * \param[inout] tx_data msgb for writing to be transmitted data. */
void (*tx_cb)(void *priv, struct msgb *tx_data);
- /*! modem status line change call-back. gets bitmask of osmo_soft_uart_status */
+ /*! Modem status line change call-back.
+ *
+ * FIXME: flow control is not implemented, so it's never called.
+ *
+ * \param[in] priv opaque application-private data.
+ * \param[in] status bit-mask of osmo_soft_uart_status. */
void (*status_change_cb)(void *priv, unsigned int status);
};
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35203?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: I415a5e5392a7f91da4bf117d59694278779acc94
Gerrit-Change-Number: 35203
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-MessageType: merged
Attention is currently required from: fixeria.
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35202?usp=email )
Change subject: soft_uart: cosmetic: do not use 'osmo_' prefix for static symbols
......................................................................
Patch Set 1: Code-Review+2
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35202?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: I2b450b715dbfd0f8d6ddb4994ae0be3b890ed4fc
Gerrit-Change-Number: 35202
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Comment-Date: Mon, 04 Dec 2023 08:41:51 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: neels, osmith.
laforge has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35207?usp=email )
Change subject: util: add osmo_strbuf macros to manipulate the strbuf tail
......................................................................
Patch Set 1:
(1 comment)
File include/osmocom/core/utils.h:
https://gerrit.osmocom.org/c/libosmocore/+/35207/comment/8bd00d27_a19b74f8
PS1, Line 329: } while (0)
> What is the advantage of having these long macros instead of turning them into (probably more readab […]
I agree. I don't really see anything in the macro at first glance which couldn't be achieved in a function, or at least an inline function. The use of macros should be constrained to situations where we really need to solve something that's not super trivial and not possible in an (if needed, inline) funtion.
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35207?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: I997707c328eab3ffa00a78fdb9a0a2cbe18404b4
Gerrit-Change-Number: 35207
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-CC: laforge <laforge(a)osmocom.org>
Gerrit-Attention: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Comment-Date: Mon, 04 Dec 2023 08:40:06 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: osmith <osmith(a)sysmocom.de>
Gerrit-MessageType: comment