SmartSnippets DA1459x SDK
Files | Data Structures | Macros | Enumerations | Functions | Variables

UART Controller. More...

Files

file  hw_uart.h
 Definition of API for the UART Low Level Driver.
 

Data Structures

struct  uart_config
 UART configuration structure definition. More...
 

Macros

#define HW_UART_REG_FIELD_MASK(instance, reg, field)   (UART##instance##_UART##instance##_##reg##_REG_##field##_Msk)
 Get the mask of a field of a UART register. More...
 
#define HW_UART_REG_FIELD_POS(instance, reg, field)   (UART##instance##_UART##instance##_##reg##_REG_##field##_Pos)
 Get the bit position of a field of a UART register. More...
 
#define HW_UART_REG_GETF(id, reg, field)   ((UBA(id)->UART2_##reg##_REG & (UART2_UART2_##reg##_REG_##field##_Msk)) >> (UART2_UART2_##reg##_REG_##field##_Pos))
 Get the value of a field of a UART register. More...
 
#define HW_UART_REG_SETF(id, reg, field, new_val)
 Set the value of a field of a UART register. More...
 
#define HW_UART_DMA_SUPPORT   dg_configUART_DMA_SUPPORT
 DMA support for UART.
 

Enumerations

enum  HW_UART_INT
 Interrupt Identification codes. More...
 
enum  HW_UART_BAUDRATE {
  HW_UART_BAUDRATE_1200 = 0, HW_UART_BAUDRATE_2400 = 1, HW_UART_BAUDRATE_4800 = 2, HW_UART_BAUDRATE_9600 = 3,
  HW_UART_BAUDRATE_14400 = 4, HW_UART_BAUDRATE_19200 = 5, HW_UART_BAUDRATE_28800 = 6, HW_UART_BAUDRATE_38400 = 7,
  HW_UART_BAUDRATE_57600 = 8, HW_UART_BAUDRATE_115200 = 9, HW_UART_BAUDRATE_230400 = 10, HW_UART_BAUDRATE_256000 = 11,
  HW_UART_BAUDRATE_460800 = 12, HW_UART_BAUDRATE_500000 = 13, HW_UART_BAUDRATE_921600 = 14, HW_UART_BAUDRATE_1000000 = 15,
  HW_UART_BAUDRATE_2000000 = 16, HW_UART_BAUDRATE_3000000 = 17, HW_UART_BAUDRATE_MAX
}
 Baud rates. More...
 
enum  HW_UART_DATABITS
 Character format. More...
 
enum  HW_UART_PARITY
 Parity. More...
 
enum  HW_UART_STOPBITS { HW_UART_STOPBITS_1 = 0, HW_UART_STOPBITS_2 = 1 }
 Stop bits. More...
 
enum  HW_UART_ERROR { ,
  HW_UART_ERR_OE = 1, HW_UART_ERR_PE = 2, HW_UART_ERR_FE = 3, HW_UART_ERR_BI = 4,
  HW_UART_ERR_RFE = 5
}
 Uart errors. More...
 
enum  HW_UART_CONFIG_ERR { ,
  HW_UART_CONFIG_ERR_RX_FIFO = 1, HW_UART_CONFIG_ERR_TX_FIFO = 2, HW_UART_CONFIG_ERR_RXTX_FIFO = 3, HW_UART_CONFIG_ERR_RX_SIZE = 4,
  HW_UART_CONFIG_ERR_TX_SIZE = 5
}
 Configuration errors. More...
 

Functions

__STATIC_INLINE bool hw_uart_is_busy (HW_UART_ID uart)
 Check if a serial transfer is in progress. More...
 
uint8_t hw_uart_read (HW_UART_ID uart)
 Read one byte from UART. More...
 
void hw_uart_write (HW_UART_ID uart, uint8_t data)
 Write one byte to UART. More...
 
uint16_t hw_uart_abort_receive (HW_UART_ID uart)
 Stop asynchronous read from UART. More...
 
uint16_t hw_uart_abort_send (HW_UART_ID uart)
 Stop asynchronous transmit from UART. More...
 
uint16_t hw_uart_peek_received (HW_UART_ID uart)
 Get number of bytes currently received by asynchronous read. More...
 
uint16_t hw_uart_peek_transmitted (HW_UART_ID uart)
 Get number of bytes currently sent by asynchronous read. More...
 
__STATIC_INLINE uint8_t hw_uart_rxdata_getf (HW_UART_ID uart)
 Read receive buffer register. More...
 
__STATIC_INLINE void hw_uart_txdata_setf (HW_UART_ID uart, uint8_t data)
 Write byte to the transmit holding register. More...
 
void hw_uart_write_buffer (HW_UART_ID uart, const void *data, uint16_t len)
 Writes number of bytes to UART synchronously. More...
 
HW_UART_CONFIG_ERR hw_uart_send (HW_UART_ID uart, const void *data, uint16_t len, hw_uart_tx_callback cb, void *user_data)
 Write number of bytes to UART. More...
 
HW_UART_CONFIG_ERR hw_uart_receive (HW_UART_ID uart, void *data, uint16_t len, hw_uart_rx_callback cb, void *user_data)
 Read number of bytes from UART. More...
 
void hw_uart_receive_error_checking (HW_UART_ID uart, void *data, uint16_t len, hw_uart_rx_callback cb, void *user_data, hw_uart_err_callback err_cb, void *error_data)
 Read number of bytes from UART with error checking. More...
 
