NEORV32 - Software Framework Documentation
Loading...
Searching...
No Matches
Functions
neorv32_uart.c File Reference

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

#include "neorv32.h"
#include "neorv32_uart.h"
#include <string.h>
#include <stdarg.h>

Functions

static void __neorv32_uart_itoa (uint32_t x, char *res)
 
static void __neorv32_uart_tohex (uint32_t x, char *res)
 
static void __neorv32_uart_touppercase (uint32_t len, char *ptr)
 
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)
 
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)
 
int putchar (int ch)
 
int getchar (void)
 

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.

Function Documentation

◆ __neorv32_uart_itoa()

static void __neorv32_uart_itoa ( uint32_t x,
char * res )
static

Private function for 'neorv32_printf' to convert into decimal.

Parameters
[in]xUnsigned input number.
[in,out]resPointer for storing the reuslting number string (11 chars).

◆ __neorv32_uart_tohex()

static void __neorv32_uart_tohex ( uint32_t x,
char * res )
static

Private function for 'neorv32_printf' to convert into hexadecimal.

Parameters
[in]xUnsigned input number.
[in,out]resPointer for storing the resulting number string (9 chars).

◆ __neorv32_uart_touppercase()

static void __neorv32_uart_touppercase ( uint32_t len,
char * ptr )
static

Private function to cast a string to UPPERCASE.

Parameters
[in]lenTotal length of input string.
[in,out]ptrPointer for input/output string.

◆ getchar()

int getchar ( void )

STDIO: Read char from UART0.

Returns
Read char.

◆ 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

◆ putchar()

int putchar ( int ch)

STDIO: Send char via UART0

Parameters
[in]Charto be send.
Returns
Char that has been sent.