Initial import of OsmocomBB into git repository
[osmocom-bb.git] / src / target / firmware / include / comm / sercomm.h
1 #ifndef _SERCOMM_H
2 #define _SERCOMM_H
3
4 /* SERCOMM layer on UART1 (modem UART) */
5
6 #ifdef HOST_BUILD
7 #include <osmocom/msgb.h>
8 #else
9 #include <comm/msgb.h>
10 #define SERCOMM_UART_NR 1
11 #endif
12
13 #define HDLC_FLAG       0x7E
14 #define HDLC_ESCAPE     0x7D
15
16 #define HDLC_C_UI       0x03
17 #define HDLC_C_P_BIT    (1 << 4)
18 #define HDLC_C_F_BIT    (1 << 4)
19
20 /* a low sercomm_dlci means high priority.  A high DLCI means low priority */
21 enum sercomm_dlci {
22         SC_DLCI_HIGHEST = 0,
23         SC_DLCI_L1A_L23 = 5,
24         SC_DLCI_CONSOLE = 10,
25         _SC_DLCI_MAX
26 };
27
28 void sercomm_init(void);
29 int sercomm_initialized(void);
30
31 /* User Interface: Tx */
32
33 /* user interface for transmitting messages for a given DLCI */
34 void sercomm_sendmsg(uint8_t dlci, struct msgb *msg);
35 /* how deep is the Tx queue for a given DLCI */
36 unsigned int sercomm_tx_queue_depth(uint8_t dlci);
37
38 /* User Interface: Rx */
39
40 /* receiving messages for a given DLCI */
41 typedef void (*dlci_cb_t)(uint8_t dlci, struct msgb *msg);
42 int sercomm_register_rx_cb(uint8_t dlci, dlci_cb_t cb);
43
44 /* Driver Interface */
45
46 /* fetch one octet of to-be-transmitted serial data. returns 0 if no more data */
47 int sercomm_drv_pull(uint8_t *ch);
48 /* the driver has received one byte, pass it into sercomm layer.
49    returns 1 in case of success, 0 in case of unrecognized char */
50 int sercomm_drv_rx_char(uint8_t ch);
51
52 static inline struct msgb *sercomm_alloc_msgb(unsigned int len)
53 {
54         return msgb_alloc_headroom(len, 4, "sercomm_tx");
55 }
56
57 #endif /* _SERCOMM_H */