NEORV32 Software Framework Documentation
The NEORV32 RISC-V Processor
Loading...
Searching...
No Matches
neorv32_uart.c File Reference

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

#include <neorv32.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>

Functions

int neorv32_uart_available (neorv32_uart_t *UARTx)
 
void neorv32_uart_setup (neorv32_uart_t *UARTx, uint32_t baudrate, uint32_t irq_mask)
 
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_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)
 
void neorv32_uart_rx_clear (neorv32_uart_t *UARTx)
 
void neorv32_uart_tx_clear (neorv32_uart_t *UARTx)
 
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)
 

Detailed Description

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

Note
These functions should only be used if the UART0/UART1 unit was synthesized.
See also
https://stnolting.github.io/neorv32/sw/files.html

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.

Warning
: This functions only provides a minimal subset of the 'printf' formatting features!
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_rx_clear()

void neorv32_uart_rx_clear ( neorv32_uart_t * UARTx)

Clear RX FIFO.

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 (including zero-termination).
[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_tx_clear()

void neorv32_uart_tx_clear ( neorv32_uart_t * UARTx)

Clear TX FIFO.

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

◆ neorv32_uart_vprintf()

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

Custom version of 'vprintf' printing to UART.

Warning
: This functions only provides a minimal subset of the 'vprintf' formating features!
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.