PebbleOS v4.47.0-512-g5285d4236
Loading...
Searching...
No Matches

Serial port class. More...

Modules

 nRF5
 UART driver for the nRF5 UARTE peripheral.
 
 POSIX
 UART driver on the host: the terminal, a TCP port or a serial device.
 
 QEMU
 UART driver for the QEMU simple UART.
 
 SF32LB
 UART driver for the SF32LB USART.
 

Data Structures

struct  pbl_uart_config
 Line settings. More...
 
struct  pbl_uart_ops
 Port driver operations. More...
 
struct  pbl_uart
 A serial port. More...
 

Macros

#define PBL_UART_STATE_DEFINE(sym)
 Define the class state of port sym, for the PBL_UART_*_DEFINE() macro of a driver.
 
#define PBL_UART_INIT(sym, _name, _parent, _ops, _baudrate)
 Initializer for the struct pbl_uart of port sym.
 

Typedefs

typedef void(* pbl_uart_rx_callback_t) (const struct pbl_uart *uart, uint8_t c, void *arg)
 Receive callback, called from the port's interrupt for each received byte.
 

Enumerations

enum  pbl_uart_parity { PBL_UART_PARITY_NONE , PBL_UART_PARITY_ODD , PBL_UART_PARITY_EVEN }
 Parity. More...
 
enum  pbl_uart_flow_ctrl { PBL_UART_FLOW_CTRL_NONE , PBL_UART_FLOW_CTRL_RTS_CTS }
 Flow control. More...
 

Functions

int pbl_uart_dev_init (const struct pbl_device *dev)
 Device init of every port: calls the driver's init, then applies the line settings, the early console's if the port was one.
 
bool pbl_uart_receive (const struct pbl_uart *uart, uint8_t c)
 Hand a received byte to the receive callback.
 
int pbl_uart_early_init (const struct pbl_uart *uart, const struct pbl_uart_config *cfg)
 Set a port up as an early console, for polled transmission before its device init.
 
int pbl_uart_configure (const struct pbl_uart *uart, const struct pbl_uart_config *cfg)
 Apply line settings.
 
int pbl_uart_config_get (const struct pbl_uart *uart, struct pbl_uart_config *cfg)
 Get the line settings.
 
void pbl_uart_poll_out (const struct pbl_uart *uart, uint8_t c)
 Send a byte, waiting for room.
 
void pbl_uart_flush (const struct pbl_uart *uart)
 Wait until the bytes sent have left the port.
 
int pbl_uart_rx_enable (const struct pbl_uart *uart, pbl_uart_rx_callback_t cb, void *arg)
 Enable reception.
 
int pbl_uart_rx_disable (const struct pbl_uart *uart)
 Disable reception.
 

Variables

const struct pbl_device_class pbl_uart_class
 Class of the serial ports.
 
const struct pbl_uart *const CONSOLE_UART
 The board's console port.
 
const struct pbl_uart *const QEMU_UART
 The board's port to the host of the QEMU serial protocol.
 
const struct pbl_uart *const BT_HCI_UART
 The board's Bluetooth HCI port, with CONFIG_NIMBLE_HCI_UART.
 

Detailed Description

Serial port class.

A serial port is a struct pbl_uart device. It starts with the baud rate the board gives, 8 data bits, no parity, one stop bit and no flow control. Bytes are sent polled, and received bytes are handed to a callback, one at a time, from the port's interrupt while reception is enabled:

static void prv_rx(const struct pbl_uart *uart, uint8_t c, void *arg) {
// interrupt context; may call pbl_uart_rx_disable() to hold further bytes back
}
const struct pbl_uart_config cfg = {.baudrate = 115200};
ret = pbl_uart_rx_enable(CONSOLE_UART, prv_rx, nullptr);
uint32_t baudrate
Baud rate, in bits per second.
Definition uart.h:66
Line settings.
Definition uart.h:64
A serial port.
Definition uart.h:135
const struct pbl_uart *const CONSOLE_UART
The board's console port.
int pbl_uart_rx_enable(const struct pbl_uart *uart, pbl_uart_rx_callback_t cb, void *arg)
Enable reception.
void pbl_uart_flush(const struct pbl_uart *uart)
Wait until the bytes sent have left the port.
void pbl_uart_poll_out(const struct pbl_uart *uart, uint8_t c)
Send a byte, waiting for room.
int pbl_uart_configure(const struct pbl_uart *uart, const struct pbl_uart_config *cfg)
Apply line settings.

A port can also serve as an early console, before the device model is initialized: pbl_uart_early_init() sets it up for polled transmission only, and the device init takes over with the same line settings.

The port may keep the SoC out of its deepest sleep states while reception is enabled. Calls may be made from interrupt context. They return 0 or a negative errno: -ENODEV if the port is not ready and -ENOTSUP for line settings it does not support.


Data Structure Documentation

◆ pbl_uart_config

struct pbl_uart_config

Line settings.

Data Fields
uint32_t baudrate Baud rate, in bits per second.
enum pbl_uart_flow_ctrl flow_ctrl Flow control.
enum pbl_uart_parity parity Parity.

◆ pbl_uart

struct pbl_uart

A serial port.

