NEORV32 - Software Framework Documentation
Loading...
Searching...
No Matches
Data Structures
neorv32_uart.h File Reference

Universal asynchronous receiver/transmitter (UART0/UART1) HW driver header file. More...

#include <stdarg.h>

Go to the source code of this file.

Data Structures

struct  neorv32_uart_t
 

Functions

Prototypes
int neorv32_uart_available (neorv32_uart_t *UARTx)
 
int neorv32_uart_get_rx_fifo_depth (neorv32_uart_t *UARTx)
 
int neorv32_uart_get_tx_fifo_depth (neorv32_uart_t *UARTx)
 
void neorv32_uart_setup (neorv32_uart_t *UARTx, uint32_t baudrate, uint32_t irq_mask)
 
void neorv32_uart_enable (neorv32_uart_t *UARTx)
 
void neorv32_uart_disable (neorv32_uart_t *UARTx)
 
void neorv32_uart_rtscts_enable (neorv32_uart_t *UARTx)
 
void neorv32_uart_rtscts_disable (neorv32_uart_t *UARTx)
 
void neorv32_uart_putc (neorv32_uart_t *UARTx, char c)
 
int neorv32_uart_tx_busy (neorv32_uart_t *UARTx)
 
char neorv32_uart_getc (neorv32_uart_t *UARTx)
 
int neorv32_uart_char_received (neorv32_uart_t *UARTx)
 
char neorv32_uart_char_received_get (neorv32_uart_t *UARTx)
 
void neorv32_uart_puts (neorv32_uart_t *UARTx, const char *s)
 
void neorv32_uart_vprintf (neorv32_uart_t *UARTx, const char *format, va_list args)
 
void neorv32_uart_printf (neorv32_uart_t *UARTx, const char *format,...)
 
int neorv32_uart_scan (neorv32_uart_t *UARTx, char *buffer, int max_size, int echo)
 

IO Device: Primary/Secondary Universal Asynchronous Receiver and Transmitter (UART0 / UART1)

#define NEORV32_UART0   ((neorv32_uart_t*) (NEORV32_UART0_BASE))
 
#define NEORV32_UART1   ((neorv32_uart_t*) (NEORV32_UART1_BASE))
 
enum  NEORV32_UART_CTRL_enum {
  UART_CTRL_EN = 0 , UART_CTRL_SIM_MODE = 1 , UART_CTRL_HWFC_EN = 2 , UART_CTRL_PRSC0 = 3 ,
  UART_CTRL_PRSC1 = 4 , UART_CTRL_PRSC2 = 5 , UART_CTRL_BAUD0 = 6 , UART_CTRL_BAUD1 = 7 ,
  UART_CTRL_BAUD2 = 8 , UART_CTRL_BAUD3 = 9 , UART_CTRL_BAUD4 = 10 , UART_CTRL_BAUD5 = 11 ,
  UART_CTRL_BAUD6 = 12 , UART_CTRL_BAUD7 = 13 , UART_CTRL_BAUD8 = 14 , UART_CTRL_BAUD9 = 15 ,
  UART_CTRL_RX_NEMPTY = 16 , UART_CTRL_RX_HALF = 17 , UART_CTRL_RX_FULL = 18 , UART_CTRL_TX_EMPTY = 19 ,
  UART_CTRL_TX_NHALF = 20 , UART_CTRL_TX_FULL = 21 , UART_CTRL_IRQ_RX_NEMPTY = 22 , UART_CTRL_IRQ_RX_HALF = 23 ,
  UART_CTRL_IRQ_RX_FULL = 24 , UART_CTRL_IRQ_TX_EMPTY = 25 , UART_CTRL_IRQ_TX_NHALF = 26 , UART_CTRL_RX_OVER = 30 ,
  UART_CTRL_TX_BUSY = 31
}
 
enum  NEORV32_UART_DATA_enum {
  UART_DATA_RTX_LSB = 0 , UART_DATA_RTX_MSB = 7 , UART_DATA_RX_FIFO_SIZE_LSB = 8 , UART_DATA_RX_FIFO_SIZE_MSB = 11 ,
  UART_DATA_TX_FIFO_SIZE_LSB = 12 , UART_DATA_TX_FIFO_SIZE_MSB = 15
}
 

Detailed Description

Universal asynchronous receiver/transmitter (UART0/UART1) HW driver header file.

Macro Definition Documentation

◆ NEORV32_UART0

#define NEORV32_UART0   ((neorv32_uart_t*) (NEORV32_UART0_BASE))

UART0 module hardware access (neorv32_uart_t)

◆ NEORV32_UART1

#define NEORV32_UART1   ((neorv32_uart_t*) (NEORV32_UART1_BASE))

UART1 module hardware access (neorv32_uart_t)

Enumeration Type Documentation

◆ NEORV32_UART_CTRL_enum

UART control register bits

Enumerator
UART_CTRL_EN 

UART control register(0) (r/w): UART global enable

UART_CTRL_SIM_MODE 

UART control register(1) (r/w): Simulation output override enable

UART_CTRL_HWFC_EN 

UART control register(2) (r/w): Enable RTS/CTS hardware flow-control

UART_CTRL_PRSC0 

UART control register(3) (r/w): clock prescaler select bit 0

UART_CTRL_PRSC1 

UART control register(4) (r/w): clock prescaler select bit 1

UART_CTRL_PRSC2 

UART control register(5) (r/w): clock prescaler select bit 2

UART_CTRL_BAUD0 

UART control register(6) (r/w): BAUD rate divisor, bit 0

UART_CTRL_BAUD1 

UART control register(7) (r/w): BAUD rate divisor, bit 1

UART_CTRL_BAUD2 

UART control register(8) (r/w): BAUD rate divisor, bit 2

UART_CTRL_BAUD3 

UART control register(9) (r/w): BAUD rate divisor, bit 3

UART_CTRL_BAUD4 

UART control register(10) (r/w): BAUD rate divisor, bit 4

UART_CTRL_BAUD5 

UART control register(11) (r/w): BAUD rate divisor, bit 5

UART_CTRL_BAUD6 

UART control register(12) (r/w): BAUD rate divisor, bit 6

UART_CTRL_BAUD7 

UART control register(13) (r/w): BAUD rate divisor, bit 7

UART_CTRL_BAUD8 

UART control register(14) (r/w): BAUD rate divisor, bit 8

UART_CTRL_BAUD9 

UART control register(15) (r/w): BAUD rate divisor, bit 9

UART_CTRL_RX_NEMPTY 

UART control register(16) (r/-): RX FIFO not empty

UART_CTRL_RX_HALF 

UART control register(17) (r/-): RX FIFO at least half-full

UART_CTRL_RX_FULL 

UART control register(18) (r/-): RX FIFO full

UART_CTRL_TX_EMPTY 

UART control register(19) (r/-): TX FIFO empty

UART_CTRL_TX_NHALF 

UART control register(20) (r/-): TX FIFO not at least half-full

UART_CTRL_TX_FULL 

UART control register(21) (r/-): TX FIFO full

UART_CTRL_IRQ_RX_NEMPTY 

UART control register(22) (r/w): Fire IRQ if RX FIFO not empty

UART_CTRL_IRQ_RX_HALF 

UART control register(23) (r/w): Fire IRQ if RX FIFO at least half-full

UART_CTRL_IRQ_RX_FULL 

UART control register(24) (r/w): Fire IRQ if RX FIFO full

UART_CTRL_IRQ_TX_EMPTY 

UART control register(25) (r/w): Fire IRQ if TX FIFO empty

UART_CTRL_IRQ_TX_NHALF 

UART control register(26) (r/w): Fire IRQ if TX FIFO not at least half-full

UART_CTRL_RX_OVER 

UART control register(30) (r/-): RX FIFO overflow

UART_CTRL_TX_BUSY 

UART control register(31) (r/-): Transmitter busy or TX FIFO not empty

◆ NEORV32_UART_DATA_enum

UART data register bits

Enumerator
UART_DATA_RTX_LSB 

UART data register(0) (r/w): UART receive/transmit data, LSB

UART_DATA_RTX_MSB 

UART data register(7) (r/w): UART receive/transmit data, MSB

UART_DATA_RX_FIFO_SIZE_LSB 

UART data register(8) (r/-): log2(RX FIFO size), LSB

UART_DATA_RX_FIFO_SIZE_MSB 

UART data register(11) (r/-): log2(RX FIFO size), MSB

UART_DATA_TX_FIFO_SIZE_LSB 

UART data register(12) (r/-): log2(RX FIFO size), LSB

UART_DATA_TX_FIFO_SIZE_MSB 

UART data register(15) (r/-): log2(RX FIFO size), MSB

Function Documentation

◆ neorv32_uart_available()

int neorv32_uart_available ( neorv32_uart_t UARTx)

Check if UART unit was synthesized.

