libosmocore 1.9.0.67-be3c3.202312012026
Osmocom core library
soft_uart.h File Reference

Software UART implementation. More...

#include <stdint.h>
#include <osmocom/core/bits.h>
#include <osmocom/core/msgb.h>

Go to the source code of this file.

Data Structures

struct  osmo_soft_uart_cfg
 

Enumerations

enum  osmo_soft_uart_parity_mode {
  OSMO_SUART_PARITY_NONE ,
  OSMO_SUART_PARITY_EVEN ,
  OSMO_SUART_PARITY_ODD ,
  OSMO_SUART_PARITY_MARK ,
  OSMO_SUART_PARITY_SPACE ,
  _OSMO_SUART_PARITY_NUM
}
 
enum  osmo_soft_uart_flags {
  OSMO_SUART_F_FRAMING_ERROR = (1 << 0) ,
  OSMO_SUART_F_PARITY_ERROR = (1 << 1) ,
  OSMO_SUART_F_BREAK = (1 << 2)
}
 

Functions

struct osmo_soft_uartosmo_soft_uart_alloc (void *ctx, const char *name, const struct osmo_soft_uart_cfg *cfg)
 Allocate a soft-UART instance. More...
 
void osmo_soft_uart_free (struct osmo_soft_uart *suart)
 Release memory taken by the given soft-UART. More...
 
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. More...
 
int osmo_soft_uart_set_rx (struct osmo_soft_uart *suart, bool enable)
 Enable/disable receiver of the given soft-UART. More...
 
int osmo_soft_uart_set_tx (struct osmo_soft_uart *suart, bool enable)
 Enable/disable transmitter of the given soft-UART. More...
 
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. More...
 
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. More...
 
int osmo_soft_uart_set_status (struct osmo_soft_uart *suart, unsigned int status)
 Set the modem status lines of the given soft-UART. More...
 
void osmo_soft_uart_flush_rx (struct osmo_soft_uart *suart)
 Flush the receive buffer, passing ownership of the msgb to the .rx_cb(). More...
 

Variables

const struct osmo_soft_uart_cfg osmo_soft_uart_default_cfg
 Default soft-UART configuration (8-N-1) More...
 

Detailed Description

Software UART implementation.

Enumeration Type Documentation

◆ osmo_soft_uart_flags

Enumerator
OSMO_SUART_F_FRAMING_ERROR 
OSMO_SUART_F_PARITY_ERROR 
OSMO_SUART_F_BREAK 

◆ osmo_soft_uart_parity_mode

Enumerator
OSMO_SUART_PARITY_NONE 
OSMO_SUART_PARITY_EVEN 
OSMO_SUART_PARITY_ODD 
OSMO_SUART_PARITY_MARK 
OSMO_SUART_PARITY_SPACE 
_OSMO_SUART_PARITY_NUM 

Function Documentation

◆ osmo_soft_uart_alloc()

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.

Parameters
[in]ctxparent talloc context.
[in]namename of the soft-UART instance.
[in]cfginitial configuration of the soft-UART instance.
Returns
pointer to allocated soft-UART instance; NULL on error.

References osmo_soft_uart::cfg, name, osmo_soft_uart::name, and OSMO_ASSERT.

◆ osmo_soft_uart_configure()

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.

Parameters
[in]suartsoft-UART instance to be re-configured.
[in]cfgthe user-provided config to be applied.
Returns
0 on success; negative on error.

References _OSMO_SUART_PARITY_NUM, osmo_soft_uart::cfg, osmo_soft_uart_cfg::num_data_bits, osmo_soft_uart_cfg::num_stop_bits, osmo_soft_uart_flush_rx(), osmo_timer_setup(), osmo_soft_uart_cfg::parity_mode, osmo_soft_uart::rx, osmo_soft_uart_cfg::rx_buf_size, osmo_soft_uart_cfg::rx_timeout_ms, suart_rx_timer_cb(), and osmo_soft_uart::timer.

◆ osmo_soft_uart_flush_rx()

void osmo_soft_uart_flush_rx ( struct osmo_soft_uart suart)

◆ osmo_soft_uart_free()

void osmo_soft_uart_free ( struct osmo_soft_uart suart)

Release memory taken by the given soft-UART.

Parameters
[in]suartsoft-UART instance to be free()d.

References osmo_soft_uart::msg, msgb_free(), osmo_soft_uart::name, osmo_timer_del(), osmo_soft_uart::rx, and osmo_soft_uart::timer.

◆ osmo_soft_uart_rx_ubits()

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.

Parameters
[in]suartsoft-UART instance to feed bits into.
[in]ubitspointer to the unpacked bits.
[in]n_ubitsnumber of unpacked bits to be fed.
Returns
0 on success; negative on error.

References osmo_uart_rx_bit().

◆ osmo_soft_uart_set_rx()

int osmo_soft_uart_set_rx ( struct osmo_soft_uart suart,
bool  enable 
)

Enable/disable receiver of the given soft-UART.

Parameters
[in]suartsoft-UART instance to be re-configured.
[in]enableenable/disable state of the receiver.
Returns
0 on success; negative on error.

References osmo_soft_uart::cfg, osmo_soft_uart::flow_state, osmo_soft_uart::msg, msgb_alloc_c(), osmo_soft_uart_flush_rx(), osmo_soft_uart::running, osmo_soft_uart::rx, osmo_soft_uart_cfg::rx_buf_size, and SUART_FLOW_ST_IDLE.

◆ osmo_soft_uart_set_status()

int osmo_soft_uart_set_status ( struct osmo_soft_uart suart,
unsigned int  status 
)

Set the modem status lines of the given soft-UART.

Parameters
[in]suartsoft-UART instance to update the modem status.
[in]statusmask of osmo_soft_uart_status.
Returns
0 on success; negative on error.

◆ osmo_soft_uart_set_tx()

int osmo_soft_uart_set_tx ( struct osmo_soft_uart suart,
bool  enable 
)

Enable/disable transmitter of the given soft-UART.

Parameters
[in]suartsoft-UART instance to be re-configured.
[in]enableenable/disable state of the transmitter.
Returns
0 on success; negative on error.

References osmo_soft_uart::flow_state, osmo_soft_uart::running, SUART_FLOW_ST_IDLE, and osmo_soft_uart::tx.

◆ osmo_soft_uart_tx_ubits()

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.

Parameters
[in]suartsoft-UART instance to pull the bits from.
[out]ubitspointer to a buffer where to store pulled bits.
[in]n_ubitsnumber of unpacked bits to be pulled.
Returns
number of unpacked bits pulled; negative on error.

References osmo_soft_uart::cfg, osmo_soft_uart::flow_state, msg, msgb_alloc_c(), msgb_free(), osmo_soft_uart_cfg::num_data_bits, osmo_soft_uart_cfg::num_stop_bits, OSMO_ASSERT, OSMO_SUART_PARITY_NONE, osmo_uart_tx_bit(), OSMO_UNLIKELY, osmo_soft_uart_cfg::parity_mode, osmo_soft_uart_cfg::priv, SUART_FLOW_ST_IDLE, osmo_soft_uart::tx, and osmo_soft_uart_cfg::tx_cb.

Variable Documentation

◆ osmo_soft_uart_default_cfg

const struct osmo_soft_uart_cfg osmo_soft_uart_default_cfg
extern

Default soft-UART configuration (8-N-1)