Serial port class.
More...
|
| | 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.
|
| |
|
| #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.
|
| |
|
| 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.
|
| |
|
| 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.
|
| |
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) {
}
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.
◆ pbl_uart_config
◆ pbl_uart
| 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. |
◆ PBL_UART_INIT
| #define PBL_UART_INIT |
( |
|
sym, |
|
|
|
_name, |
|
|
|
_parent, |
|
|
|
_ops, |
|
|
|
_baudrate |
|
) |
| |
Value: { \
.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
-
| sym | Symbol of the port instance, with its state defined by PBL_UART_STATE_DEFINE(). |
| _name | Name. |
| _parent | Parent device, or NULL. |
| _ops | Driver operations. |
| _baudrate | Initial 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
-
| sym | Symbol of the port instance. |
◆ 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
-
| uart | Port. |
| c | Byte. |
| arg | Callback argument. |
◆ 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.
|
◆ pbl_uart_config_get()
Get the line settings.
- Parameters
-
| uart | Port. |
| [out] | cfg | Line settings. |
- Returns
- 0 or a negative errno.
◆ pbl_uart_configure()
Apply line settings.
- Parameters
-
| uart | Port. |
| cfg | Line 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
-
- Returns
- 0 or a negative errno.
◆ pbl_uart_early_init()
Set a port up as an early console, for polled transmission before its device init.
- Parameters
-
| uart | Port. |
| cfg | Line 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
-
◆ 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
-
◆ 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
-
- 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
-
- Returns
- 0 or a negative errno.
◆ pbl_uart_rx_enable()
Enable reception.
Bytes are handed to cb until pbl_uart_rx_disable() is called. Enabling it again replaces the callback.
- Parameters
-
| uart | Port. |
| cb | Receive callback. |
| arg | Callback argument. |
- Returns
- 0 or a negative errno.
◆ 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
Class of the serial ports.
◆ QEMU_UART
The board's port to the host of the QEMU serial protocol.