fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/35045?usp=email )
Change subject: [WIP] soft_uart: implement OSMO_SUART_RX_MODE_N_FRAMES
......................................................................
[WIP] soft_uart: implement OSMO_SUART_RX_MODE_N_FRAMES
This is a hack allowing us to examine the receiver's internal buffer
without having to wait for a timeout to expire. I am not sure if
such mode would be useful for anything else. Maybe adding API to
access the Rx msgb would be a more flexible solution?
Change-Id: Ib3249a06c84f3ddb2723d0787db51873c4707d81
Related: OS#4396
---
M include/osmocom/core/soft_uart.h
M src/core/soft_uart.c
2 files changed, 67 insertions(+), 11 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/45/35045/1
diff --git a/include/osmocom/core/soft_uart.h b/include/osmocom/core/soft_uart.h
index 6088922..19af0cf 100644
--- a/include/osmocom/core/soft_uart.h
+++ b/include/osmocom/core/soft_uart.h
@@ -45,6 +45,14 @@
};
#endif
+/*! Rx data pulling mode */
+enum osmo_soft_uart_rx_mode {
+ /*! the .rx_cb() is called on timeout */
+ OSMO_SUART_RX_MODE_TIMEOUT,
+ /*! the .rx_cb() is called on a specified number of UART frames */
+ OSMO_SUART_RX_MODE_N_FRAMES,
+};
+
/* configuration for a soft-uart */
struct osmo_soft_uart_cfg {
/*! number of data bits (typically 5, 6, 7 or 8) */
@@ -53,14 +61,25 @@
uint8_t num_stop_bits;
/*! parity mode (none, even, odd) */
enum osmo_soft_uart_parity_mode parity_mode;
+
/*! size of transmit buffer */
unsigned int tx_buf_size;
- /*! size of receive buffer; UART will buffer up to that number of characters
- * before calling the receive call-back */
+ /*! size of receive buffer */
unsigned int rx_buf_size;
- /*! receive timeout; UART will flush receive buffer via the receive call-back
- * after indicated number of milli-seconds even if it is not full yet */
- unsigned int rx_timeout_ms;
+
+ /*! Rx data pulling mode */
+ enum osmo_soft_uart_rx_mode rx_pull_mode;
+ /*! Rx data pulling parameters */
+ union {
+ /*! receive timeout for OSMO_SUART_RX_MODE_TIMEOUT; UART will flush receive
+ * buffer via the receive call-back after indicated number of milli-seconds
+ * even if it is not full yet. */
+ unsigned int rx_timeout_ms;
+ /*! number of received UART frames for OSMO_SUART_RX_MODE_N_FRAMES; UART
+ * will flush receive buffer via the receive call-back after indicated number
+ * of UART frames had been received. */
+ unsigned int rx_n_uart_frames;
+ } rx_pull_param;
/*! opaque application-private data; passed to call-backs */
void *priv;
diff --git a/src/core/soft_uart.c b/src/core/soft_uart.c
index 9b6ca05..c7179a6 100644
--- a/src/core/soft_uart.c
+++ b/src/core/soft_uart.c
@@ -47,6 +47,7 @@
unsigned int flags;
unsigned int status;
struct osmo_timer_list timer;
+ unsigned int n_uart_frames;
enum suart_flow_state flow_state;
} rx;
struct {
@@ -71,7 +72,8 @@
.parity_mode = OSMO_SUART_PARITY_NONE,
.tx_buf_size = 1024,
.rx_buf_size = 1024,
- .rx_timeout_ms = 100,
+ .rx_pull_mode = OSMO_SUART_RX_MODE_TIMEOUT,
+ .rx_pull_param = { .rx_timeout_ms = 100 },
.priv = NULL,
.rx_cb = NULL,
.status_change_cb = NULL,
@@ -105,12 +107,29 @@
msgb_put_u8(suart->rx.msg, ch);
msg_len = msgb_length(suart->rx.msg);
- /* first character in new message: start timer */
- if (msg_len == 1) {
- 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) {
+ /* flush immediately:
+ * a) when the Rx buffer gets full;
+ * b) when a parity/framing error is occured. */
+ if (msg_len >= suart->cfg.rx_buf_size || suart->rx.flags) {
suart_flush_rx(suart);
+ return;
+ }
+
+ switch (suart->cfg.rx_pull_mode) {
+ case OSMO_SUART_RX_MODE_TIMEOUT:
+ /* first character in new message: start timer */
+ if (msg_len == 1) {
+ unsigned int rx_timeout_ms = suart->cfg.rx_pull_param.rx_timeout_ms;
+ osmo_timer_schedule(&suart->rx.timer, rx_timeout_ms / 1000,
+ (rx_timeout_ms % 1000) * 1000);
+ }
+ break;
+ case OSMO_SUART_RX_MODE_N_FRAMES:
+ if (suart->rx.n_uart_frames >= suart->cfg.rx_pull_param.rx_n_uart_frames) {
+ suart->rx.n_uart_frames = 0;
+ suart_flush_rx(suart);
+ }
+ break;
}
}
@@ -171,6 +190,7 @@
if (suart->rx.bit_count >= (suart->cfg.num_data_bits + suart->cfg.num_stop_bits)) {
/* we have accumulated enough stop bits */
+ suart->rx.n_uart_frames++;
suart_rx_ch(suart, suart->rx.shift_reg);
suart->rx.flow_state = SUART_FLOW_ST_IDLE;
}
@@ -358,10 +378,12 @@
if (cfg->rx_buf_size == 0)
return -EINVAL;
+#if 0
if (suart->cfg.rx_buf_size > cfg->rx_buf_size ||
suart->cfg.rx_timeout_ms > cfg->rx_timeout_ms) {
suart_flush_rx(suart);
}
+#endif
suart->cfg = *cfg;
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35045?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: Ib3249a06c84f3ddb2723d0787db51873c4707d81
Gerrit-Change-Number: 35045
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-MessageType: newchange
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/35019?usp=email )
Change subject: soft_uart: add doxygen documentation
......................................................................
soft_uart: add doxygen documentation
Change-Id: Ib0dcea0c35619bda5626cf75044000951b26485b
Related: OS#4396
---
M src/core/soft_uart.c
1 file changed, 42 insertions(+), 6 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/19/35019/1
diff --git a/src/core/soft_uart.c b/src/core/soft_uart.c
index e97ad2f..a668b21 100644
--- a/src/core/soft_uart.c
+++ b/src/core/soft_uart.c
@@ -26,7 +26,7 @@
#include <osmocom/core/timer.h>
#include <osmocom/core/soft_uart.h>
-/*! one instance of a soft-uart */
+/*! Internal state of a soft-UART */
struct osmo_soft_uart {
struct osmo_soft_uart_cfg cfg;
const char *name;
@@ -49,6 +49,7 @@
} tx;
};
+/*! Default soft-UART configuration (8-N-1) */
static struct osmo_soft_uart_cfg suart_default_cfg = {
.num_data_bits = 8,
.num_stop_bits = 1,
@@ -154,7 +155,11 @@
suart_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.
+ * \param[in] suart soft-UART instance to feed bits into.
+ * \param[in] ubits pointer to the unpacked bits.
+ * \param[in] n_ubits number of unpacked bits to be fed.
+ * \returns 0 on success; negative on error. */
int osmo_soft_uart_rx_ubits(struct osmo_soft_uart *suart, const ubit_t *ubits, size_t n_ubits)
{
for (size_t i = 0; i < n_ubits; i++) {
@@ -167,7 +172,9 @@
* Transmitter
*************************************************************************/
-/*! enqueue the given message buffer into the transmit queue of the UART. */
+/*! Enqueue the given message buffer into the transmit queue of the soft-UART.
+ * \param[in] suart soft-UART instance for transmitting data.
+ * \param[in] tx_data message buffer containing to be transmitted data. */
void osmo_soft_uart_tx(struct osmo_soft_uart *suart, struct msgb *tx_data)
{
if (!suart->tx.msg)
@@ -190,7 +197,11 @@
return 1;
}
-/*! pull then number of specified unpacked bits out of the UART Transmitter */
+/*! Pull a number of unpacked bits out of the soft-UART transmitter.
+ * \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 number of unpacked bits pulled; negative on error. */
int osmo_soft_uart_tx_ubits(struct osmo_soft_uart *suart, ubit_t *ubits, size_t n_ubits)
{
for (size_t i = 0; i < n_ubits; i++) {
@@ -199,7 +210,10 @@
return n_ubits;
}
-/*! Set the modem status lines of the UART */
+/*! Set the modem status lines of the given soft-UART.
+ * \param[in] suart soft-UART instance to update the modem status.
+ * \param[in] status mask of osmo_soft_uart_status.
+ * \returns 0 on success; negative on error. */
int osmo_soft_uart_set_status(struct osmo_soft_uart *suart, unsigned int status)
{
/* FIXME: Tx */
@@ -211,6 +225,10 @@
* Management / Initialization
*************************************************************************/
+/*! Allocate a soft-UART instance.
+ * \param[in] ctx parent talloc context.
+ * \param[in] name name of the soft-UART instance.
+ * \returns pointer to allocated soft-UART instance; NULL on error. */
struct osmo_soft_uart *osmo_soft_uart_alloc(void *ctx, const char *name)
{
struct osmo_soft_uart *suart = talloc_zero(ctx, struct osmo_soft_uart);
@@ -236,7 +254,10 @@
talloc_free(suart);
}
-/*! change soft-UART configuration to user-provided config */
+/*! Change soft-UART configuration to the user-provided config.
+ * \param[in] suart soft-UART instance to be re-configured.
+ * \param[in] cfg the user-provided config to be applied.
+ * \returns 0 on success; negative on error. */
int osmo_soft_uart_configure(struct osmo_soft_uart *suart, const struct osmo_soft_uart_cfg *cfg)
{
/* consistency checks on the configuration */
@@ -262,6 +283,11 @@
return 0;
}
+/*! Enable/disable receiver and/or transmitter 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.
+ * \returns 0 on success; negative on error. */
int osmo_soft_uart_enable(struct osmo_soft_uart *suart, bool rx, bool tx)
{
if (!rx && suart->rx.running) {
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35019?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: Ib0dcea0c35619bda5626cf75044000951b26485b
Gerrit-Change-Number: 35019
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-MessageType: newchange
Attention is currently required from: daniel.
fixeria has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/34967?usp=email )
Change subject: tests: Test gsmtap logging if write queue fills up
......................................................................
Patch Set 2:
(1 comment)
File tests/logging/logging_test_gsmtap.c:
https://gerrit.osmocom.org/c/libosmocore/+/34967/comment/0eccdc17_56efdb64
PS2, Line 3: 2008, 2009 by Holger Hans Peter Freyther <zecke(a)selfish.org>
I doubt it was Holger who wrote this test
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/34967?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: Id5ae0c4c3820a9ed59eaf4003d2c57b6bdfe3468
Gerrit-Change-Number: 34967
Gerrit-PatchSet: 2
Gerrit-Owner: daniel <dwillmann(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: arehbein <arehbein(a)sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Attention: daniel <dwillmann(a)sysmocom.de>
Gerrit-Comment-Date: Thu, 16 Nov 2023 06:57:55 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment