OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [examples/] [dhrystone21/] [src/] [uart.cpp] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
#include <stdio.h>
2
#include <stdarg.h>
3
#ifdef CONFIG_RISCV64
4
#include <axi_maps.h>
5
#elif CONFIG_LEON3
6
#include "leon3_config.h"
7
#endif
8
 
9
static const int BUF_LENGTH = 2048;
10
static char tmpUartStr[BUF_LENGTH];
11
 
12
//****************************************************************************
13
extern "C" void uart_init() {
14
#ifdef CONFIG_RISCV64
15
    //uart_map *uart = (uart_map *)ADDR_NASTI_SLAVE_UART1;
16
    // Inited in bootloader
17
#elif CONFIG_LEON3
18
    uart_fields *uart = (uart_fields *)ADR_APBUART_BASE;
19
    // scaler = 66MHz/(8*(1+rate)) = 115200 = 71
20
    uart->scaler = 71;       // 115200 baudrate
21
    // Init port for the transmition:
22
    uart->control = UART_CTRL_ENABLE_TX;//|UART_CTRL_TSEMPTY_IRQEN;
23
#endif
24
}
25
 
26
extern "C" int uart_busy() {
27
#ifdef CONFIG_RISCV64
28
    uart_map *uart = (uart_map *)ADDR_NASTI_SLAVE_UART1;
29
    return uart->status & UART_STATUS_TX_FULL;
30
 
31
#elif CONFIG_LEON3
32
    uart_fields *uart = (uart_fields *)ADR_APBUART_BASE;
33
    return uart->status & UART_STATUS_TFULL;
34
#endif
35
}
36
 
37
extern "C" void uart_send(unsigned v) {
38
#ifdef CONFIG_RISCV64
39
    uart_map *uart = (uart_map *)ADDR_NASTI_SLAVE_UART1;
40
    uart->data = v;
41
#elif CONFIG_LEON3
42
    uart_fields *uart = (uart_fields *)ADR_APBUART_BASE;
43
    uart->data = v;
44
#endif
45
}
46
 
47
//****************************************************************************
48
extern "C" int printf_uart(const char *_format, ... ) {
49
    int ret = 0;
50
 
51
    va_list arg;
52
    va_start(arg, _format );
53
 
54
    ret = vsprintf(tmpUartStr, _format, arg );
55
    va_end( arg );
56
 
57
    for (int i = 0; i < ret; i++) {
58
        while(uart_busy()) {}
59
        uart_send((unsigned int)tmpUartStr[i]);
60
    }
61
    return ret;
62
}
63
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.