Harald Welte | c68af6a | 2017-04-30 21:21:52 +0200 | [diff] [blame^] | 1 | #ifndef _SERCOMM_H |
| 2 | #define _SERCOMM_H |
| 3 | |
| 4 | #include <osmocom/core/msgb.h> |
| 5 | |
| 6 | #define HDLC_FLAG 0x7E |
| 7 | #define HDLC_ESCAPE 0x7D |
| 8 | |
| 9 | #define HDLC_C_UI 0x03 |
| 10 | #define HDLC_C_P_BIT (1 << 4) |
| 11 | #define HDLC_C_F_BIT (1 << 4) |
| 12 | |
| 13 | /* a low sercomm_dlci means high priority. A high DLCI means low priority */ |
| 14 | enum sercomm_dlci { |
| 15 | SC_DLCI_HIGHEST = 0, |
| 16 | SC_DLCI_DEBUG = 4, |
| 17 | SC_DLCI_L1A_L23 = 5, |
| 18 | SC_DLCI_LOADER = 9, |
| 19 | SC_DLCI_CONSOLE = 10, |
| 20 | SC_DLCI_ECHO = 128, |
| 21 | _SC_DLCI_MAX |
| 22 | }; |
| 23 | |
| 24 | #ifndef HOST_BUILD |
| 25 | #include <uart.h> |
| 26 | /* helper functions for target */ |
| 27 | void sercomm_bind_uart(int uart); |
| 28 | int sercomm_get_uart(void); |
| 29 | void sercomm_change_speed(enum uart_baudrate bdrt); |
| 30 | #endif |
| 31 | |
| 32 | void sercomm_init(void); |
| 33 | int sercomm_initialized(void); |
| 34 | |
| 35 | /* User Interface: Tx */ |
| 36 | |
| 37 | /* user interface for transmitting messages for a given DLCI */ |
| 38 | void sercomm_sendmsg(uint8_t dlci, struct msgb *msg); |
| 39 | /* how deep is the Tx queue for a given DLCI */ |
| 40 | unsigned int sercomm_tx_queue_depth(uint8_t dlci); |
| 41 | |
| 42 | /* User Interface: Rx */ |
| 43 | |
| 44 | /* receiving messages for a given DLCI */ |
| 45 | typedef void (*dlci_cb_t)(uint8_t dlci, struct msgb *msg); |
| 46 | int sercomm_register_rx_cb(uint8_t dlci, dlci_cb_t cb); |
| 47 | |
| 48 | /* Driver Interface */ |
| 49 | |
| 50 | /* fetch one octet of to-be-transmitted serial data. returns 0 if no more data */ |
| 51 | int sercomm_drv_pull(uint8_t *ch); |
| 52 | /* the driver has received one byte, pass it into sercomm layer. |
| 53 | returns 1 in case of success, 0 in case of unrecognized char */ |
| 54 | int sercomm_drv_rx_char(uint8_t ch); |
| 55 | |
| 56 | static inline struct msgb *sercomm_alloc_msgb(unsigned int len) |
| 57 | { |
| 58 | return msgb_alloc_headroom(len+4, 4, "sercomm_tx"); |
| 59 | } |
| 60 | |
| 61 | #endif /* _SERCOMM_H */ |