__STATIC_INLINE void hw_uart_rec_data_int_set (HW_UART_ID uart, uint8_t recdataavail)
 Set the Received Data Available interrupt. More...
 
__STATIC_INLINE void hw_uart_tx_empty_int_set (HW_UART_ID uart, uint8_t txempty)
 Set the Transmit Holding Register empty interrupt. More...
 
__STATIC_INLINE void hw_uart_linestat_int_set (HW_UART_ID uart, uint8_t linestat)
 Set the Line Status interrupt. More...
 
__STATIC_INLINE void hw_uart_pthre_int_set (HW_UART_ID uart, uint8_t pthre)
 Set the Programmable THRE interrupt. More...
 
__STATIC_INLINE HW_UART_INT hw_uart_get_interrupt_id (HW_UART_ID uart)
 Get the Interrupt ID. More...
 
__STATIC_INLINE void hw_uart_write_scr (const HW_UART_ID uart, uint8_t value)
 Write Scratch pad register. More...
 
__STATIC_INLINE uint8_t hw_uart_read_scr (const HW_UART_ID uart)
 Read Scratch pad register. More...
 
void hw_uart_set_sclk (const HW_UART_ID uart, bool sclk)
 Configure the serial clock input of the UART (divN or div1) More...
 
HW_UART_BAUDRATE hw_uart_baudrate_get (HW_UART_ID uart)
 Get the baud rate setting. More...
 
void hw_uart_baudrate_set (HW_UART_ID uart, HW_UART_BAUDRATE baud_rate)
 Set the baud rate. More...
 
__STATIC_INLINE bool hw_uart_is_data_ready (HW_UART_ID uart)
 Check if there is data available for read. More...
 
__STATIC_INLINE bool hw_uart_is_fifo_enabled (HW_UART_ID uart)
 Get the FIFO mode setting. More...
 
__STATIC_INLINE void hw_uart_disable_fifo (HW_UART_ID uart)
 Disable both FIFOs. More...
 
__STATIC_INLINE void hw_uart_enable_fifo (HW_UART_ID uart)
 Enable both FIFOs. More...
 
__STATIC_INLINE bool hw_uart_receive_fifo_not_empty (HW_UART_ID uart)
 Check if receive FIFO is not empty. More...
 
__STATIC_INLINE bool hw_uart_transmit_fifo_not_full (HW_UART_ID uart)
 Check if transmit FIFO is not full. More...
 
__STATIC_INLINE bool hw_uart_transmit_fifo_empty (HW_UART_ID uart)
 Check if transmit FIFO is empty. More...
 
__STATIC_INLINE uint16_t hw_uart_receive_fifo_count (HW_UART_ID uart)
 Read number of bytes in receive FIFO. More...
 
__STATIC_INLINE uint16_t hw_uart_transmit_fifo_count (HW_UART_ID uart)
 Read number of bytes in transmit FIFO. More...
 
__STATIC_INLINE void hw_uart_enable_loopback (HW_UART_ID uart)
 Enable loopback. More...
 
__STATIC_INLINE void hw_uart_disable_loopback (HW_UART_ID uart)
 Disable loopback. More...
 
uint8_t hw_uart_fifo_en_getf (HW_UART_ID uart)
 Get the FIFO mode setting. More...
 
__STATIC_INLINE void hw_uart_fifo_en_setf (HW_UART_ID uart, uint8_t en)
 Enable or disable the UART FIFO mode. More...
 
__STATIC_INLINE uint8_t hw_uart_rx_fifo_tr_lvl_getf (HW_UART_ID uart)
 Get the receive FIFO trigger level at which the Received Data Available Interrupt is generated. More...
 
__STATIC_INLINE void hw_uart_rx_fifo_tr_lvl_setf (HW_UART_ID uart, uint8_t tr_lvl)
 Set the receive FIFO trigger level at which the Received Data Available Interrupt is generated. More...
 
uint8_t hw_uart_tx_fifo_tr_lvl_getf (HW_UART_ID uart)
 Get the transmit FIFO trigger level at which the Transmit Holding Register Empty (THRE) Interrupt is generated. More...
 
__STATIC_INLINE void hw_uart_tx_fifo_tr_lvl_setf (HW_UART_ID uart, uint8_t tr_lvl)
 Set the transmit FIFO trigger level at which the Transmit Holding Register Empty (THRE) Interrupt is generated. More...
 
__STATIC_INLINE void hw_uart_tx_fifo_flush (HW_UART_ID uart)
 Reset UART transmit FIFO. More...
 
__STATIC_INLINE void hw_uart_rx_fifo_flush (HW_UART_ID uart)
 Reset UART receive FIFO. More...
 
__STATIC_INLINE bool hw_uart_read_buf_empty (HW_UART_ID uart)
 Check whether reading buffer is empty. More...
 
__STATIC_INLINE bool hw_uart_write_buf_full (HW_UART_ID uart)
 Check whether writing buffer is full. More...
 
__STATIC_INLINE bool hw_uart_transmit_empty (HW_UART_ID uart)
 Check whether transmitter is empty. More...
 
HW_UART_CONFIG_ERR hw_uart_init (HW_UART_ID uart, const uart_config *cfg)
 Set UART line settings. More...
 
void hw_uart_deinit (HW_UART_ID uart)
 Disables UART controller. More...
 
void hw_uart_reinit (HW_UART_ID uart, const uart_config *cfg)
 Re-initialize UART registers. More...
 
void hw_uart_cfg_get (HW_UART_ID uart, uart_config *cfg)
 Get UART line settings. More...
 
uint8_t hw_uart_afce_getf (HW_UART_ID uart)
 Get the Auto Flow Control Enable (AFCE) setting. More...
 
void hw_uart_afce_setf (HW_UART_ID uart, uint8_t afce)
 Enable or disable Auto Flow Control. More...
 
uint8_t hw_uart_loopback_getf (HW_UART_ID uart)
 Get UART diagnostic mode status. More...
 
void hw_uart_loopback_setf (HW_UART_ID uart, uint8_t lb)
 Set UART in diagnostic mode. More...
 
uint8_t hw_uart_rts_getf (HW_UART_ID uart)
 Get RTS output value. More...
 
void hw_uart_rts_setf (HW_UART_ID uart, uint8_t rtsn)
 Set RTS output value. More...
 
HW_UART_ERROR hw_uart_error_getf (HW_UART_ID uart)
 Get the line status register error. More...
 
uint8_t hw_uart_rx_fifo_err_getf (HW_UART_ID uart)
 Get the value of the Receiver FIFO Error bit. More...
 
uint8_t hw_uart_is_tx_fifo_empty (HW_UART_ID uart)
 Get the value of the Transmitter Empty bit. More...
 
uint8_t hw_uart_thr_empty_getf (HW_UART_ID uart)
 Get the value of the Transmit Holding Register Empty bit. More...
 
uint8_t hw_uart_break_int_getf (HW_UART_ID uart)
 Get the value of the Break Interrupt bit. More...
 
uint8_t hw_uart_frame_err_getf (HW_UART_ID uart)
 Get the value of the Framing Error bit. More...
 
uint8_t hw_uart_parity_err_getf (HW_UART_ID uart)
 Get the value of the Parity Error bit. More...
 
uint8_t hw_uart_overrun_err_getf (HW_UART_ID uart)
 Get the value of the Overrun Error bit. More...
 
uint8_t hw_uart_cts_getf (HW_UART_ID uart)
 Get CTS input status. More...
 
uint8_t hw_uart_delta_cts_getf (HW_UART_ID uart)
 Get Delta CTS. More...
 
bool hw_uart_tx_in_progress (const HW_UART_ID uart)
 Check if buffered write is in progress. More...
 
bool hw_uart_rx_in_progress (const HW_UART_ID uart)
 Check if buffered read is in progress. More...
 

Variables

const uint32_t hw_uart_divisor [HW_UART_BAUDRATE_MAX]
 Baud rates dividers. More...
 

Detailed Description

UART Controller.

Macro Definition Documentation

◆ HW_UART_REG_FIELD_MASK

