Line 78... |
Line 78... |
* @note To enable simulation mode add <USER_FLAGS+=-DUART0_SIM_MODE> when compiling.
|
* @note To enable simulation mode add <USER_FLAGS+=-DUART0_SIM_MODE> when compiling.
|
*
|
*
|
* @warning The baud rate is computed using INTEGER operations (truncation errors might occur).
|
* @warning The baud rate is computed using INTEGER operations (truncation errors might occur).
|
*
|
*
|
* @param[in] baudrate Targeted BAUD rate (e.g. 9600).
|
* @param[in] baudrate Targeted BAUD rate (e.g. 9600).
|
* @param[in] parity Parity configuration (00=off, 10=even, 11=odd).
|
* @param[in] parity Parity configuration (00=off, 10=even, 11=odd), see #NEORV32_UART_PARITY_enum.
|
|
* @param[in] flow_con Hardware flow control configuration (00=off, 01=RTS, 10=CTS, 11=RTS/CTS), see #NEORV32_UART_FLOW_CONTROL_enum.
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_uart_setup(uint32_t baudrate, uint8_t parity) { neorv32_uart0_setup(baudrate, parity); }
|
void neorv32_uart_setup(uint32_t baudrate, uint8_t parity, uint8_t flow_con) { neorv32_uart0_setup(baudrate, parity, flow_con); }
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Disable UART0.
|
* Disable UART0.
|
* @warning This functions maps to UART0 (primary UART).
|
* @warning This functions maps to UART0 (primary UART).
|
Line 144... |
Line 145... |
* @note This function is non-blocking and checks for frame and parity errors.
|
* @note This function is non-blocking and checks for frame and parity errors.
|
*
|
*
|
* @param[in,out] data Received char.
|
* @param[in,out] data Received char.
|
* @return Status code (0=nothing received, 1: char received without errors; -1: char received with frame error; -2: char received with parity error; -3 char received with frame & parity error).
|
* @return Status code (0=nothing received, 1: char received without errors; -1: char received with frame error; -2: char received with parity error; -3 char received with frame & parity error).
|
**************************************************************************/
|
**************************************************************************/
|
int neorv32_uart_getc_secure(char *data) { return neorv32_uart0_getc_secure(data); }
|
int neorv32_uart_getc_safe(char *data) { return neorv32_uart0_getc_safe(data); }
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Get a received char from UART0.
|
* Get a received char from UART0.
|
*
|
*
|
Line 233... |
Line 234... |
* @note To enable simulation mode add <USER_FLAGS+=-DUART0_SIM_MODE> when compiling.
|
* @note To enable simulation mode add <USER_FLAGS+=-DUART0_SIM_MODE> when compiling.
|
*
|
*
|
* @warning The baud rate is computed using INTEGER operations (truncation errors might occur).
|
* @warning The baud rate is computed using INTEGER operations (truncation errors might occur).
|
*
|
*
|
* @param[in] baudrate Targeted BAUD rate (e.g. 9600).
|
* @param[in] baudrate Targeted BAUD rate (e.g. 9600).
|
* @param[in] parity Parity configuration (00=off, 10=even, 11=odd).
|
* @param[in] parity Parity configuration (00=off, 10=even, 11=odd), see #NEORV32_UART_PARITY_enum.
|
|
* @param[in] flow_con Hardware flow control configuration (00=off, 01=RTS, 10=CTS, 11=RTS/CTS), see #NEORV32_UART_FLOW_CONTROL_enum.
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_uart0_setup(uint32_t baudrate, uint8_t parity) {
|
void neorv32_uart0_setup(uint32_t baudrate, uint8_t parity, uint8_t flow_con) {
|
|
|
UART0_CT = 0; // reset
|
UART0_CT = 0; // reset
|
|
|
uint32_t clock = SYSINFO_CLK;
|
uint32_t clock = SYSINFO_CLK;
|
uint16_t i = 0; // BAUD rate divisor
|
uint16_t i = 0; // BAUD rate divisor
|
Line 277... |
Line 279... |
uart_en = uart_en << UART_CT_EN;
|
uart_en = uart_en << UART_CT_EN;
|
|
|
uint32_t parity_config = (uint32_t)(parity & 3);
|
uint32_t parity_config = (uint32_t)(parity & 3);
|
parity_config = parity_config << UART_CT_PMODE0;
|
parity_config = parity_config << UART_CT_PMODE0;
|
|
|
|
uint32_t flow_control = (uint32_t)(flow_con & 3);
|
|
flow_control = flow_control << UART_CT_RTS_EN;
|
|
|
/* Enable UART0 for SIM mode. */
|
/* Enable UART0 for SIM mode. */
|
/* USE THIS ONLY FOR SIMULATION! */
|
/* USE THIS ONLY FOR SIMULATION! */
|
#ifdef UART_SIM_MODE
|
#ifdef UART_SIM_MODE
|
#warning <UART_SIM_MODE> is obsolete (but still supported for compatibility). Please consider using the new flag <UART0_SIM_MODE>.
|
#warning <UART_SIM_MODE> is obsolete (but still supported for compatibility). Please consider using the new flag <UART0_SIM_MODE>.
|
#endif
|
#endif
|
Line 289... |
Line 294... |
uint32_t sim_mode = 1 << UART_CT_SIM_MODE;
|
uint32_t sim_mode = 1 << UART_CT_SIM_MODE;
|
#else
|
#else
|
uint32_t sim_mode = 0;
|
uint32_t sim_mode = 0;
|
#endif
|
#endif
|
|
|
UART0_CT = clk_prsc | baud_prsc | uart_en | parity_config | sim_mode;
|
UART0_CT = clk_prsc | baud_prsc | uart_en | parity_config | sim_mode | flow_control;
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Disable UART0.
|
* Disable UART0.
|
Line 364... |
Line 369... |
* @note This function is non-blocking and checks for frame and parity errors.
|
* @note This function is non-blocking and checks for frame and parity errors.
|
*
|
*
|
* @param[in,out] data Received char.
|
* @param[in,out] data Received char.
|
* @return Status code (0=nothing received, 1: char received without errors; -1: char received with frame error; -2: char received with parity error; -3 char received with frame & parity error).
|
* @return Status code (0=nothing received, 1: char received without errors; -1: char received with frame error; -2: char received with parity error; -3 char received with frame & parity error).
|
**************************************************************************/
|
**************************************************************************/
|
int neorv32_uart0_getc_secure(char *data) {
|
int neorv32_uart0_getc_safe(char *data) {
|
|
|
uint32_t uart_rx = UART0_DATA;
|
uint32_t uart_rx = UART0_DATA;
|
if (uart_rx & (1<<UART_DATA_AVAIL)) { // char available at all?
|
if (uart_rx & (1<<UART_DATA_AVAIL)) { // char available at all?
|
|
|
int status = 0;
|
int status = 0;
|
Line 585... |
Line 590... |
* @note To enable simulation mode add <USER_FLAGS+=-DUART1_SIM_MODE> when compiling.
|
* @note To enable simulation mode add <USER_FLAGS+=-DUART1_SIM_MODE> when compiling.
|
*
|
*
|
* @warning The baud rate is computed using INTEGER operations (truncation errors might occur).
|
* @warning The baud rate is computed using INTEGER operations (truncation errors might occur).
|
*
|
*
|
* @param[in] baudrate Targeted BAUD rate (e.g. 9600).
|
* @param[in] baudrate Targeted BAUD rate (e.g. 9600).
|
* @param[in] parity Parity configuration (00=off, 10=even, 11=odd).
|
* @param[in] parity Parity configuration (00=off, 10=even, 11=odd), see #NEORV32_UART_PARITY_enum.
|
|
* @param[in] flow_con Hardware flow control configuration (00=off, 01=RTS, 10=CTS, 11=RTS/CTS), see #NEORV32_UART_FLOW_CONTROL_enum.
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_uart1_setup(uint32_t baudrate, uint8_t parity) {
|
void neorv32_uart1_setup(uint32_t baudrate, uint8_t parity, uint8_t flow_con) {
|
|
|
UART1_CT = 0; // reset
|
UART1_CT = 0; // reset
|
|
|
uint32_t clock = SYSINFO_CLK;
|
uint32_t clock = SYSINFO_CLK;
|
uint16_t i = 0; // BAUD rate divisor
|
uint16_t i = 0; // BAUD rate divisor
|
Line 629... |
Line 635... |
uart_en = uart_en << UART_CT_EN;
|
uart_en = uart_en << UART_CT_EN;
|
|
|
uint32_t parity_config = (uint32_t)(parity & 3);
|
uint32_t parity_config = (uint32_t)(parity & 3);
|
parity_config = parity_config << UART_CT_PMODE0;
|
parity_config = parity_config << UART_CT_PMODE0;
|
|
|
|
uint32_t flow_control = (uint32_t)(flow_con & 3);
|
|
flow_control = flow_control << UART_CT_RTS_EN;
|
|
|
/* Enable UART1 for SIM mode. */
|
/* Enable UART1 for SIM mode. */
|
/* USE THIS ONLY FOR SIMULATION! */
|
/* USE THIS ONLY FOR SIMULATION! */
|
#ifdef UART1_SIM_MODE
|
#ifdef UART1_SIM_MODE
|
#warning UART1_SIM_MODE (secondary UART) enabled! Sending all UART1.TX data to text.io simulation output instead of real UART1 transmitter. Use this for simulations only!
|
#warning UART1_SIM_MODE (secondary UART) enabled! Sending all UART1.TX data to text.io simulation output instead of real UART1 transmitter. Use this for simulations only!
|
uint32_t sim_mode = 1 << UART_CT_SIM_MODE;
|
uint32_t sim_mode = 1 << UART_CT_SIM_MODE;
|
#else
|
#else
|
uint32_t sim_mode = 0;
|
uint32_t sim_mode = 0;
|
#endif
|
#endif
|
|
|
UART1_CT = clk_prsc | baud_prsc | uart_en | parity_config | sim_mode;
|
UART1_CT = clk_prsc | baud_prsc | uart_en | parity_config | sim_mode | flow_control;
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Disable UART1.
|
* Disable UART1.
|
Line 713... |
Line 722... |
* @note This function is non-blocking and checks for frame and parity errors.
|
* @note This function is non-blocking and checks for frame and parity errors.
|
*
|
*
|
* @param[in,out] data Received char.
|
* @param[in,out] data Received char.
|
* @return Status code (0=nothing received, 1: char received without errors; -1: char received with frame error; -2: char received with parity error; -3 char received with frame & parity error).
|
* @return Status code (0=nothing received, 1: char received without errors; -1: char received with frame error; -2: char received with parity error; -3 char received with frame & parity error).
|
**************************************************************************/
|
**************************************************************************/
|
int neorv32_uart1_getc_secure(char *data) {
|
int neorv32_uart1_getc_safe(char *data) {
|
|
|
uint32_t uart_rx = UART1_DATA;
|
uint32_t uart_rx = UART1_DATA;
|
if (uart_rx & (1<<UART_DATA_AVAIL)) { // char available at all?
|
if (uart_rx & (1<<UART_DATA_AVAIL)) { // char available at all?
|
|
|
int status = 0;
|
int status = 0;
|