Parameters
[in,out]Hardwarehandle to UART register struct, neorv32_uart_t.
Returns
0 if UART0/1 was not synthesized, 1 if UART0/1 is available.

◆ neorv32_uart_char_received()

int neorv32_uart_char_received ( neorv32_uart_t UARTx)

Check if UART has received a char.

Note
This function is non-blocking.
Use neorv32_uart_char_received_get(void) to get the char.
Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.
Returns
1 when a char has been received, 0 otherwise.

◆ neorv32_uart_char_received_get()

char neorv32_uart_char_received_get ( neorv32_uart_t UARTx)

Get a received char from UART.

Note
This function is non-blocking.
Should only be used in combination with neorv32_uart_char_received(void).
Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.
Returns
Received char.

◆ neorv32_uart_disable()

void neorv32_uart_disable ( neorv32_uart_t UARTx)

Disable UART.

Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.

◆ neorv32_uart_enable()

void neorv32_uart_enable ( neorv32_uart_t UARTx)

Enable UART.

Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.

◆ neorv32_uart_get_rx_fifo_depth()

int neorv32_uart_get_rx_fifo_depth ( neorv32_uart_t UARTx)

Get UART RX FIFO depth.

Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.
Returns
FIFO depth (number of entries)

◆ neorv32_uart_get_tx_fifo_depth()

int neorv32_uart_get_tx_fifo_depth ( neorv32_uart_t UARTx)

Get UART TX FIFO depth.

Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.
Returns
FIFO depth (number of entries)

◆ neorv32_uart_getc()

char neorv32_uart_getc ( neorv32_uart_t UARTx)

Get char from UART.

Note
This function is blocking.
Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.
Returns
Received char.

◆ neorv32_uart_printf()

void neorv32_uart_printf ( neorv32_uart_t UARTx,
const char *  format,
  ... 
)

Custom version of 'printf' printing to UART.

Note
This function is blocking.
Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.
[in]formatPointer to format string. See neorv32_uart_vprintf.

◆ neorv32_uart_putc()

void neorv32_uart_putc ( neorv32_uart_t UARTx,
char  c 
)

Send single char via UART.

Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.
[in]cChar to be send.

◆ neorv32_uart_puts()

void neorv32_uart_puts ( neorv32_uart_t UARTx,
const char *  s 
)

Print string (zero-terminated) via UART. Print full line break "\r\n" for every '
'.

Note
This function is blocking.
Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.
[in]sPointer to string.

◆ neorv32_uart_rtscts_disable()

void neorv32_uart_rtscts_disable ( neorv32_uart_t UARTx)

Disable RTS/CTS hardware flow-control.

Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.

◆ neorv32_uart_rtscts_enable()

void neorv32_uart_rtscts_enable ( neorv32_uart_t UARTx)

Enable RTS/CTS hardware flow-control.

Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.

◆ neorv32_uart_scan()

int neorv32_uart_scan ( neorv32_uart_t UARTx,
char *  buffer,
int  max_size,
int  echo 
)

Simplified custom version of 'scanf' reading from UART.

Note
This function is blocking.
Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.
[in,out]bufferPointer to array of chars to store string.
[in]max_sizeMaximum number of chars to sample.
[in]echoEcho UART input when 1.
Returns
Number of chars read.

◆ neorv32_uart_setup()

void neorv32_uart_setup ( neorv32_uart_t UARTx,
uint32_t  baudrate,
uint32_t  irq_mask 
)

Reset, configure and enable UART.

Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.
[in]baudrateTargeted BAUD rate (e.g. 19200).
[in]irq_maskInterrupt configuration mask (CTRL's irq_* bits).

◆ neorv32_uart_tx_busy()

int neorv32_uart_tx_busy ( neorv32_uart_t UARTx)

Check if UART TX is busy (transmitter busy or data left in TX buffer).

Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.
Returns
0 if idle, 1 if busy

◆ neorv32_uart_vprintf()

void neorv32_uart_vprintf ( neorv32_uart_t UARTx,
const char *  format,
va_list  args 
)

Custom version of 'vprintf' printing to UART.

Note
This function is blocking.
Parameters
[in,out]UARTxHardware handle to UART register struct, neorv32_uart_t.
[in]formatPointer to format string.
[in]argsA value identifying a variable arguments list.
sString (array of chars, zero-terminated)
cSingle char
d/i32-bit signed number, printed as decimal
u32-bit unsigned number, printed as decimal
x32-bit number, printed as 8-char hexadecimal - lower-case
X32-bit number, printed as 8-char hexadecimal - upper-case
p32-bit pointer, printed as 8-char hexadecimal - lower-case