Line 76... |
Line 76... |
*
|
*
|
* @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).
|
* @param[in] rx_irq Enable RX interrupt (data received) when 1.
|
|
* @param[in] tx_irq Enable TX interrupt (transmission done) when 1.
|
|
**************************************************************************/
|
**************************************************************************/
|
void neorv32_uart_setup(uint32_t baudrate, uint8_t parity, uint8_t rx_irq, uint8_t tx_irq) {
|
void neorv32_uart_setup(uint32_t baudrate, uint8_t parity) {
|
|
|
UART_CT = 0; // reset
|
UART_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 121... |
Line 119... |
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 rx_irq_en = (uint32_t)(rx_irq & 1);
|
|
rx_irq_en = rx_irq_en << UART_CT_RX_IRQ;
|
|
|
|
uint32_t tx_irq_en = (uint32_t)(tx_irq & 1);
|
|
tx_irq_en = tx_irq_en << UART_CT_TX_IRQ;
|
|
|
|
/* Enable the UART for SIM mode. */
|
/* Enable the UART 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 enabled! Sending all UART.TX data to text.io simulation output instead of real UART transmitter. Use this for simulations only!
|
#warning UART_SIM_MODE enabled! Sending all UART.TX data to text.io simulation output instead of real UART 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
|
|
|
UART_CT = clk_prsc | baud_prsc | uart_en | parity_config | rx_irq_en | tx_irq_en | sim_mode;
|
UART_CT = clk_prsc | baud_prsc | uart_en | parity_config | sim_mode;
|
}
|
}
|
|
|
|
|
/**********************************************************************//**
|
/**********************************************************************//**
|
* Disable UART.
|
* Disable UART.
|