PebbleOS
Loading...
Searching...
No Matches
Modules | Data Structures | Typedefs | Functions

Serial port driver interface. More...

Modules

 nRF5
 nRF5 UARTE device definition.
 
 POSIX
 UART on the host: the terminal, a TCP port or a serial device.
 
 QEMU
 QEMU UART device definition.
 
 SF32LB
 SF32LB UART device definition.
 

Data Structures

struct  UARTRXErrorFlags
 Receive error flags. More...
 
union  UARTRXErrorFlags.__unnamed29__
 
struct  UARTRXErrorFlags.__unnamed29__.__unnamed31__
 

Typedefs

typedef const struct UARTDevice UARTDevice
 UART device, defined per SoC.
 
typedef void(* UARTRXInterruptHandler) (UARTDevice *dev, uint8_t data, const UARTRXErrorFlags *err_flags)
 Receive interrupt handler, called from the UART ISR for each received byte.
 
typedef void(* UARTTXInterruptHandler) (UARTDevice *dev)
 Transmit interrupt handler, called from the UART ISR when a byte can be sent.
 

Functions

void uart_init (UARTDevice *dev)
 Initialize the device for receive and transmit.
 
void uart_init_open_drain (UARTDevice *dev)
 Initialize the device with open-drain instead of push-pull pins.
 
void uart_init_tx_only (UARTDevice *dev)
 Initialize the device for transmit only.
 
void uart_init_rx_only (UARTDevice *dev)
 Initialize the device for receive only.
 
void uart_deinit (UARTDevice *dev)
 Deinitialize the device.
 
void uart_set_baud_rate (UARTDevice *dev, uint32_t baud_rate)
 Set the baud rate.
 
void uart_set_rx_interrupt_handler (UARTDevice *dev, UARTRXInterruptHandler irq_handler)
 Set the receive interrupt handler.
 
void uart_set_tx_interrupt_handler (UARTDevice *dev, UARTTXInterruptHandler irq_handler)
 Set the transmit interrupt handler.
 
void uart_set_rx_interrupt_enabled (UARTDevice *dev, bool enabled)
 Enable or disable the receive interrupt.
 
void uart_set_tx_interrupt_enabled (UARTDevice *dev, bool enabled)
 Enable or disable the transmit interrupt.
 
void uart_write_byte (UARTDevice *dev, uint8_t data)
 Write a byte.
 
uint8_t uart_read_byte (UARTDevice *dev)
 Read a byte.
 
void uart_start_rx_dma (UARTDevice *dev, void *buffer, uint32_t length)
 Start receiving into a circular DMA buffer.
 
void uart_stop_rx_dma (UARTDevice *dev)
 Stop receiving through DMA.
 
void uart_clear_rx_dma_buffer (UARTDevice *dev)
 Discard data pending in the receive DMA buffer.
 
bool uart_is_rx_ready (UARTDevice *dev)
 Check whether a received byte is ready to be read.
 
bool uart_has_rx_overrun (UARTDevice *dev)
 Check for a receive overrun.
 
bool uart_has_rx_framing_error (UARTDevice *dev)
 Check for a framing error.
 
bool uart_is_tx_ready (UARTDevice *dev)
 Check whether a byte can be written.
 
bool uart_is_tx_complete (UARTDevice *dev)
 Check whether the last byte has been fully sent.
 
void uart_wait_for_tx_complete (UARTDevice *dev)
 Wait until the last byte has been fully sent.
 
UARTRXErrorFlags uart_has_errored_out (UARTDevice *dev)
 Get the pending receive errors.
 
void uart_clear_all_interrupt_flags (UARTDevice *dev)
 Clear all interrupt flags.
 

Detailed Description

Serial port driver interface.

Devices are defined by the board, with a SoC-specific UARTDevice. Received bytes are delivered to an RX handler from the UART interrupt, also when receiving through DMA.

static void prv_rx(UARTDevice *dev, uint8_t data, const UARTRXErrorFlags *err_flags) {
// ISR context
}
uart_init(dev);
uart_set_baud_rate(dev, 115200);
uart_write_byte(dev, 'A');
nRF5 UART device.
Definition nrf5.h:59
Receive error flags.
Definition uart.h:39
void uart_wait_for_tx_complete(UARTDevice *dev)
Wait until the last byte has been fully sent.
void uart_set_baud_rate(UARTDevice *dev, uint32_t baud_rate)
Set the baud rate.
void uart_set_rx_interrupt_enabled(UARTDevice *dev, bool enabled)
Enable or disable the receive interrupt.
void uart_write_byte(UARTDevice *dev, uint8_t data)
Write a byte.
void uart_init(UARTDevice *dev)
Initialize the device for receive and transmit.
void uart_set_rx_interrupt_handler(UARTDevice *dev, UARTRXInterruptHandler irq_handler)
Set the receive interrupt handler.

Data Structure Documentation

◆ UARTRXErrorFlags

struct UARTRXErrorFlags

Receive error flags.

Data Fields
union UARTRXErrorFlags.__unnamed29__ __unnamed__

◆ UARTRXErrorFlags.__unnamed29__

union UARTRXErrorFlags.__unnamed29__
Data Fields
struct UARTRXErrorFlags.__unnamed29__.__unnamed31__ __unnamed__
uint8_t error_mask All flags as a bit mask; non-zero if any error occurred.

◆ UARTRXErrorFlags.__unnamed29__.__unnamed31__

struct UARTRXErrorFlags.__unnamed29__.__unnamed31__
Data Fields
bool framing_error: 1 Framing error.
bool noise_detected: 1 Noise detected.
bool overrun_error: 1 Receive overrun: data was lost.
bool parity_error: 1 Parity error.
uint8_t reserved: 4 Reserved.

