libosmocore 1.10.0.10-24ad1
Osmocom core library
|
Software UART implementation. More...
#include <stdbool.h>
#include <stdint.h>
#include <errno.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/soft_uart.h>
Data Structures | |
struct | osmo_soft_uart |
Internal state of a soft-UART. More... | |
Enumerations | |
enum | suart_flow_state { SUART_FLOW_ST_IDLE , SUART_FLOW_ST_DATA , SUART_FLOW_ST_PARITY , SUART_FLOW_ST_STOP } |
Rx/Tx flow state of a soft-UART. More... | |
Functions | |
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... | |
static void | suart_rx_ch (struct osmo_soft_uart *suart, uint8_t ch) |
static void | suart_rx_bit (struct osmo_soft_uart *suart, const ubit_t bit) |
static void | suart_rx_timer_cb (void *data) |
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... | |
static ubit_t | suart_tx_bit (struct osmo_soft_uart *suart, struct msgb *msg) |
static size_t | suart_tx_pending (struct osmo_soft_uart *suart, ubit_t *ubits, size_t n_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. More... | |
unsigned int | osmo_soft_uart_get_status (const struct osmo_soft_uart *suart) |
Get the modem status bitmask of the given soft-UART. More... | |
int | osmo_soft_uart_set_status (struct osmo_soft_uart *suart, unsigned int status) |
Set the modem status bitmask of the given soft-UART. More... | |
void | osmo_soft_uart_set_status_line (struct osmo_soft_uart *suart, enum osmo_soft_uart_status line, bool active) |
Activate/deactivate a modem status line of the given soft-UART. More... | |
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. 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... | |
const char * | osmo_soft_uart_get_name (const struct osmo_soft_uart *suart) |
Get a name for the given soft-UART instance. More... | |
void | osmo_soft_uart_set_name (struct osmo_soft_uart *suart, const char *name) |
Set a new name for the given soft-UART instance. 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... | |
Variables | |
const struct osmo_soft_uart_cfg | osmo_soft_uart_default_cfg |
Default soft-UART configuration (8-N-1) More... | |
Software UART implementation.
enum suart_flow_state |
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.
[in] | ctx | parent talloc context. |
[in] | name | name of the soft-UART instance. |
[in] | cfg | initial configuration of the soft-UART instance. |
References osmo_soft_uart::cfg, name, osmo_soft_uart::name, and OSMO_ASSERT.
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.
[in] | suart | soft-UART instance to be re-configured. |
[in] | cfg | the user-provided config to be applied. |
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.
void osmo_soft_uart_flush_rx | ( | struct osmo_soft_uart * | suart | ) |
Flush the receive buffer, passing ownership of the msgb to the .rx_cb().
[in] | suart | soft-UART instance holding the receive buffer. |
References osmo_soft_uart::cfg, osmo_soft_uart::flags, osmo_soft_uart::msg, msgb_alloc_c(), msgb_length(), msgb_reset(), osmo_timer_del(), osmo_soft_uart_cfg::priv, osmo_soft_uart::rx, osmo_soft_uart_cfg::rx_buf_size, osmo_soft_uart_cfg::rx_cb, and osmo_soft_uart::timer.
Referenced by osmo_soft_uart_configure(), osmo_soft_uart_set_rx(), suart_rx_ch(), and suart_rx_timer_cb().
void osmo_soft_uart_free | ( | struct osmo_soft_uart * | suart | ) |
Release memory taken by the given soft-UART.
[in] | suart | soft-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.
const char * osmo_soft_uart_get_name | ( | const struct osmo_soft_uart * | suart | ) |
Get a name for the given soft-UART instance.
[in] | suart | soft-UART instance to get the name from. |
References osmo_soft_uart::name.
unsigned int osmo_soft_uart_get_status | ( | const struct osmo_soft_uart * | suart | ) |
Get the modem status bitmask of the given soft-UART.
[in] | suart | soft-UART instance to get the modem status. |
References osmo_soft_uart::status.
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.
[in] | suart | soft-UART instance to feed bits into. |
[in] | ubits | pointer to the unpacked bits. |
[in] | n_ubits | number of unpacked bits to be fed. |
References osmo_soft_uart::running, osmo_soft_uart::rx, and suart_rx_bit().
void osmo_soft_uart_set_name | ( | struct osmo_soft_uart * | suart, |
const char * | name | ||
) |
Set a new name for the given soft-UART instance.
[in] | suart | soft-UART instance to set the name for. |
[in] | name | the new name. |
References name, osmo_soft_uart::name, and osmo_talloc_replace_string().
int osmo_soft_uart_set_rx | ( | struct osmo_soft_uart * | suart, |
bool | enable | ||
) |
Enable/disable receiver of the given soft-UART.
[in] | suart | soft-UART instance to be re-configured. |
[in] | enable | enable/disable state of the receiver. |
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.
int osmo_soft_uart_set_status | ( | struct osmo_soft_uart * | suart, |
unsigned int | status | ||
) |
Set the modem status bitmask of the given soft-UART.
[in] | suart | soft-UART instance to set the modem status. |
[in] | status | bitmask of OSMO_SUART_STATUS_F_*. |
References osmo_soft_uart::cfg, osmo_soft_uart_cfg::priv, osmo_soft_uart::status, and osmo_soft_uart_cfg::status_change_cb.
Referenced by osmo_soft_uart_set_status_line().
void osmo_soft_uart_set_status_line | ( | struct osmo_soft_uart * | suart, |
enum osmo_soft_uart_status | line, | ||
bool | active | ||
) |
Activate/deactivate a modem status line of the given soft-UART.
[in] | suart | soft-UART instance to update the modem status. |
[in] | line | a modem status line, one of OSMO_SUART_STATUS_F_*. |
[in] | active | activate (true) or deactivate (false) the line. |
References osmo_soft_uart_set_status(), and osmo_soft_uart::status.
int osmo_soft_uart_set_tx | ( | struct osmo_soft_uart * | suart, |
bool | enable | ||
) |
Enable/disable transmitter of the given soft-UART.
[in] | suart | soft-UART instance to be re-configured. |
[in] | enable | enable/disable state of the transmitter. |
References osmo_soft_uart::flow_state, osmo_soft_uart::running, SUART_FLOW_ST_IDLE, and osmo_soft_uart::tx.
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.
[in] | suart | soft-UART instance to pull the bits from. |
[out] | ubits | pointer to a buffer where to store pulled bits. |
[in] | n_ubits | number of unpacked bits to be pulled. |
References osmo_soft_uart::cfg, osmo_soft_uart_cfg::flow_ctrl_mode, 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_FLOW_CTRL_DTR_DSR, OSMO_SUART_FLOW_CTRL_NONE, OSMO_SUART_FLOW_CTRL_RTS_CTS, OSMO_SUART_PARITY_NONE, OSMO_SUART_STATUS_F_CTS, OSMO_SUART_STATUS_F_DSR, OSMO_UNLIKELY, osmo_soft_uart_cfg::parity_mode, osmo_soft_uart_cfg::priv, osmo_soft_uart::running, osmo_soft_uart::status, SUART_FLOW_ST_IDLE, suart_tx_bit(), suart_tx_pending(), osmo_soft_uart::tx, and osmo_soft_uart_cfg::tx_cb.
|
inlinestatic |
References osmo_soft_uart::bit_count, osmo_soft_uart::cfg, osmo_soft_uart::flags, osmo_soft_uart::flow_state, osmo_soft_uart_cfg::num_data_bits, osmo_soft_uart_cfg::num_stop_bits, OSMO_ASSERT, OSMO_SUART_F_FRAMING_ERROR, OSMO_SUART_F_PARITY_ERROR, OSMO_SUART_PARITY_EVEN, OSMO_SUART_PARITY_MARK, OSMO_SUART_PARITY_NONE, OSMO_SUART_PARITY_ODD, OSMO_SUART_PARITY_SPACE, osmo_soft_uart::parity_bit, osmo_soft_uart_cfg::parity_mode, osmo_soft_uart::rx, osmo_soft_uart::shift_reg, SUART_FLOW_ST_DATA, SUART_FLOW_ST_IDLE, SUART_FLOW_ST_PARITY, SUART_FLOW_ST_STOP, and suart_rx_ch().
Referenced by osmo_soft_uart_rx_ubits().
|
static |
References osmo_soft_uart::cfg, osmo_soft_uart::flags, osmo_soft_uart::msg, msgb_length(), msgb_put_u8(), OSMO_ASSERT, osmo_soft_uart_flush_rx(), osmo_timer_schedule(), osmo_soft_uart::rx, osmo_soft_uart_cfg::rx_buf_size, osmo_soft_uart_cfg::rx_timeout_ms, and osmo_soft_uart::timer.
Referenced by suart_rx_bit().
|
static |
References data, and osmo_soft_uart_flush_rx().
Referenced by osmo_soft_uart_configure().
|
inlinestatic |
References osmo_soft_uart::bit_count, osmo_soft_uart::cfg, osmo_soft_uart::flow_state, osmo_soft_uart::msg, msgb_length(), msgb_pull_u8(), osmo_soft_uart_cfg::num_data_bits, osmo_soft_uart_cfg::num_stop_bits, OSMO_ASSERT, OSMO_SUART_PARITY_EVEN, OSMO_SUART_PARITY_MARK, OSMO_SUART_PARITY_NONE, OSMO_SUART_PARITY_ODD, OSMO_SUART_PARITY_SPACE, osmo_soft_uart::parity_bit, osmo_soft_uart_cfg::parity_mode, osmo_soft_uart::shift_reg, SUART_FLOW_ST_DATA, SUART_FLOW_ST_IDLE, SUART_FLOW_ST_PARITY, SUART_FLOW_ST_STOP, and osmo_soft_uart::tx.
Referenced by osmo_soft_uart_tx_ubits(), and suart_tx_pending().
|
static |
References osmo_soft_uart::flow_state, SUART_FLOW_ST_IDLE, suart_tx_bit(), and osmo_soft_uart::tx.
Referenced by osmo_soft_uart_tx_ubits().
const struct osmo_soft_uart_cfg osmo_soft_uart_default_cfg |
Default soft-UART configuration (8-N-1)