summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-04-30 21:21:52 +0200
committerHarald Welte <laforge@gnumonks.org>2017-05-17 10:46:39 +0000
commitc68af6a64bc762b570b84eb90401da0acc914ed4 (patch)
treeab5001386bc1100fb9e0707e98375d15bd677aad /include
parent1cd9991cf68eda563f65a7b8eda8e3cec5ed0859 (diff)
Import sercomm.c from osmocom-bb
This imports the file src/target/firmware/comm/sercomm.c from osmocom-bb.git without introducing any modifications. It will not even be built yet, as Makefile integration is intentionally left until it has been adapted to work inside libosmocore. Change-Id: I9ee199381c7b5986a9540d124836cdddd0f66c86
Diffstat (limited to 'include')
-rw-r--r--include/osmocom/core/sercomm.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/include/osmocom/core/sercomm.h b/include/osmocom/core/sercomm.h
new file mode 100644
index 00000000..21f715ba
--- /dev/null
+++ b/include/osmocom/core/sercomm.h
@@ -0,0 +1,61 @@
+#ifndef _SERCOMM_H
+#define _SERCOMM_H
+
+#include <osmocom/core/msgb.h>
+
+#define HDLC_FLAG 0x7E
+#define HDLC_ESCAPE 0x7D
+
+#define HDLC_C_UI 0x03
+#define HDLC_C_P_BIT (1 << 4)
+#define HDLC_C_F_BIT (1 << 4)
+
+/* a low sercomm_dlci means high priority. A high DLCI means low priority */
+enum sercomm_dlci {
+ SC_DLCI_HIGHEST = 0,
+ SC_DLCI_DEBUG = 4,
+ SC_DLCI_L1A_L23 = 5,
+ SC_DLCI_LOADER = 9,
+ SC_DLCI_CONSOLE = 10,
+ SC_DLCI_ECHO = 128,
+ _SC_DLCI_MAX
+};
+
+#ifndef HOST_BUILD
+#include <uart.h>
+/* helper functions for target */
+void sercomm_bind_uart(int uart);
+int sercomm_get_uart(void);
+void sercomm_change_speed(enum uart_baudrate bdrt);
+#endif
+
+void sercomm_init(void);
+int sercomm_initialized(void);
+
+/* User Interface: Tx */
+
+/* user interface for transmitting messages for a given DLCI */
+void sercomm_sendmsg(uint8_t dlci, struct msgb *msg);
+/* how deep is the Tx queue for a given DLCI */
+unsigned int sercomm_tx_queue_depth(uint8_t dlci);
+
+/* User Interface: Rx */
+
+/* receiving messages for a given DLCI */
+typedef void (*dlci_cb_t)(uint8_t dlci, struct msgb *msg);
+int sercomm_register_rx_cb(uint8_t dlci, dlci_cb_t cb);
+
+/* Driver Interface */
+
+/* fetch one octet of to-be-transmitted serial data. returns 0 if no more data */
+int sercomm_drv_pull(uint8_t *ch);
+/* the driver has received one byte, pass it into sercomm layer.
+ returns 1 in case of success, 0 in case of unrecognized char */
+int sercomm_drv_rx_char(uint8_t ch);
+
+static inline struct msgb *sercomm_alloc_msgb(unsigned int len)
+{
+ return msgb_alloc_headroom(len+4, 4, "sercomm_tx");
+}
+
+#endif /* _SERCOMM_H */