Typedef Documentation

◆ UARTDevice

typedef const struct UARTDevice UARTDevice

UART device, defined per SoC.

◆ UARTRXInterruptHandler

typedef void(* UARTRXInterruptHandler) (UARTDevice *dev, uint8_t data, const UARTRXErrorFlags *err_flags)

Receive interrupt handler, called from the UART ISR for each received byte.

Parameters
devDevice.
dataReceived byte.
err_flagsErrors detected with this byte.

◆ UARTTXInterruptHandler

typedef void(* UARTTXInterruptHandler) (UARTDevice *dev)

Transmit interrupt handler, called from the UART ISR when a byte can be sent.

Parameters
devDevice.

Function Documentation

◆ uart_clear_all_interrupt_flags()

void uart_clear_all_interrupt_flags ( UARTDevice *  dev)

Clear all interrupt flags.

Parameters
devDevice.

◆ uart_clear_rx_dma_buffer()

void uart_clear_rx_dma_buffer ( UARTDevice *  dev)

Discard data pending in the receive DMA buffer.

Parameters
devDevice.

◆ uart_deinit()

void uart_deinit ( UARTDevice *  dev)

Deinitialize the device.

Parameters
devDevice.

◆ uart_has_errored_out()

UARTRXErrorFlags uart_has_errored_out ( UARTDevice *  dev)

Get the pending receive errors.

Parameters
devDevice.
Returns
Error flags; error_mask is non-zero if an error occurred.

◆ uart_has_rx_framing_error()

bool uart_has_rx_framing_error ( UARTDevice *  dev)

Check for a framing error.

Check before reading the received byte, as reading clears the flag.

Parameters
devDevice.
Returns
true on framing error.

◆ uart_has_rx_overrun()

bool uart_has_rx_overrun ( UARTDevice *  dev)

Check for a receive overrun.

Check before reading the received byte, as reading clears the flag.

Parameters
devDevice.
Returns
true on overrun.

◆ uart_init()

void uart_init ( UARTDevice *  dev)

Initialize the device for receive and transmit.

Parameters
devDevice.

◆ uart_init_open_drain()

void uart_init_open_drain ( UARTDevice *  dev)

Initialize the device with open-drain instead of push-pull pins.

Not supported on all SoCs.

Parameters
devDevice.

◆ uart_init_rx_only()

void uart_init_rx_only ( UARTDevice *  dev)

Initialize the device for receive only.

Parameters
devDevice.

◆ uart_init_tx_only()

void uart_init_tx_only ( UARTDevice *  dev)

Initialize the device for transmit only.

Parameters
devDevice.

◆ uart_is_rx_ready()

bool uart_is_rx_ready ( UARTDevice *  dev)

Check whether a received byte is ready to be read.

Parameters
devDevice.
Returns
true if a byte is ready.

◆ uart_is_tx_complete()

bool uart_is_tx_complete ( UARTDevice *  dev)

Check whether the last byte has been fully sent.

Parameters
devDevice.
Returns
true if transmission is complete.

◆ uart_is_tx_ready()

bool uart_is_tx_ready ( UARTDevice *  dev)

Check whether a byte can be written.

Parameters
devDevice.
Returns
true if the transmit buffer has room.

◆ uart_read_byte()

uint8_t uart_read_byte ( UARTDevice *  dev)

Read a byte.

Clears the framing and overrun error flags.

Parameters
devDevice.
Returns
Byte read.

◆ uart_set_baud_rate()

void uart_set_baud_rate ( UARTDevice *  dev,
uint32_t  baud_rate 
)

Set the baud rate.

Parameters
devDevice.
baud_rateBaud rate in bits per second.

◆ uart_set_rx_interrupt_enabled()

void uart_set_rx_interrupt_enabled ( UARTDevice *  dev,
bool  enabled 
)

Enable or disable the receive interrupt.

Parameters
devDevice.
enabledtrue to enable.

◆ uart_set_rx_interrupt_handler()

void uart_set_rx_interrupt_handler ( UARTDevice *  dev,
UARTRXInterruptHandler  irq_handler 
)

Set the receive interrupt handler.

Parameters
devDevice.
irq_handlerHandler, called from the ISR for each received byte.

◆ uart_set_tx_interrupt_enabled()

void uart_set_tx_interrupt_enabled ( UARTDevice *  dev,
bool  enabled 
)

Enable or disable the transmit interrupt.

Parameters
devDevice.
enabledtrue to enable.

◆ uart_set_tx_interrupt_handler()

void uart_set_tx_interrupt_handler ( UARTDevice *  dev,
UARTTXInterruptHandler  irq_handler 
)

Set the transmit interrupt handler.

Parameters
devDevice.
irq_handlerHandler, called from the ISR when a byte can be sent.

◆ uart_start_rx_dma()

void uart_start_rx_dma ( UARTDevice *  dev,
void *  buffer,
uint32_t  length 
)

Start receiving into a circular DMA buffer.

The device must have DMA configured. Received bytes are still delivered to the receive handler. Some SoCs require buffer and length to be aligned to the data cache line.

Parameters
devDevice.
bufferDMA buffer.
lengthSize of buffer in bytes.

◆ uart_stop_rx_dma()

void uart_stop_rx_dma ( UARTDevice *  dev)

Stop receiving through DMA.

Parameters
devDevice.

◆ uart_wait_for_tx_complete()

void uart_wait_for_tx_complete ( UARTDevice *  dev)

Wait until the last byte has been fully sent.

Parameters
devDevice.

◆ uart_write_byte()

void uart_write_byte ( UARTDevice *  dev,
uint8_t  data 
)

Write a byte.

Blocks until the transmit buffer has room.

Parameters
devDevice.
dataByte to write.