libosmocore 1.9.0.196-9975
Osmocom core library
sercomm.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <osmocom/core/msgb.h>
8
22};
23
29typedef void (*dlci_cb_t)(struct osmo_sercomm_inst *sercomm, uint8_t dlci, struct msgb *msg);
30
37
39 struct {
43 struct msgb *msg;
45 int state;
47 uint8_t *next_char;
48 } tx;
49
51 struct {
55 unsigned int msg_size;
57 struct msgb *msg;
59 int state;
61 uint8_t dlci;
63 uint8_t ctrl;
64 } rx;
65};
66
67
68void osmo_sercomm_init(struct osmo_sercomm_inst *sercomm);
70
71/* User Interface: Tx */
72void osmo_sercomm_sendmsg(struct osmo_sercomm_inst *sercomm, uint8_t dlci, struct msgb *msg);
73unsigned int osmo_sercomm_tx_queue_depth(struct osmo_sercomm_inst *sercomm, uint8_t dlci);
74
75/* User Interface: Rx */
76int osmo_sercomm_register_rx_cb(struct osmo_sercomm_inst *sercomm, uint8_t dlci, dlci_cb_t cb);
77
78int osmo_sercomm_change_speed(struct osmo_sercomm_inst *sercomm, uint32_t bdrt);
79
80/* Driver Interface */
81
82int osmo_sercomm_drv_pull(struct osmo_sercomm_inst *sercomm, uint8_t *ch);
83int osmo_sercomm_drv_rx_char(struct osmo_sercomm_inst *sercomm, uint8_t ch);
84
85extern void sercomm_drv_lock(unsigned long *flags);
86extern void sercomm_drv_unlock(unsigned long *flags);
87
96extern void sercomm_drv_start_tx(struct osmo_sercomm_inst *sercomm);
97
103extern int sercomm_drv_baudrate_chg(struct osmo_sercomm_inst *sercomm, uint32_t bdrt);
104
106static inline struct msgb *osmo_sercomm_alloc_msgb(unsigned int len)
107{
108 return msgb_alloc_headroom(len+4, 4, "sercomm_tx");
109}
110
static size_t len(const char *str)
static struct msgb * msgb_alloc_headroom(uint16_t size, uint16_t headroom, const char *name)
Allocate message buffer with specified headroom.
Definition: msgb.h:551
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:245
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:179
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:272
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:126
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...
static struct msgb * osmo_sercomm_alloc_msgb(unsigned int len)
Sercomm msgb allocator function.
Definition: sercomm.h:106
int osmo_sercomm_initialized(struct osmo_sercomm_inst *sercomm)
Determine if a given Osmocom sercomm instance has been initialized.
Definition: sercomm.c:92
void sercomm_drv_unlock(unsigned long *flags)
sercomm_dlci
A low sercomm_dlci means high priority.
Definition: sercomm.h:14
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:29
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:144
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:102
void osmo_sercomm_init(struct osmo_sercomm_inst *sercomm)
Initialize an Osmocom sercomm instance.
Definition: sercomm.c:74
void sercomm_drv_lock(unsigned long *flags)
int sercomm_drv_baudrate_chg(struct osmo_sercomm_inst *sercomm, uint32_t bdrt)
low-level driver routine to execute baud-rate change
@ SC_DLCI_HIGHEST
Definition: sercomm.h:15
@ SC_DLCI_L1A_L23
Definition: sercomm.h:17
@ SC_DLCI_ECHO
Definition: sercomm.h:20
@ SC_DLCI_CONSOLE
Definition: sercomm.h:19
@ SC_DLCI_DEBUG
Definition: sercomm.h:16
@ _SC_DLCI_MAX
Definition: sercomm.h:21
@ SC_DLCI_LOADER
Definition: sercomm.h:18
uint8_t msg[0]
(double) linked list header structure
Definition: linuxlist.h:46
Osmocom message buffer.
Definition: msgb.h:31
unsigned long cb[5]
control buffer
Definition: msgb.h:48
one instance of a sercomm multiplex/demultiplex
Definition: sercomm.h:32
unsigned int msg_size
msgb allocation size for rx msgs
Definition: sercomm.h:55
int initialized
Has this instance been initialized?
Definition: sercomm.h:34
struct llist_head dlci_queues[_SC_DLCI_MAX]
per-DLC queue of pending transmit msgbs
Definition: sercomm.h:41
struct msgb * msg
msgb currently being transmitted
Definition: sercomm.h:43
uint8_t dlci
DLCI of currently received msgb.
Definition: sercomm.h:61
uint8_t ctrl
CTRL of currently received msgb.
Definition: sercomm.h:63
int uart_id
UART Identifier.
Definition: sercomm.h:36
int state
transmit state
Definition: sercomm.h:45
struct osmo_sercomm_inst::@25 rx
receive side
uint8_t * next_char
next to-be-transmitted char in msg
Definition: sercomm.h:47
struct osmo_sercomm_inst::@24 tx
transmit side
dlci_cb_t dlci_handler[_SC_DLCI_MAX]
per-DLC handler call-back functions
Definition: sercomm.h:53