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

Subversion Repositories riscv_vhdl

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

powered by: WebSVN 2.1.0

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