This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.orgHarald Welte has submitted this change and it was merged. Change subject: sercomm: Better integration of driver interface ...................................................................... sercomm: Better integration of driver interface We cannot assume a certain UART API like uart_baudrate() which only exists in OsmocomBB. Rather, use generic function prototypes (sercomm_drv_*) which are to be provided by the application / environment to the sercomm core. Change-Id: I01ea3067baf1791000c1a7d537ccce496a1ab1ee --- M include/osmocom/core/sercomm.h M src/sercomm.c 2 files changed, 24 insertions(+), 34 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified diff --git a/include/osmocom/core/sercomm.h b/include/osmocom/core/sercomm.h index 32b96c5..e263080 100644 --- a/include/osmocom/core/sercomm.h +++ b/include/osmocom/core/sercomm.h @@ -58,12 +58,6 @@ }; -#ifdef EMBEDDED -#include <uart.h> -/* helper functions for target */ -void osmo_sercomm_change_speed(struct osmo_sercomm_inst *sercomm, enum uart_baudrate bdrt); -#endif - void osmo_sercomm_init(struct osmo_sercomm_inst *sercomm); int osmo_sercomm_initialized(struct osmo_sercomm_inst *sercomm); @@ -74,11 +68,18 @@ /* User Interface: Rx */ int osmo_sercomm_register_rx_cb(struct osmo_sercomm_inst *sercomm, uint8_t dlci, dlci_cb_t cb); +int osmo_sercomm_change_speed(struct osmo_sercomm_inst *sercomm, uint32_t bdrt); + /* Driver Interface */ int osmo_sercomm_drv_pull(struct osmo_sercomm_inst *sercomm, uint8_t *ch); int osmo_sercomm_drv_rx_char(struct osmo_sercomm_inst *sercomm, uint8_t ch); +extern void sercomm_drv_lock(unsigned long *flags); +extern void sercomm_drv_unlock(unsigned long *flags); +extern void sercomm_drv_start_tx(struct osmo_sercomm_inst *sercomm); +extern int sercomm_drv_baudrate_chg(struct osmo_sercomm_inst *sercomm, uint32_t bdrt); + static inline struct msgb *osmo_sercomm_alloc_msgb(unsigned int len) { return msgb_alloc_headroom(len+4, 4, "sercomm_tx"); diff --git a/src/sercomm.c b/src/sercomm.c index f3241c4..409efba 100644 --- a/src/sercomm.c +++ b/src/sercomm.c @@ -20,6 +20,8 @@ * */ +#include "config.h" + #include <stdint.h> #include <stdio.h> #include <errno.h> @@ -30,30 +32,19 @@ #include <osmocom/core/linuxlist.h> #ifndef EMBEDDED - # define DEFAULT_RX_MSG_SIZE 2048 -static inline void sercomm_drv_lock(unsigned long __attribute__((unused)) *flags) {} -static inline void sercomm_drv_unlock(unsigned long __attribute__((unused)) *flags) {} - +void sercomm_drv_lock(unsigned long __attribute__((unused)) *flags) {} +void sercomm_drv_unlock(unsigned long __attribute__((unused)) *flags) {} #else - # define DEFAULT_RX_MSG_SIZE 256 -# include <debug.h> -# include <asm/system.h> +#endif /* EMBEDDED */ -static inline void sercomm_drv_lock(unsigned long *flags) +/* weak symbols to be overridden by application */ +__attribute__((weak)) void sercomm_drv_start_tx(struct osmo_sercomm_inst *sercomm) {}; +__attribute__((weak)) int sercomm_drv_baudrate_chg(struct osmo_sercomm_inst *sercomm, uint32_t bdrt) { - local_firq_save(*flags); + return -1; } - -static inline void sercomm_drv_unlock(unsigned long *flags) -{ - local_irq_restore(*flags); -} - -# include <uart.h> - -#endif #define HDLC_FLAG 0x7E #define HDLC_ESCAPE 0x7D @@ -107,10 +98,8 @@ msgb_enqueue(&sercomm->tx.dlci_queues[dlci], msg); sercomm_drv_unlock(&flags); -#ifdef EMBEDDED /* tell UART that we have something to send */ - uart_irq_enable(sercomm->uart_id, UART_IRQ_TX_EMPTY, 1); -#endif + sercomm_drv_start_tx(sercomm); } /* how deep is the Tx queue for a given DLCI */ @@ -126,10 +115,9 @@ return num; } -#ifdef EMBEDDED /* wait until everything has been transmitted, then grab the lock and * change the baud rate as requested */ -void osmo_sercomm_change_speed(struct osmo_sercomm_inst *sercomm, enum uart_baudrate bdrt) +int osmo_sercomm_change_speed(struct osmo_sercomm_inst *sercomm, uint32_t bdrt) { unsigned int i, count; unsigned long flags; @@ -138,7 +126,7 @@ /* count the number of pending messages */ count = 0; for (i = 0; i < ARRAY_SIZE(sercomm->tx.dlci_queues); i++) - count += sercomm_tx_queue_depth(i); + count += osmo_sercomm_tx_queue_depth(sercomm, i); /* if we still have any in the queue, restart */ if (count == 0) break; @@ -149,15 +137,16 @@ * stays that way */ sercomm_drv_lock(&flags); if (!sercomm->tx.msg && !sercomm->tx.next_char) { + int rc; /* change speed */ - uart_baudrate(sercomm->uart_id, bdrt); + rc = sercomm_drv_baudrate_chg(sercomm, bdrt); sercomm_drv_unlock(&flags); - break; - } + return rc; + } else sercomm_drv_unlock(&flags); } + return -1; } -#endif /*! \brief fetch one octet of to-be-transmitted serial data * \param[in] sercomm Sercomm Instance from which to fetch pending data -- To view, visit https://gerrit.osmocom.org/2645 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: merged Gerrit-Change-Id: I01ea3067baf1791000c1a7d537ccce496a1ab1ee Gerrit-PatchSet: 3 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Jenkins Builder