fixeria has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmocore/+/35021?usp=email )
Change subject: soft_uart: make osmo_soft_uart_alloc() accept *cfg
......................................................................
soft_uart: make osmo_soft_uart_alloc() accept *cfg
I cannot see how naming soft-UART instances would be useful, given
that currently we're not logging anything. What I find useful is
having access to the default configuration and being able to
configure soft-UART at the allocation time.
Change-Id: I7e78d60c747a8805064d5e4bacfd47a30bc65cba
Related: OS#4396
---
M include/osmocom/core/soft_uart.h
M src/core/libosmocore.map
M src/core/soft_uart.c
3 files changed, 23 insertions(+), 9 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/21/35021/1
diff --git a/include/osmocom/core/soft_uart.h b/include/osmocom/core/soft_uart.h
index 71846ed..df14648 100644
--- a/include/osmocom/core/soft_uart.h
+++ b/include/osmocom/core/soft_uart.h
@@ -74,7 +74,9 @@
struct osmo_soft_uart;
-struct osmo_soft_uart *osmo_soft_uart_alloc(void *ctx, const char *name);
+extern const struct osmo_soft_uart_cfg osmo_soft_uart_default_cfg;
+
+struct osmo_soft_uart *osmo_soft_uart_alloc(void *ctx, const struct osmo_soft_uart_cfg
*cfg);
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_set_rx(struct osmo_soft_uart *suart, bool enable);
diff --git a/src/core/libosmocore.map b/src/core/libosmocore.map
index e2aef39..a9d25fb 100644
--- a/src/core/libosmocore.map
+++ b/src/core/libosmocore.map
@@ -439,6 +439,7 @@
osmo_sock_set_priority;
osmo_sock_unix_init;
osmo_sock_unix_init_ofd;
+osmo_soft_uart_default_cfg;
osmo_soft_uart_alloc;
osmo_soft_uart_free;
osmo_soft_uart_configure;
diff --git a/src/core/soft_uart.c b/src/core/soft_uart.c
index fcc90b2..4633691 100644
--- a/src/core/soft_uart.c
+++ b/src/core/soft_uart.c
@@ -29,7 +29,6 @@
/*! Internal state of a soft-UART */
struct osmo_soft_uart {
struct osmo_soft_uart_cfg cfg;
- const char *name;
struct {
bool running;
uint8_t bit_count;
@@ -50,7 +49,7 @@
};
/*! Default soft-UART configuration (8-N-1) */
-static struct osmo_soft_uart_cfg suart_default_cfg = {
+const struct osmo_soft_uart_cfg osmo_soft_uart_default_cfg = {
.num_data_bits = 8,
.num_stop_bits = 1,
.parity_mode = OSMO_SUART_PARITY_NONE,
@@ -227,15 +226,14 @@
/*! Allocate a soft-UART instance.
* \param[in] ctx parent talloc context.
- * \param[in] name name of the soft-UART instance.
+ * \param[in] cfg initial configuration 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 *osmo_soft_uart_alloc(void *ctx, const struct osmo_soft_uart_cfg
*cfg)
{
struct osmo_soft_uart *suart = talloc_zero(ctx, struct osmo_soft_uart);
if (!suart)
return NULL;
- suart->name = talloc_strdup(suart, name);
- suart->cfg = suart_default_cfg;
+ suart->cfg = *cfg;
return suart;
}
@@ -249,8 +247,6 @@
osmo_timer_del(&suart->rx.timer);
msgb_free(suart->rx.msg);
-
- talloc_free((void *)suart->name);
talloc_free(suart);
}
--
To view, visit
https://gerrit.osmocom.org/c/libosmocore/+/35021?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: I7e78d60c747a8805064d5e4bacfd47a30bc65cba
Gerrit-Change-Number: 35021
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-MessageType: newchange