URL
https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk
Subversion Repositories riscv_vhdl
[/] [riscv_vhdl/] [trunk/] [examples/] [dhrystone21/] [src/] [uart.cpp] - Rev 5
Compare with Previous | Blame | View Log
#include <stdio.h> #include <stdarg.h> #ifdef CONFIG_RISCV64 #include <axi_maps.h> #elif CONFIG_LEON3 #include "leon3_config.h" #endif static const int BUF_LENGTH = 2048; static char tmpUartStr[BUF_LENGTH]; //**************************************************************************** extern "C" void uart_init() { #ifdef CONFIG_RISCV64 //uart_map *uart = (uart_map *)ADDR_NASTI_SLAVE_UART1; // Inited in bootloader #elif CONFIG_LEON3 uart_fields *uart = (uart_fields *)ADR_APBUART_BASE; // scaler = 66MHz/(8*(1+rate)) = 115200 = 71 uart->scaler = 71; // 115200 baudrate // Init port for the transmition: uart->control = UART_CTRL_ENABLE_TX;//|UART_CTRL_TSEMPTY_IRQEN; #endif } extern "C" int uart_busy() { #ifdef CONFIG_RISCV64 uart_map *uart = (uart_map *)ADDR_NASTI_SLAVE_UART1; return uart->status & UART_STATUS_TX_FULL; #elif CONFIG_LEON3 uart_fields *uart = (uart_fields *)ADR_APBUART_BASE; return uart->status & UART_STATUS_TFULL; #endif } extern "C" void uart_send(unsigned v) { #ifdef CONFIG_RISCV64 uart_map *uart = (uart_map *)ADDR_NASTI_SLAVE_UART1; uart->data = v; #elif CONFIG_LEON3 uart_fields *uart = (uart_fields *)ADR_APBUART_BASE; uart->data = v; #endif } //**************************************************************************** extern "C" int printf_uart(const char *_format, ... ) { int ret = 0; va_list arg; va_start(arg, _format ); ret = vsprintf(tmpUartStr, _format, arg ); va_end( arg ); for (int i = 0; i < ret; i++) { while(uart_busy()) {} uart_send((unsigned int)tmpUartStr[i]); } return ret; }