libosmocore 1.9.0.67-be3c3.202312012026
Osmocom core library
soft_uart.h
Go to the documentation of this file.
1#pragma once
2
5/*
6 * (C) 2022 by Harald Welte <laforge@gnumonks.org>
7 *
8 * All Rights Reserved
9 *
10 * SPDX-License-Identifier: GPL-2.0+
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 */
23
24#include <stdint.h>
25#include <osmocom/core/bits.h>
26#include <osmocom/core/msgb.h>
27
32 OSMO_SUART_PARITY_MARK, /* always 1 */
35};
36
41};
42
43#if 0
44enum osmo_soft_uart_status {
45 /* RTS, CTS, ... */
46 _fixme,
47};
48#endif
49
50/* configuration for a soft-uart */
60 unsigned int rx_buf_size;
63 unsigned int rx_timeout_ms;
64
66 void *priv;
67
71 void (*rx_cb)(void *priv, struct msgb *rx_data, unsigned int flags);
72
76 void (*tx_cb)(void *priv, struct msgb *tx_data);
77
79 void (*status_change_cb)(void *priv, unsigned int status);
80};
81
83
84struct osmo_soft_uart;
85
86struct osmo_soft_uart *osmo_soft_uart_alloc(void *ctx, const char *name,
87 const struct osmo_soft_uart_cfg *cfg);
88void osmo_soft_uart_free(struct osmo_soft_uart *suart);
89int osmo_soft_uart_configure(struct osmo_soft_uart *suart, const struct osmo_soft_uart_cfg *cfg);
90int osmo_soft_uart_set_rx(struct osmo_soft_uart *suart, bool enable);
91int osmo_soft_uart_set_tx(struct osmo_soft_uart *suart, bool enable);
92
93int osmo_soft_uart_rx_ubits(struct osmo_soft_uart *suart, const ubit_t *ubits, size_t n_ubits);
94int osmo_soft_uart_tx_ubits(struct osmo_soft_uart *suart, ubit_t *ubits, size_t n_ubits);
95
96int osmo_soft_uart_set_status(struct osmo_soft_uart *suart, unsigned int status);
97void osmo_soft_uart_flush_rx(struct osmo_soft_uart *suart);
Osmocom bit level support code.
uint16_t flags
const char * name
uint8_t ubit_t
unpacked bit (0 or 1): 1 bit per byte
Definition: bits.h:24
struct osmo_soft_uart * osmo_soft_uart_alloc(void *ctx, const char *name, const struct osmo_soft_uart_cfg *cfg)
Allocate a soft-UART instance.
Definition: soft_uart.c:343
int osmo_soft_uart_set_tx(struct osmo_soft_uart *suart, bool enable)
Enable/disable transmitter of the given soft-UART.
Definition: soft_uart.c:423
int osmo_soft_uart_set_rx(struct osmo_soft_uart *suart, bool enable)
Enable/disable receiver of the given soft-UART.
Definition: soft_uart.c:403
void osmo_soft_uart_flush_rx(struct osmo_soft_uart *suart)
Flush the receive buffer, passing ownership of the msgb to the .rx_cb().
Definition: soft_uart.c:78
void osmo_soft_uart_free(struct osmo_soft_uart *suart)
Release memory taken by the given soft-UART.
Definition: soft_uart.c:359
int osmo_soft_uart_tx_ubits(struct osmo_soft_uart *suart, ubit_t *ubits, size_t n_ubits)
Pull a number of unpacked bits out of the soft-UART transmitter.
Definition: soft_uart.c:284
const struct osmo_soft_uart_cfg osmo_soft_uart_default_cfg
Default soft-UART configuration (8-N-1)
Definition: soft_uart.c:64
osmo_soft_uart_parity_mode
Definition: soft_uart.h:28
@ _OSMO_SUART_PARITY_NUM
Definition: soft_uart.h:34
@ OSMO_SUART_PARITY_SPACE
Definition: soft_uart.h:33
@ OSMO_SUART_PARITY_EVEN
Definition: soft_uart.h:30
@ OSMO_SUART_PARITY_ODD
Definition: soft_uart.h:31
@ OSMO_SUART_PARITY_MARK
Definition: soft_uart.h:32
@ OSMO_SUART_PARITY_NONE
Definition: soft_uart.h:29
osmo_soft_uart_flags
Definition: soft_uart.h:37
@ OSMO_SUART_F_BREAK
Definition: soft_uart.h:40
@ OSMO_SUART_F_PARITY_ERROR
Definition: soft_uart.h:39
@ OSMO_SUART_F_FRAMING_ERROR
Definition: soft_uart.h:38
int osmo_soft_uart_rx_ubits(struct osmo_soft_uart *suart, const ubit_t *ubits, size_t n_ubits)
Feed a number of unpacked bits into the soft-UART receiver.
Definition: soft_uart.c:200
int osmo_soft_uart_set_status(struct osmo_soft_uart *suart, unsigned int status)
Set the modem status lines of the given soft-UART.
Definition: soft_uart.c:327
int osmo_soft_uart_configure(struct osmo_soft_uart *suart, const struct osmo_soft_uart_cfg *cfg)
Change soft-UART configuration to the user-provided config.
Definition: soft_uart.c:375
Osmocom message buffer.
Definition: msgb.h:31
Definition: soft_uart.h:51
uint8_t num_stop_bits
number of stop bits (typically 1 or 2)
Definition: soft_uart.h:55
enum osmo_soft_uart_parity_mode parity_mode
parity mode (none, even, odd)
Definition: soft_uart.h:57
void(* tx_cb)(void *priv, struct msgb *tx_data)
transmit call-back.
Definition: soft_uart.h:76
uint8_t num_data_bits
number of data bits (typically 5, 6, 7 or 8)
Definition: soft_uart.h:53
void(* rx_cb)(void *priv, struct msgb *rx_data, unsigned int flags)
receive call-back.
Definition: soft_uart.h:71
unsigned int rx_buf_size
size of receive buffer; UART will buffer up to that number of characters before calling the receive c...
Definition: soft_uart.h:60
void * priv
opaque application-private data; passed to call-backs
Definition: soft_uart.h:66
unsigned int rx_timeout_ms
receive timeout; UART will flush receive buffer via the receive call-back after indicated number of m...
Definition: soft_uart.h:63
void(* status_change_cb)(void *priv, unsigned int status)
modem status line change call-back.
Definition: soft_uart.h:79
Internal state of a soft-UART.
Definition: soft_uart.c:40
struct osmo_soft_uart_cfg cfg
Definition: soft_uart.c:41
unsigned int status
Definition: soft_uart.c:50