libosmocore  1.5.1
Osmocom core library
sercomm.h
Go to the documentation of this file.
1 
5 #ifndef _SERCOMM_H
6 #define _SERCOMM_H
7 
8 #include <osmocom/core/msgb.h>
9 
21  SC_DLCI_ECHO = 128,
23 };
24 
25 struct osmo_sercomm_inst;
30 typedef void (*dlci_cb_t)(struct osmo_sercomm_inst *sercomm, uint8_t dlci, struct msgb *msg);
31 
37  int uart_id;
38 
40  struct {
44  struct msgb *msg;
46  int state;
48  uint8_t *next_char;
49  } tx;
50 
52  struct {
56  unsigned int msg_size;
58  struct msgb *msg;
60  int state;
62  uint8_t dlci;
64  uint8_t ctrl;
65  } rx;
66 };
67 
68 
69 void osmo_sercomm_init(struct osmo_sercomm_inst *sercomm);
70 int osmo_sercomm_initialized(struct osmo_sercomm_inst *sercomm);
71 
72 /* User Interface: Tx */
73 void osmo_sercomm_sendmsg(struct osmo_sercomm_inst *sercomm, uint8_t dlci, struct msgb *msg);
74 unsigned int osmo_sercomm_tx_queue_depth(struct osmo_sercomm_inst *sercomm, uint8_t dlci);
75 
76 /* User Interface: Rx */
77 int osmo_sercomm_register_rx_cb(struct osmo_sercomm_inst *sercomm, uint8_t dlci, dlci_cb_t cb);
78 
79 int osmo_sercomm_change_speed(struct osmo_sercomm_inst *sercomm, uint32_t bdrt);
80 
81 /* Driver Interface */
82 
83 int osmo_sercomm_drv_pull(struct osmo_sercomm_inst *sercomm, uint8_t *ch);
84 int osmo_sercomm_drv_rx_char(struct osmo_sercomm_inst *sercomm, uint8_t ch);
85 
86 extern void sercomm_drv_lock(unsigned long *flags);
87 extern void sercomm_drv_unlock(unsigned long *flags);
88 
97 extern void sercomm_drv_start_tx(struct osmo_sercomm_inst *sercomm);
98 
104 extern int sercomm_drv_baudrate_chg(struct osmo_sercomm_inst *sercomm, uint32_t bdrt);
105 
107 static inline struct msgb *osmo_sercomm_alloc_msgb(unsigned int len)
108 {
109  return msgb_alloc_headroom(len+4, 4, "sercomm_tx");
110 }
111 
114 #endif /* _SERCOMM_H */
osmo_sercomm_drv_rx_char
int osmo_sercomm_drv_rx_char(struct osmo_sercomm_inst *sercomm, uint8_t ch)
the driver has received one byte, pass it into sercomm layer
Definition: sercomm.c:276
SC_DLCI_ECHO
@ SC_DLCI_ECHO
Definition: sercomm.h:21
len
static size_t len(const char *str)
osmo_sercomm_init
void osmo_sercomm_init(struct osmo_sercomm_inst *sercomm)
Initialize an Osmocom sercomm instance.
Definition: sercomm.c:78
msgb_alloc_headroom
static struct msgb * msgb_alloc_headroom(int size, int headroom, const char *name)
Allocate message buffer with specified headroom.
Definition: msgb.h:549
osmo_sercomm_inst::dlci_queues
struct llist_head dlci_queues[_SC_DLCI_MAX]
per-DLC queue of pending transmit msgbs
Definition: sercomm.h:42
msg
uint8_t msg[0]
_SC_DLCI_MAX
@ _SC_DLCI_MAX
Definition: sercomm.h:22
msgb::cb
unsigned long cb[5]
control buffer
Definition: msgb.h:52
SC_DLCI_LOADER
@ SC_DLCI_LOADER
Definition: sercomm.h:19
osmo_sercomm_inst::initialized
int initialized
Has this instance been initialized?
Definition: sercomm.h:35
osmo_sercomm_drv_pull
int osmo_sercomm_drv_pull(struct osmo_sercomm_inst *sercomm, uint8_t *ch)
fetch one octet of to-be-transmitted serial data
Definition: sercomm.c:183
sercomm_drv_baudrate_chg
int sercomm_drv_baudrate_chg(struct osmo_sercomm_inst *sercomm, uint32_t bdrt)
low-level driver routine to execute baud-rate change
osmo_sercomm_inst::next_char
uint8_t * next_char
next to-be-transmitted char in msg
Definition: sercomm.h:48
SC_DLCI_L1A_L23
@ SC_DLCI_L1A_L23
Definition: sercomm.h:18
msgb
Osmocom message buffer.
Definition: msgb.h:35
osmo_sercomm_inst::ctrl
uint8_t ctrl
CTRL of currently received msgb.
Definition: sercomm.h:64
SC_DLCI_CONSOLE
@ SC_DLCI_CONSOLE
Definition: sercomm.h:20
SC_DLCI_DEBUG
@ SC_DLCI_DEBUG
Definition: sercomm.h:17
osmo_sercomm_initialized
int osmo_sercomm_initialized(struct osmo_sercomm_inst *sercomm)
Determine if a given Osmocom sercomm instance has been initialized.
Definition: sercomm.c:96
sercomm_drv_lock
void sercomm_drv_lock(unsigned long *flags)
osmo_sercomm_inst::dlci_handler
dlci_cb_t dlci_handler[_SC_DLCI_MAX]
per-DLC handler call-back functions
Definition: sercomm.h:54
osmo_sercomm_inst::msg
struct msgb * msg
msgb currently being transmitted
Definition: sercomm.h:44
SC_DLCI_HIGHEST
@ SC_DLCI_HIGHEST
Definition: sercomm.h:16
osmo_sercomm_inst::uart_id
int uart_id
UART Identifier.
Definition: sercomm.h:37
llist_head
(double) linked list header structure
Definition: linuxlist.h:46
msgb.h
sercomm_drv_start_tx
void sercomm_drv_start_tx(struct osmo_sercomm_inst *sercomm)
low-level driver routine to request start of transmission The Sercomm code calls this function to inf...
osmo_sercomm_inst::dlci
uint8_t dlci
DLCI of currently received msgb.
Definition: sercomm.h:62
osmo_sercomm_tx_queue_depth
unsigned int osmo_sercomm_tx_queue_depth(struct osmo_sercomm_inst *sercomm, uint8_t dlci)
How deep is the Tx queue for a given DLCI?
Definition: sercomm.c:130
osmo_sercomm_inst::state
int state
transmit state
Definition: sercomm.h:46
osmo_sercomm_inst
one instance of a sercomm multiplex/demultiplex
Definition: sercomm.h:33
osmo_sercomm_inst::msg_size
unsigned int msg_size
msgb allocation size for rx msgs
Definition: sercomm.h:56
sercomm_drv_unlock
void sercomm_drv_unlock(unsigned long *flags)
osmo_sercomm_change_speed
int osmo_sercomm_change_speed(struct osmo_sercomm_inst *sercomm, uint32_t bdrt)
wait until everything has been transmitted, then grab the lock and change the baud rate as requested
Definition: sercomm.c:148
osmo_sercomm_register_rx_cb
int osmo_sercomm_register_rx_cb(struct osmo_sercomm_inst *sercomm, uint8_t dlci, dlci_cb_t cb)
Register a handler for a given DLCI.
Definition: sercomm.c:249
osmo_sercomm_inst::tx
struct osmo_sercomm_inst::@18 tx
transmit side
osmo_sercomm_sendmsg
void osmo_sercomm_sendmsg(struct osmo_sercomm_inst *sercomm, uint8_t dlci, struct msgb *msg)
User interface for transmitting messages for a given DLCI.
Definition: sercomm.c:106
osmo_sercomm_inst::rx
struct osmo_sercomm_inst::@19 rx
receive side
osmo_sercomm_alloc_msgb
static struct msgb * osmo_sercomm_alloc_msgb(unsigned int len)
Sercomm msgb allocator function.
Definition: sercomm.h:107
sercomm_dlci
sercomm_dlci
A low sercomm_dlci means high priority.
Definition: sercomm.h:15
dlci_cb_t
void(* dlci_cb_t)(struct osmo_sercomm_inst *sercomm, uint8_t dlci, struct msgb *msg)
call-back function for per-DLC receive handler
Definition: sercomm.h:30