#define HW_UART_REG_FIELD_MASK (   instance,
  reg,
  field 
)    (UART##instance##_UART##instance##_##reg##_REG_##field##_Msk)

Get the mask of a field of a UART register.

Parameters
[in]instanceidentifies the UART instance to use (empty: UART, 2: UART2)
[in]regis the register to access
[in]fieldis the register field to access
Note
The stripped register name should be provided, e.g.:

◆ HW_UART_REG_FIELD_POS

#define HW_UART_REG_FIELD_POS (   instance,
  reg,
  field 
)    (UART##instance##_UART##instance##_##reg##_REG_##field##_Pos)

Get the bit position of a field of a UART register.

Parameters
[in]instanceidentifies the UART instance to use (empty: UART, 2: UART2)
[in]regis the register to access
[in]fieldis the register field to access
Note
The stripped register name should be provided, e.g.:

◆ HW_UART_REG_GETF

#define HW_UART_REG_GETF (   id,
  reg,
  field 
)    ((UBA(id)->UART2_##reg##_REG & (UART2_UART2_##reg##_REG_##field##_Msk)) >> (UART2_UART2_##reg##_REG_##field##_Pos))

Get the value of a field of a UART register.

Parameters
[in]ididentifies UART to use
[in]regis the register to access
[in]fieldis the register field to write
Returns
the value of the register field

◆ HW_UART_REG_SETF

#define HW_UART_REG_SETF (   id,
  reg,
  field,
  new_val 
)
Value:
UBA(id)->UART2_##reg##_REG = ((UBA(id)->UART2_##reg##_REG & ~(UART2_UART2_##reg##_REG_##field##_Msk)) | \
((UART2_UART2_##reg##_REG_##field##_Msk) & ((new_val) << (UART2_UART2_##reg##_REG_##field##_Pos))))

Set the value of a field of a UART register.

Parameters
[in]ididentifies UART to use
[in]regis the register to access
[in]fieldis the register field to write
[in]new_valis the value to write

Enumeration Type Documentation

◆ HW_UART_BAUDRATE

Baud rates.

Note
Baud rate values greater than 2000000 can only be selected when Doubler is used as system clock! Otherwise, a warning-assertion will be triggered!
Enumerator
HW_UART_BAUDRATE_1200 

baud rate 1200

HW_UART_BAUDRATE_2400 

baud rate 2400

HW_UART_BAUDRATE_4800 

baud rate 4800

HW_UART_BAUDRATE_9600 

baud rate 9600

HW_UART_BAUDRATE_14400 

baud rate 14400

HW_UART_BAUDRATE_19200 

baud rate 19200

HW_UART_BAUDRATE_28800 

baud rate 28800

HW_UART_BAUDRATE_38400 

baud rate 38400

HW_UART_BAUDRATE_57600 

baud rate 57600

HW_UART_BAUDRATE_115200 

baud rate 115200

HW_UART_BAUDRATE_230400 

baud rate 230400

HW_UART_BAUDRATE_256000 

baud rate 256000

HW_UART_BAUDRATE_460800 

baud rate 460800

HW_UART_BAUDRATE_500000 

baud rate 500000

HW_UART_BAUDRATE_921600 

baud rate 921600

HW_UART_BAUDRATE_1000000 

baud rate 1000000

HW_UART_BAUDRATE_2000000 

baud rate 2000000

HW_UART_BAUDRATE_3000000 

baud rate 3000000

HW_UART_BAUDRATE_MAX 

Invalid baud rate

◆ HW_UART_CONFIG_ERR

Configuration errors.

Enumerator
HW_UART_CONFIG_ERR_RX_FIFO 

RX FIFO level different than RX burst mode

HW_UART_CONFIG_ERR_TX_FIFO 

TX FIFO level different than TX burst mode

HW_UART_CONFIG_ERR_RXTX_FIFO 

RX and TX FIFO level different than TX RX burst mode

HW_UART_CONFIG_ERR_RX_SIZE 

Received buffer size is not aligned with burst mode

HW_UART_CONFIG_ERR_TX_SIZE 

Transmitted buffer size is not aligned with burst mode

◆ HW_UART_DATABITS

Character format.

◆ HW_UART_ERROR

Uart errors.

Enumerator
HW_UART_ERR_OE 

Overrun error

HW_UART_ERR_PE 

Parity error

HW_UART_ERR_FE 

Framing error

HW_UART_ERR_BI 

Break interrupt indication

HW_UART_ERR_RFE 

Receive FIFO error

◆ HW_UART_INT

Interrupt Identification codes.

◆ HW_UART_PARITY

Parity.

◆ HW_UART_STOPBITS

Stop bits.

Enumerator
HW_UART_STOPBITS_1 

The number of stop bits is 1.5 if a character format with 5 bit is chosen

HW_UART_STOPBITS_2 

Stop bit 2

Function Documentation

◆ hw_uart_abort_receive()

uint16_t hw_uart_abort_receive ( HW_UART_ID  uart)

Stop asynchronous read from UART.

If there is outstanding reception on given UART, it will be stopped. The callback function will be fired with the number of bytes already present in rx buffer. If DMA is used, the DMA channel will be stopped.

Parameters
[in]uartidentifies UART to use
Returns
number of bytes actually received

◆ hw_uart_abort_send()

uint16_t hw_uart_abort_send ( HW_UART_ID  uart)

Stop asynchronous transmit from UART.

If there is outstanding transmission from given UART, it will be stopped. The callback function will be fired with the least number of bytes that have been transmitted.

Parameters
[in]uartidentifies UART to use
Returns
number of bytes actually sent

◆ hw_uart_afce_getf()

uint8_t hw_uart_afce_getf ( HW_UART_ID  uart)

Get the Auto Flow Control Enable (AFCE) setting.

Parameters
[in]uartidentifies UART to use
Returns
Auto Flow Control Enable (AFCE): 0 = Auto Flow Control Mode disabled, 1 = Auto Flow Control Mode enabled

◆ hw_uart_afce_setf()

void hw_uart_afce_setf ( HW_UART_ID  uart,
uint8_t  afce 
)

Enable or disable Auto Flow Control.

Parameters
[in]uartidentifies UART to use
[in]afceAuto Flow Control Enable (AFCE): 0 = disable Auto Flow Control Mode, 1 = enable Auto Flow Control Mode

◆ hw_uart_baudrate_get()

HW_UART_BAUDRATE hw_uart_baudrate_get ( HW_UART_ID  uart)

Get the baud rate setting.

This functions returns the HW_UART_BAUDRATE value that corresponds to the baud rate that has been set. This value is basically the settings of the baud rate divider registers (DLH|DLH|DLF)), unless a high baud rate has been set that is part of the HW_UART_BAUDRATE enum.

Parameters
[in]uartidentifies UART to use
Returns
value of the HW_UART_BAUDRATE enum that corresponds to the baud rate set

◆ hw_uart_baudrate_set()

void hw_uart_baudrate_set ( HW_UART_ID  uart,
HW_UART_BAUDRATE  baud_rate 
)

Set the baud rate.

Parameters
[in]uartidentifies UART to use
[in]baud_rateuart baud rate
Note
the baud_rate parameter does not actually represent the baud rate itself, but the value of the HW_UART_BAUDRATE enum that corresponds to the desired baud rate or, - in case of low baud rates (i.e. in case baud_rate <0x100) simply the settings of the baud rate divider registers (DLH|DLH|DLF)). It is recommended to use the HW_UART_BAUDRATE enum for this.
If baud_rate < 0x100, an ASSERT_WARNING() is triggered unless all the conditions below are satisfied:
  • the selected value equals one of the high baud rate values of the HW_UART_BAUDRATE enum
  • Doubler is used as system clock
  • a uart instance that supports high baud rates is used (UART1/2).

◆ hw_uart_break_int_getf()

uint8_t hw_uart_break_int_getf ( HW_UART_ID  uart)

Get the value of the Break Interrupt bit.

Parameters
[in]uartidentifies UART to use
Returns
Break Interrupt bit value: This is used to indicate the detection of a break sequence on the serial input data.

◆ hw_uart_cfg_get()

void hw_uart_cfg_get ( HW_UART_ID  uart,
uart_config cfg 
)

Get UART line settings.

Parameters
[in]uartidentifies UART to use
[in]cfgpointer to the UART configuration structure

◆ hw_uart_cts_getf()

uint8_t hw_uart_cts_getf ( HW_UART_ID  uart)

Get CTS input status.

Parameters
[in]uartidentifies UART to use
Returns
status of CTS input: 0 = CTSn input is de-asserted (logic 1), 1 = CTSn input is asserted (logic 0), In loopback mode, CTS is the same as RTS.

◆ hw_uart_deinit()

void hw_uart_deinit ( HW_UART_ID  uart)

Disables UART controller.

Parameters
[in]uartUART controller instance

◆ hw_uart_delta_cts_getf()

uint8_t hw_uart_delta_cts_getf ( HW_UART_ID  uart)

Get Delta CTS.

Parameters
[in]uartidentifies UART to use
Returns
DCTS: 0 = No change on CTS since last read of Modem Control Register, 1 = Change on CTS since last read of Modem Control Register, Note that calling this function will clear the DCTS bit, In loopback mode, DCTS reflects changes on RTS.

◆ hw_uart_disable_fifo()

__STATIC_INLINE void hw_uart_disable_fifo ( HW_UART_ID  uart)

Disable both FIFOs.

Parameters
[in]uartidentifies UART to use

◆ hw_uart_disable_loopback()

__STATIC_INLINE void hw_uart_disable_loopback ( HW_UART_ID  uart)

Disable loopback.

Parameters
[in]uartidentifies UART to use

◆ hw_uart_enable_fifo()

__STATIC_INLINE void hw_uart_enable_fifo ( HW_UART_ID  uart)

Enable both FIFOs.

Thresholds should be set before for predictable results.

Parameters
[in]uartidentifies UART to use

◆ hw_uart_enable_loopback()

__STATIC_INLINE void hw_uart_enable_loopback ( HW_UART_ID  uart)

Enable loopback.

Parameters
[in]uartidentifies UART to use

◆ hw_uart_error_getf()

HW_UART_ERROR hw_uart_error_getf ( HW_UART_ID  uart)

Get the line status register error.

Parameters
[in]uartidentifies UART to use
Returns
the line status error

◆ hw_uart_fifo_en_getf()

uint8_t hw_uart_fifo_en_getf ( HW_UART_ID  uart)

Get the FIFO mode setting.

Parameters
[in]uartidentifies UART to use
Returns
the FIFO mode that has been set in the FIFO Control Register: 0 = FIFO mode disabled, 1 = FIFO mode enabled

◆ hw_uart_fifo_en_setf()

__STATIC_INLINE void hw_uart_fifo_en_setf ( HW_UART_ID  uart,
uint8_t  en 
)

Enable or disable the UART FIFO mode.

Parameters
[in]uartidentifies UART to use
[in]enshould be 0 to disable and 1 to enable FIFO mode

◆ hw_uart_frame_err_getf()

uint8_t hw_uart_frame_err_getf ( HW_UART_ID  uart)

Get the value of the Framing Error bit.

Parameters
[in]uartidentifies UART to use
Returns
Framing Error bit value: 0 = no framing error, 1 = framing error

◆ hw_uart_get_interrupt_id()

__STATIC_INLINE HW_UART_INT hw_uart_get_interrupt_id ( HW_UART_ID  uart)

Get the Interrupt ID.

Parameters
[in]uartidentifies UART to use
Returns
interrupt type

◆ hw_uart_init()

HW_UART_CONFIG_ERR hw_uart_init ( HW_UART_ID  uart,
const uart_config cfg 
)

Set UART line settings.

This function initializes UART registers with given configuration, including tx and rx FIFO trigger levels. It also initializes all internal software variables for buffered transmissions. Extra care is needed when configuring DMA burst mode and FIFO trigger level: If DMA burst mode is 4x, then the TX or RX trigger level should be 1/4 full. If DMA burst mode is 8x, then the TX or RX trigger level should be 1/2 full.

Parameters
[in]uartidentifies UART to use
[in]cfgpointer to the UART configuration structure
Returns
FIFO and burst mode configuration error: HW_UART_CONFIG_ERR_RX_FIFO = rx FIFO trigger level is different than rx dma burst HW_UART_CONFIG_ERR_TX_FIFO = tx FIFO trigger level is different than tx dma burst
Warning
Extra care is needed when configuring DMA burst mode and FIFO trigger level: If DMA burst mode is 4x, then the TX or RX trigger level should be 1/4 full. If DMA burst mode is 8x, then the TX or RX trigger level should be 1/2 full.

◆ hw_uart_is_busy()

__STATIC_INLINE bool hw_uart_is_busy ( HW_UART_ID  uart)

Check if a serial transfer is in progress.

Returns
true or false

◆ hw_uart_is_data_ready()

__STATIC_INLINE bool hw_uart_is_data_ready ( HW_UART_ID  uart)

Check if there is data available for read.

Parameters
[in]uartidentifies UART to use
Returns
true if there is data to receive

◆ hw_uart_is_fifo_enabled()

__STATIC_INLINE bool hw_uart_is_fifo_enabled ( HW_UART_ID  uart)

Get the FIFO mode setting.

Parameters
[in]uartidentifies UART to use
Returns
true if FIFO is enabled (both transmitter and receiver)

◆ hw_uart_is_tx_fifo_empty()

uint8_t hw_uart_is_tx_fifo_empty ( HW_UART_ID  uart)

Get the value of the Transmitter Empty bit.

Parameters
[in]uartidentifies UART to use
Returns
1 if transmitter FIFO is empty

◆ hw_uart_linestat_int_set()

__STATIC_INLINE void hw_uart_linestat_int_set ( HW_UART_ID  uart,
uint8_t  linestat 
)

Set the Line Status interrupt.

Parameters
[in]uartidentifies UART to use
[in]linestatshould be 0 to disable and 1 to enable

◆ hw_uart_loopback_getf()

uint8_t hw_uart_loopback_getf ( HW_UART_ID  uart)

Get UART diagnostic mode status.

Parameters
[in]uartidentifies UART to use
Returns
the value of the loop back bit

◆ hw_uart_loopback_setf()

void hw_uart_loopback_setf ( HW_UART_ID  uart,
uint8_t  lb 
)

Set UART in diagnostic mode.

Parameters
[in]uartidentifies UART to use
[in]lbloop back bit value

◆ hw_uart_overrun_err_getf()

uint8_t hw_uart_overrun_err_getf ( HW_UART_ID  uart)

Get the value of the Overrun Error bit.

Parameters
[in]uartidentifies UART to use
Returns
Overrun Error bit value: 0 = no overrun error, 1 = overrun error

◆ hw_uart_parity_err_getf()

uint8_t hw_uart_parity_err_getf ( HW_UART_ID  uart)

Get the value of the Parity Error bit.

Parameters
[in]uartidentifies UART to use
Returns
Parity Error bit value: 0 = no parity error, 1 = parity error

◆ hw_uart_peek_received()

uint16_t hw_uart_peek_received ( HW_UART_ID  uart)

Get number of bytes currently received by asynchronous read.

If there is outstanding read on given UART, the function returns the number of bytes currently received.

Parameters
[in]uartidentifies UART to use

◆ hw_uart_peek_transmitted()

uint16_t hw_uart_peek_transmitted ( HW_UART_ID  uart)

Get number of bytes currently sent by asynchronous read.

If there is outstanding sending on given UART, the function returns the number of bytes currently sent.

Parameters
[in]uartidentifies UART to use

◆ hw_uart_pthre_int_set()

__STATIC_INLINE void hw_uart_pthre_int_set ( HW_UART_ID  uart,
uint8_t  pthre 
)

Set the Programmable THRE interrupt.

Parameters
[in]uartidentifies UART to use
[in]pthreshould be 0 to disable and 1 to enable

◆ hw_uart_read()

uint8_t hw_uart_read ( HW_UART_ID  uart)

Read one byte from UART.

This is a blocking function to read single byte from UART. UART must be enabled before.

Parameters
[in]uartidentifies UART to use
Returns
the received byte

◆ hw_uart_read_buf_empty()

__STATIC_INLINE bool hw_uart_read_buf_empty ( HW_UART_ID  uart)

Check whether reading buffer is empty.

Works for both when Rx FIFO is enabled or not.

Parameters
[in]uartidentifies UART to use
Returns
true if there is no data available for reading

◆ hw_uart_read_scr()

__STATIC_INLINE uint8_t hw_uart_read_scr ( const HW_UART_ID  uart)

Read Scratch pad register.

Parameters
[in]uartidentifies UART to use
Returns
register value
Warning
Reserved when retarget is used, else it is free to use.

◆ hw_uart_rec_data_int_set()

__STATIC_INLINE void hw_uart_rec_data_int_set ( HW_UART_ID  uart,
uint8_t  recdataavail 
)

Set the Received Data Available interrupt.

Parameters
[in]uartidentifies UART to use
[in]recdataavailshould be 0 to disable and 1 to enable

◆ hw_uart_receive()

HW_UART_CONFIG_ERR hw_uart_receive ( HW_UART_ID  uart,
void *  data,
uint16_t  len,
hw_uart_rx_callback  cb,
void *  user_data 
)

Read number of bytes from UART.

This function initializes UART for receiving data. When len data is received or timeout occurs, user provided callback function will be fired with number of bytes read so far.

Parameters
[in]uartidentifies UART to use
[out]databuffer for incoming data
[in]lenmax number of bytes to read
[in]cbfunction to call from interrupt when data is received
[in]user_dataparameter passed to cb function
Returns
success or no success of receiving: HW_UART_CONFIG_ERR_NOERR = successful reception HW_UART_CONFIG_ERR_RX_SIZE = unsuccessful reception, dma burst mode level incorrect

◆ hw_uart_receive_error_checking()

void hw_uart_receive_error_checking ( HW_UART_ID  uart,
void *  data,
uint16_t  len,
hw_uart_rx_callback  cb,
void *  user_data,
hw_uart_err_callback  err_cb,
void *  error_data 
)

Read number of bytes from UART with error checking.

Function initializes UART for receiving data. It is a superset of the hw_uart_receive and provides information about the receiving errors. When len data is received or timeout occurs user provided callback will be fired with number of bytes read so far. If an error occurrs during reception, the err_cb will be called providing info about the error type.

Parameters
[in]uartidentifies UART to use
[out]databuffer for incoming data
[in]lenmax number of bytes to read
[in]cbfunction to call from interrupt when data is received
[in]user_dataparameter passed to cb function
[in]err_cbfunction to call from interrupt when an error is detected
[in]error_dataparameter passed to err_cb function

◆ hw_uart_receive_fifo_count()

__STATIC_INLINE uint16_t hw_uart_receive_fifo_count ( HW_UART_ID  uart)

Read number of bytes in receive FIFO.

Parameters
[in]uartidentifies UART to use
Returns
number of bytes in receive FIFO

◆ hw_uart_receive_fifo_not_empty()

__STATIC_INLINE bool hw_uart_receive_fifo_not_empty ( HW_UART_ID  uart)

Check if receive FIFO is not empty.

Parameters
[in]uartidentifies UART to use
Returns
true if FIFO is not empty

◆ hw_uart_reinit()

void hw_uart_reinit ( HW_UART_ID  uart,
const uart_config cfg 
)

Re-initialize UART registers.

Call this function with the configuration that should be re-applied. It should be called after platform exits power sleep mode. This function is similar to uart_init_ex, but it does not initialize software variables used for transmission control; it just re-applies hardware configuration. It will turn on interrupts if transmission is in progress.

Parameters
[in]uartidentifies UART to use
[in]cfgpointer to the UART configuration structure

◆ hw_uart_rts_getf()

uint8_t hw_uart_rts_getf ( HW_UART_ID  uart)

Get RTS output value.

Parameters
[in]uartidentifies UART to use
Returns
RTS output value

◆ hw_uart_rts_setf()

void hw_uart_rts_setf ( HW_UART_ID  uart,
uint8_t  rtsn 
)

Set RTS output value.

Parameters
[in]uartidentifies UART to use
[in]rtsnValue for the RTS output (asserted low)

◆ hw_uart_rx_fifo_err_getf()

uint8_t hw_uart_rx_fifo_err_getf ( HW_UART_ID  uart)

Get the value of the Receiver FIFO Error bit.

Parameters
[in]uartidentifies UART to use
Returns
Receiver FIFO Error bit value: 0 = no error in RX FIFO, 1 = error in RX FIFO

◆ hw_uart_rx_fifo_flush()

__STATIC_INLINE void hw_uart_rx_fifo_flush ( HW_UART_ID  uart)

Reset UART receive FIFO.

Parameters
[in]uartidentifies UART to use

◆ hw_uart_rx_fifo_tr_lvl_getf()

__STATIC_INLINE uint8_t hw_uart_rx_fifo_tr_lvl_getf ( HW_UART_ID  uart)

Get the receive FIFO trigger level at which the Received Data Available Interrupt is generated.

Parameters
[in]uartidentifies UART to use
Returns
the receive FIFO trigger level: 0 = 1 character in the FIFO, 1 = FIFO 1/4 full, 2 = FIFO 1/2 full, 3 = FIFO 2 less than full

◆ hw_uart_rx_fifo_tr_lvl_setf()

__STATIC_INLINE void hw_uart_rx_fifo_tr_lvl_setf ( HW_UART_ID  uart,
uint8_t  tr_lvl 
)

Set the receive FIFO trigger level at which the Received Data Available Interrupt is generated.

Parameters
[in]uartidentifies UART to use
[in]tr_lvlthe receive FIFO trigger level: 0 = 1 character in the FIFO, 1 = FIFO 1/4 full, 2 = FIFO 1/2 full, 3 = FIFO 2 less than full

◆ hw_uart_rx_in_progress()

bool hw_uart_rx_in_progress ( const HW_UART_ID  uart)

Check if buffered read is in progress.

Parameters
[in]uartidentifies UART to use
Returns
true if there is RX transmission in progress

◆ hw_uart_rxdata_getf()

__STATIC_INLINE uint8_t hw_uart_rxdata_getf ( HW_UART_ID  uart)

Read receive buffer register.

Parameters
[in]uartidentifies UART to use
Returns
the read byte

◆ hw_uart_send()

HW_UART_CONFIG_ERR hw_uart_send ( HW_UART_ID  uart,
const void *  data,
uint16_t  len,
hw_uart_tx_callback  cb,
void *  user_data 
)

Write number of bytes to UART.

Parameters
[in]uartidentifies UART to use
[in]datadata to be written
[in]lennumber of bytes to be written
[in]cbfunction to call from interrupt when transmission ends
[in]user_dataparameter passed to cb function
Returns
success or no success of sending: HW_UART_CONFIG_ERR_NOERR = successful transmit HW_UART_CONFIG_ERR_TX_SIZE = unsuccessful transmit, dma burst mode level incorrect

◆ hw_uart_set_sclk()

void hw_uart_set_sclk ( const HW_UART_ID  uart,
bool  sclk 
)

Configure the serial clock input of the UART (divN or div1)

This function allows the user to use custom high baud rates. The baud rates that can be used are not only the ones that are part of the HW_UART_BAUDRATE enum.

Parameters
[in]uartidentifies UART to use
[in]sclkSerial clock, if true then DIV1 is used otherwise DIVN.

◆ hw_uart_thr_empty_getf()

uint8_t hw_uart_thr_empty_getf ( HW_UART_ID  uart)

Get the value of the Transmit Holding Register Empty bit.

Parameters
[in]uartidentifies UART to use
Returns
Transmit Holding Register Empty bit value

◆ hw_uart_transmit_empty()

__STATIC_INLINE bool hw_uart_transmit_empty ( HW_UART_ID  uart)

Check whether transmitter is empty.

If FIFOs are enabled (FCR[0] set to one), this bit is set whenever the Transmitter Shift Register and the FIFO are both empty. If FIFOs are disabled, this bit is set whenever the Transmitter Holding Register and the Transmitter Shift Register are both empty.

Parameters
[in]uartidentifies UART to use
Returns
true if transmitter is empty

◆ hw_uart_transmit_fifo_count()

__STATIC_INLINE uint16_t hw_uart_transmit_fifo_count ( HW_UART_ID  uart)

Read number of bytes in transmit FIFO.

Parameters
[in]uartidentifies UART to use
Returns
number of bytes in transmit FIFO

◆ hw_uart_transmit_fifo_empty()

__STATIC_INLINE bool hw_uart_transmit_fifo_empty ( HW_UART_ID  uart)

Check if transmit FIFO is empty.

Parameters
[in]uartidentifies UART to use
Returns
true if FIFO empty

◆ hw_uart_transmit_fifo_not_full()

__STATIC_INLINE bool hw_uart_transmit_fifo_not_full ( HW_UART_ID  uart)

Check if transmit FIFO is not full.

Parameters
[in]uartidentifies UART to use
Returns
true if FIFO is full

◆ hw_uart_tx_empty_int_set()

__STATIC_INLINE void hw_uart_tx_empty_int_set ( HW_UART_ID  uart,
uint8_t  txempty 
)

Set the Transmit Holding Register empty interrupt.

Parameters
[in]uartidentifies UART to use
[in]txemptyshould be 0 to disable and 1 to enable

◆ hw_uart_tx_fifo_flush()

__STATIC_INLINE void hw_uart_tx_fifo_flush ( HW_UART_ID  uart)

Reset UART transmit FIFO.

Parameters
[in]uartidentifies UART to use

◆ hw_uart_tx_fifo_tr_lvl_getf()

uint8_t hw_uart_tx_fifo_tr_lvl_getf ( HW_UART_ID  uart)

Get the transmit FIFO trigger level at which the Transmit Holding Register Empty (THRE) Interrupt is generated.

Parameters
[in]uartidentifies UART to use
Returns
the transmit FIFO trigger level: 0 = FIFO empty, 1 = 2 characters in the FIFO, 2 = FIFO 1/4 full, 3 = FIFO 1/2 full

◆ hw_uart_tx_fifo_tr_lvl_setf()

__STATIC_INLINE void hw_uart_tx_fifo_tr_lvl_setf ( HW_UART_ID  uart,
uint8_t  tr_lvl 
)

Set the transmit FIFO trigger level at which the Transmit Holding Register Empty (THRE) Interrupt is generated.

Parameters
[in]uartidentifies UART to use
[in]tr_lvlthe transmit FIFO trigger level: 0 = FIFO empty, 1 = 2 characters in the FIFO, 2 = FIFO 1/4 full, 3 = FIFO 1/2 full

◆ hw_uart_tx_in_progress()

bool hw_uart_tx_in_progress ( const HW_UART_ID  uart)

Check if buffered write is in progress.

Parameters
[in]uartidentifies UART to use
Returns
true if there is TX transmission in progress

◆ hw_uart_txdata_setf()

__STATIC_INLINE void hw_uart_txdata_setf ( HW_UART_ID  uart,
uint8_t  data 
)

Write byte to the transmit holding register.

Parameters
[in]uartidentifies UART to use
[in]databyte to be written

◆ hw_uart_write()

void hw_uart_write ( HW_UART_ID  uart,
uint8_t  data 
)

Write one byte to UART.

This function waits till output FIFO has empty space according to threshold level, and puts byte to be transmitted.

Parameters
[in]uartidentifies UART to use
[in]databyte to be written

◆ hw_uart_write_buf_full()

__STATIC_INLINE bool hw_uart_write_buf_full ( HW_UART_ID  uart)

Check whether writing buffer is full.

Works for both when Tx FIFO is enabled or not.

Parameters
[in]uartidentifies UART to use
Returns
true if transmit buffer is full

◆ hw_uart_write_buffer()

void hw_uart_write_buffer ( HW_UART_ID  uart,
const void *  data,
uint16_t  len 
)

Writes number of bytes to UART synchronously.

This function finishes when all data is put in FIFO. It does not wait for data to be transmitted out from UART. Call

See also
hw_uart_is_tx_fifo_empty() to wait for transmission to finish. This function does not use interrupts, nor DMA.
Parameters
[in]uartidentifies UART to use
[in]datadata to be written
[in]lennumber of bytes to be written

◆ hw_uart_write_scr()

__STATIC_INLINE void hw_uart_write_scr ( const HW_UART_ID  uart,
uint8_t  value 
)

Write Scratch pad register.

Parameters
[in]uartidentifies UART to use
[in]valuethe value to be written
Warning
Reserved when retarget is used, else it is free to use.

Variable Documentation

◆ hw_uart_divisor

const uint32_t hw_uart_divisor[HW_UART_BAUDRATE_MAX]

Baud rates dividers.

The defined values comprise the values of 3 registers: DLH, DLL, DLF. The encoding of the values for each register is:

+-----—+-----—+-----—+-----—+ | unused | DLH | DLL | DLF | +-----—+-----—+-----—+-----—+

Note
BAUDRATE_3000000 -> Requires Doubler@64MHz to be used as sys clk! An actual baud rate of 3047619.05 will be generated!