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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [examples/] [boot/] [src/] [main.c] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
/******************************************************************************
2
 * @file
3
 * @copyright Copyright 2015 GNSS Sensor Ltd. All right reserved.
4
 * @author    Sergey Khabarov - sergeykhbr@gmail.com
5
 * @brief     Boot procedure of copying FW image into SRAM with the debug
6
 *            signals.
7
******************************************************************************/
8
 
9
#include <string.h>
10
#include "axi_maps.h"
11
#include "encoding.h"
12
 
13
static const int FW_IMAGE_SIZE_BYTES = 1 << 18;
14
 
15
void led_set(int output) {
16
    ((gpio_map *)ADDR_NASTI_SLAVE_GPIO)->led = output;
17
}
18
 
19
void print_uart(const char *buf, int sz) {
20
    uart_map *uart = (uart_map *)ADDR_NASTI_SLAVE_UART1;
21
    for (int i = 0; i < sz; i++) {
22
        while (uart->status & UART_STATUS_TX_FULL) {}
23
        uart->data = buf[i];
24
    }
25
}
26
 
27
void print_uart_hex(long val) {
28
    unsigned char t, s;
29
    uart_map *uart = (uart_map *)ADDR_NASTI_SLAVE_UART1;
30
    for (int i = 0; i < 16; i++) {
31
        while (uart->status & UART_STATUS_TX_FULL) {}
32
 
33
        t = (unsigned char)((val >> ((15 - i) * 4)) & 0xf);
34
        if (t < 10) {
35
            s = t + '0';
36
        } else {
37
            s = (t - 10) + 'a';
38
        }
39
        uart->data = s;
40
    }
41
}
42
 
43
void copy_image() {
44
    uint32_t tech;
45
    uint64_t *fwrom = (uint64_t *)ADDR_NASTI_SLAVE_FWIMAGE;
46
    uint64_t *sram = (uint64_t *)ADDR_NASTI_SLAVE_SRAM;
47
    pnp_map *pnp = (pnp_map *)ADDR_NASTI_SLAVE_PNP;
48
 
49
    /**
50
     * Speed-up RTL simulation by skipping coping stage.
51
     * Or skip this stage to avoid rewritting of externally loaded image.
52
     */
53
    tech = pnp->tech & 0xFF;
54
 
55
    if (tech != TECH_INFERRED && pnp->fwid == 0) {
56
        memcpy(sram, fwrom, FW_IMAGE_SIZE_BYTES);
57
    }
58
    // Write Firmware ID to avoid copy image after soft-reset.
59
    pnp->fwid = 0x20180725;
60
 
61
#if 0
62
    /** Just to check access to DSU and read MCPUID via this slave device.
63
     *  Verification is made on time diagram (ModelSim), no other purposes of
64
     *  these operations.
65
     *        DSU base address = 0x80080000:
66
     *        CSR address: Addr[15:4] = 16 bytes alignment
67
     *  3296 ns - reading (iClkCnt = 409)
68
     *  3435 ns - writing (iClkCnt = 427)
69
     */
70
    uint64_t *arr_csrs = (uint64_t *)0x80080000;
71
    uint64_t x1 = arr_csrs[CSR_MCPUID<<1];
72
    pnp->fwdbg1 = x1;
73
    arr_csrs[CSR_MCPUID<<1] = x1;
74
#endif
75
}
76
 
77
void _init() {
78
    uint32_t tech;
79
    pnp_map *pnp = (pnp_map *)ADDR_NASTI_SLAVE_PNP;
80
    uart_map *uart = (uart_map *)ADDR_NASTI_SLAVE_UART1;
81
    gpio_map *gpio = (gpio_map *)ADDR_NASTI_SLAVE_GPIO;
82
    irqctrl_map *p_irq = (irqctrl_map *)ADDR_NASTI_SLAVE_IRQCTRL;
83
 
84
    // mask all interrupts in interrupt controller to avoid
85
    // unpredictable behaviour after elf-file reloading via debug port.
86
    p_irq->irq_mask = 0xFFFFFFFF;
87
 
88
    // Half period of the uart = Fbus / 115200 / 2 = 70 MHz / 115200 / 2:
89
    //uart->scaler = 304;  // 70 MHz
90
    //uart->scaler = 260;  // 60 MHz
91
    uart->scaler = 40000000 / 115200 / 2;  // 40 MHz
92
 
93
    led_set(0x01);
94
    print_uart("Boot . . .", 10);
95
    led_set(0x02);
96
 
97
    copy_image();
98
    led_set(0x03);
99
    print_uart("OK\r\n", 4);
100
 
101
    /** Check ADC detector that RF front-end is connected: */
102
    tech = (pnp->tech >> 24) & 0xff;
103
    if (tech != 0xFF) {
104
        print_uart("ADC clock not found. Enable DIP int_rf.\r\n", 41);
105
        tech = (pnp->tech >> 24) & 0xff;
106
        led_set(tech);
107
    }
108
    led_set(0x04);
109
}
110
 
111
/** Not used actually */
112
int main() {
113
    while (1) {}
114
 
115
    return 0;
116
}

powered by: WebSVN 2.1.0

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