Data Fields
uint32_t baudrate Initial baud rate, in bits per second.
struct pbl_device dev Device.
const struct pbl_uart_ops * ops Driver operations.
struct pbl_uart_state * state Runtime state.

Macro Definition Documentation

◆ PBL_UART_INIT

#define PBL_UART_INIT (   sym,
  _name,
  _parent,
  _ops,
  _baudrate 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, pbl_uart_dev_init, _parent, &pbl_uart_class), \
.ops = (_ops), \
.state = &sym##_uart_state, \
.baudrate = (_baudrate), \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:153
const struct pbl_device_class pbl_uart_class
Class of the serial ports.
int pbl_uart_dev_init(const struct pbl_device *dev)
Device init of every port: calls the driver's init, then applies the line settings,...

Initializer for the struct pbl_uart of port sym.

Parameters
symSymbol of the port instance, with its state defined by PBL_UART_STATE_DEFINE().
_nameName.
_parentParent device, or NULL.
_opsDriver operations.
_baudrateInitial baud rate, in bits per second.

◆ PBL_UART_STATE_DEFINE

#define PBL_UART_STATE_DEFINE (   sym)
Value:
static struct pbl_uart_state sym##_uart_state
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:132

Define the class state of port sym, for the PBL_UART_*_DEFINE() macro of a driver.

Parameters
symSymbol of the port instance.

Typedef Documentation

◆ pbl_uart_rx_callback_t

typedef void(* pbl_uart_rx_callback_t) (const struct pbl_uart *uart, uint8_t c, void *arg)

Receive callback, called from the port's interrupt for each received byte.

Parameters
uartPort.
cByte.
argCallback argument.

Enumeration Type Documentation

◆ pbl_uart_flow_ctrl

Flow control.

Enumerator
PBL_UART_FLOW_CTRL_NONE 

None.

PBL_UART_FLOW_CTRL_RTS_CTS 

RTS and CTS lines.

◆ pbl_uart_parity

Parity.

Enumerator
PBL_UART_PARITY_NONE 

No parity bit.

PBL_UART_PARITY_ODD 

Odd parity.

PBL_UART_PARITY_EVEN 

Even parity.

Function Documentation

◆ pbl_uart_config_get()

int pbl_uart_config_get ( const struct pbl_uart *  uart,
struct pbl_uart_config *  cfg 
)

Get the line settings.

Parameters
uartPort.
[out]cfgLine settings.
Returns
0 or a negative errno.

◆ pbl_uart_configure()

int pbl_uart_configure ( const struct pbl_uart *  uart,
const struct pbl_uart_config *  cfg 
)

Apply line settings.

Parameters
uartPort.
cfgLine settings.
Returns
0 or a negative errno.

◆ pbl_uart_dev_init()

int pbl_uart_dev_init ( const struct pbl_device *  dev)

Device init of every port: calls the driver's init, then applies the line settings, the early console's if the port was one.

Parameters
devPort device.
Returns
0 or a negative errno.

◆ pbl_uart_early_init()

int pbl_uart_early_init ( const struct pbl_uart *  uart,
const struct pbl_uart_config *  cfg 
)

Set a port up as an early console, for polled transmission before its device init.

Parameters
uartPort.
cfgLine settings, kept once the device init takes over.
Returns
0 or a negative errno.

◆ pbl_uart_flush()

void pbl_uart_flush ( const struct pbl_uart *  uart)

Wait until the bytes sent have left the port.

Parameters
uartPort.

◆ pbl_uart_poll_out()

void pbl_uart_poll_out ( const struct pbl_uart *  uart,
uint8_t  c 
)

Send a byte, waiting for room.

Does nothing if the port is neither ready nor an early console.

Parameters
uartPort.
cByte.

◆ pbl_uart_receive()

bool pbl_uart_receive ( const struct pbl_uart *  uart,
uint8_t  c 
)

Hand a received byte to the receive callback.

Called by the port driver from its interrupt.

Parameters
uartPort.
cByte.
Returns
true if reception is still enabled, false if the driver must hold further bytes back.

◆ pbl_uart_rx_disable()

int pbl_uart_rx_disable ( const struct pbl_uart *  uart)

Disable reception.

Bytes the port does not hold back are lost.

Parameters
uartPort.
Returns
0 or a negative errno.

◆ pbl_uart_rx_enable()

int pbl_uart_rx_enable ( const struct pbl_uart *  uart,
pbl_uart_rx_callback_t  cb,
void *  arg 
)

Enable reception.

Bytes are handed to cb until pbl_uart_rx_disable() is called. Enabling it again replaces the callback.

Parameters
uartPort.
cbReceive callback.
argCallback argument.
Returns
0 or a negative errno.

Variable Documentation

◆ BT_HCI_UART

const struct pbl_uart* const BT_HCI_UART
extern

The board's Bluetooth HCI port, with CONFIG_NIMBLE_HCI_UART.

◆ CONSOLE_UART

const struct pbl_uart* const CONSOLE_UART
extern

The board's console port.

◆ pbl_uart_class

const struct pbl_device_class pbl_uart_class
extern

Class of the serial ports.

◆ QEMU_UART

const struct pbl_uart* const QEMU_UART
extern

The board's port to the host of the QEMU serial protocol.