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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [lib/] [source/] [neorv32_rte.c] - Blame information for rev 14

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 zero_gravi
// #################################################################################################
2
// # << NEORV32: neorv32_rte.c - NEORV32 Runtime Environment >>                                    #
3
// # ********************************************************************************************* #
4
// # BSD 3-Clause License                                                                          #
5
// #                                                                                               #
6
// # Copyright (c) 2020, Stephan Nolting. All rights reserved.                                     #
7
// #                                                                                               #
8
// # Redistribution and use in source and binary forms, with or without modification, are          #
9
// # permitted provided that the following conditions are met:                                     #
10
// #                                                                                               #
11
// # 1. Redistributions of source code must retain the above copyright notice, this list of        #
12
// #    conditions and the following disclaimer.                                                   #
13
// #                                                                                               #
14
// # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
15
// #    conditions and the following disclaimer in the documentation and/or other materials        #
16
// #    provided with the distribution.                                                            #
17
// #                                                                                               #
18
// # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
19
// #    endorse or promote products derived from this software without specific prior written      #
20
// #    permission.                                                                                #
21
// #                                                                                               #
22
// # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
23
// # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
24
// # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
25
// # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
26
// # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
27
// # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
28
// # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
29
// # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
30
// # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
31
// # ********************************************************************************************* #
32
// # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
33
// #################################################################################################
34
 
35
 
36
/**********************************************************************//**
37
 * @file neorv32_rte.c
38
 * @author Stephan Nolting
39
 * @brief NEORV32 Runtime Environment.
40
 **************************************************************************/
41
 
42
#include "neorv32.h"
43
#include "neorv32_rte.h"
44
 
45 14 zero_gravi
/**********************************************************************//**
46
 * The >private< trap vector look-up table of the NEORV32 RTE.
47
 **************************************************************************/
48
static uint32_t __neorv32_rte_vector_lut[16] __attribute__((unused)); // trap handler vector table
49
 
50
// private functions
51
static void __attribute__((__interrupt__)) __neorv32_rte_core(void) __attribute__((aligned(16))) __attribute__((unused));
52 6 zero_gravi
static void __neorv32_rte_debug_exc_handler(void)     __attribute__((unused));
53
static void __neorv32_rte_print_true_false(int state) __attribute__((unused));
54 2 zero_gravi
 
55
 
56
/**********************************************************************//**
57 14 zero_gravi
 * Setup NEORV32 runtime environment.
58 2 zero_gravi
 *
59
 * @note This function installs a debug handler for ALL exception and interrupt sources, which
60 14 zero_gravi
 * gives detailed information about the exception/interrupt. Actual handler can be installed afterwards
61
 * via neorv32_rte_exception_install(uint8_t id, void (*handler)(void)).
62 2 zero_gravi
 **************************************************************************/
63 14 zero_gravi
void neorv32_rte_setup(void) {
64 2 zero_gravi
 
65 14 zero_gravi
  // configure trap handler base address
66
  uint32_t mtvec_base = (uint32_t)(&__neorv32_rte_core);
67
  neorv32_cpu_csr_write(CSR_MTVEC, mtvec_base);
68 2 zero_gravi
 
69
  // install debug handler for all sources
70 14 zero_gravi
  uint8_t id;
71
  for (id = 0; id < (sizeof(__neorv32_rte_vector_lut)/sizeof(__neorv32_rte_vector_lut[0])); id++) {
72
    neorv32_rte_exception_uninstall(id); // this will configure the debug handler
73 2 zero_gravi
  }
74
}
75
 
76
 
77
/**********************************************************************//**
78
 * Install exception handler function to NEORV32 runtime environment.
79
 *
80
 * @note This function automatically activates the according CSR.mie bits when installing handlers for
81 14 zero_gravi
 * the MTIME (MTI), CLIC (MEI), machine software interrupt (MSI) or a fast IRQ. The global interrupt enable bit mstatus.mie has
82 2 zero_gravi
 * to be set by the user via neorv32_cpu_eint(void).
83
 *
84 14 zero_gravi
 * @param[in] id Identifier (type) of the targeted exception. See #NEORV32_RTE_TRAP_enum.
85
 * @param[in] handler The actual handler function for the specified exception (function MUST be of type "void function(void);").
86
 * return 0 if success, 1 if error (invalid id or targeted exception not supported).
87 2 zero_gravi
 **************************************************************************/
88 14 zero_gravi
int neorv32_rte_exception_install(uint8_t id, void (*handler)(void)) {
89 2 zero_gravi
 
90
  // id valid?
91 14 zero_gravi
  if ((id == RTE_TRAP_I_MISALIGNED) || (id == RTE_TRAP_I_ACCESS)     || (id == RTE_TRAP_I_ILLEGAL) ||
92
      (id == RTE_TRAP_BREAKPOINT)   || (id == RTE_TRAP_L_MISALIGNED) || (id == RTE_TRAP_L_ACCESS)  ||
93
      (id == RTE_TRAP_S_MISALIGNED) || (id == RTE_TRAP_S_ACCESS)     || (id == RTE_TRAP_MENV_CALL) ||
94
      (id == RTE_TRAP_MSI)          || (id == RTE_TRAP_MTI)          || (id == RTE_TRAP_MEI)       ||
95
      (id == RTE_TRAP_FIRQ_0)       || (id == RTE_TRAP_FIRQ_1)       || (id == RTE_TRAP_FIRQ_2)    || (id == RTE_TRAP_FIRQ_3)) {
96 2 zero_gravi
 
97
 
98 14 zero_gravi
    if (id == RTE_TRAP_MSI)    { neorv32_cpu_irq_enable(CPU_MIE_MSIE); } // activate software interrupt
99
    if (id == RTE_TRAP_MTI)    { neorv32_cpu_irq_enable(CPU_MIE_MTIE); } // activate timer interrupt
100
    if (id == RTE_TRAP_MEI)    { neorv32_cpu_irq_enable(CPU_MIE_MEIE); } // activate external interrupt
101
    if (id == RTE_TRAP_FIRQ_0) { neorv32_cpu_irq_enable(CPU_MIE_FIRQ0E); } // activate fast interrupt channel 0
102
    if (id == RTE_TRAP_FIRQ_1) { neorv32_cpu_irq_enable(CPU_MIE_FIRQ1E); } // activate fast interrupt channel 1
103
    if (id == RTE_TRAP_FIRQ_2) { neorv32_cpu_irq_enable(CPU_MIE_FIRQ2E); } // activate fast interrupt channel 2
104
    if (id == RTE_TRAP_FIRQ_3) { neorv32_cpu_irq_enable(CPU_MIE_FIRQ3E); } // activate fast interrupt channel 3
105 2 zero_gravi
 
106 14 zero_gravi
    __neorv32_rte_vector_lut[id]  = (uint32_t)handler; // install handler
107
 
108 2 zero_gravi
    return 0;
109
  }
110
  return 1;
111
}
112
 
113
 
114
/**********************************************************************//**
115
 * Uninstall exception handler function from NEORV32 runtime environment, which was
116 14 zero_gravi
 * previously installed via neorv32_rte_exception_install(uint8_t id, void (*handler)(void)).
117 2 zero_gravi
 *
118
 * @note This function automatically clears the according CSR.mie bits when uninstalling handlers for
119 14 zero_gravi
 * the MTIME (MTI), CLIC (MEI), machine software interrupt (MSI) or fast IRQs. The global interrupt enable bit mstatus.mie has
120 2 zero_gravi
 * to be cleared by the user via neorv32_cpu_dint(void).
121
 *
122 14 zero_gravi
 * @param[in] id Identifier (type) of the targeted exception. See #NEORV32_RTE_TRAP_enum.
123
 * return 0 if success, 1 if error (invalid id or targeted exception not supported).
124 2 zero_gravi
 **************************************************************************/
125 14 zero_gravi
int neorv32_rte_exception_uninstall(uint8_t id) {
126 2 zero_gravi
 
127
  // id valid?
128 14 zero_gravi
  if ((id == RTE_TRAP_I_MISALIGNED) || (id == RTE_TRAP_I_ACCESS)     || (id == RTE_TRAP_I_ILLEGAL) ||
129
      (id == RTE_TRAP_BREAKPOINT)   || (id == RTE_TRAP_L_MISALIGNED) || (id == RTE_TRAP_L_ACCESS)  ||
130
      (id == RTE_TRAP_S_MISALIGNED) || (id == RTE_TRAP_S_ACCESS)     || (id == RTE_TRAP_MENV_CALL) ||
131
      (id == RTE_TRAP_MSI)          || (id == RTE_TRAP_MTI)          || (id == RTE_TRAP_MEI)       ||
132
      (id == RTE_TRAP_FIRQ_0)       || (id == RTE_TRAP_FIRQ_1)       || (id == RTE_TRAP_FIRQ_2)    || (id == RTE_TRAP_FIRQ_3)) {
133 2 zero_gravi
 
134 14 zero_gravi
    if (id == RTE_TRAP_MSI)    { neorv32_cpu_irq_disable(CPU_MIE_MSIE); } // deactivate software interrupt
135
    if (id == RTE_TRAP_MTI)    { neorv32_cpu_irq_disable(CPU_MIE_MTIE); } // deactivate timer interrupt
136
    if (id == RTE_TRAP_MEI)    { neorv32_cpu_irq_disable(CPU_MIE_MEIE); } // deactivate external interrupt
137
    if (id == RTE_TRAP_FIRQ_0) { neorv32_cpu_irq_disable(CPU_MIE_FIRQ0E); } // deactivate fast interrupt channel 0
138
    if (id == RTE_TRAP_FIRQ_1) { neorv32_cpu_irq_disable(CPU_MIE_FIRQ1E); } // deactivate fast interrupt channel 1
139
    if (id == RTE_TRAP_FIRQ_2) { neorv32_cpu_irq_disable(CPU_MIE_FIRQ2E); } // deactivate fast interrupt channel 2
140
    if (id == RTE_TRAP_FIRQ_3) { neorv32_cpu_irq_disable(CPU_MIE_FIRQ3E); } // deactivate fast interrupt channel 3
141 2 zero_gravi
 
142 14 zero_gravi
    __neorv32_rte_vector_lut[id] = (uint32_t)(&__neorv32_rte_debug_exc_handler); // use dummy handler in case the exception is accidently triggered
143 2 zero_gravi
 
144
    return 0;
145
  }
146
  return 1;
147
}
148
 
149
 
150
/**********************************************************************//**
151 14 zero_gravi
 * This is the core of the NEORV32 RTE.
152
 *
153
 * @note This function must no be explicitly used by the user.
154
 * @warning When using the the RTE, this function is the ONLY function that can use the 'interrupt' attribute!
155 2 zero_gravi
 **************************************************************************/
156 14 zero_gravi
static void __attribute__((__interrupt__)) __attribute__((aligned(16)))  __neorv32_rte_core(void) {
157 2 zero_gravi
 
158 14 zero_gravi
  register uint32_t rte_mepc   = neorv32_cpu_csr_read(CSR_MEPC);
159
  register uint32_t rte_mcause = neorv32_cpu_csr_read(CSR_MCAUSE);
160
 
161
  // compute return address
162
  if ((rte_mcause & 0x80000000) == 0) { // modify pc only if exception
163
 
164
    // get low half word of faulting instruction
165
    register uint32_t rte_trap_inst;
166
    asm volatile ("lh %[result], 0(%[input_i])" : [result] "=r" (rte_trap_inst) : [input_i] "r" (rte_mepc));
167
 
168
    if ((rte_trap_inst & 3) == 3) { // faulting instruction is uncompressed instruction
169
      rte_mepc += 4;
170
    }
171
    else { // faulting instruction is compressed instruction
172
      rte_mepc += 2;
173
    }
174
 
175
    // store new return address
176
    neorv32_cpu_csr_write(CSR_MEPC, rte_mepc);
177
  }
178
 
179
  // find according trap handler
180
  register uint32_t rte_handler = (uint32_t)(&__neorv32_rte_debug_exc_handler);
181
  switch (rte_mcause) {
182
    case TRAP_CODE_I_MISALIGNED: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_I_MISALIGNED]; break;
183
    case TRAP_CODE_I_ACCESS:     rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_I_ACCESS]; break;
184
    case TRAP_CODE_I_ILLEGAL:    rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_I_ILLEGAL]; break;
185
    case TRAP_CODE_BREAKPOINT:   rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_BREAKPOINT]; break;
186
    case TRAP_CODE_L_MISALIGNED: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_L_MISALIGNED]; break;
187
    case TRAP_CODE_L_ACCESS:     rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_L_ACCESS]; break;
188
    case TRAP_CODE_S_MISALIGNED: rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_S_MISALIGNED]; break;
189
    case TRAP_CODE_S_ACCESS:     rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_S_ACCESS]; break;
190
    case TRAP_CODE_MENV_CALL:    rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_MENV_CALL]; break;
191
    case TRAP_CODE_MSI:          rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_MSI]; break;
192
    case TRAP_CODE_MTI:          rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_MTI]; break;
193
    case TRAP_CODE_MEI:          rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_MEI]; break;
194
    case TRAP_CODE_FIRQ_0:       rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_0]; break;
195
    case TRAP_CODE_FIRQ_1:       rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_1]; break;
196
    case TRAP_CODE_FIRQ_2:       rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_2]; break;
197
    case TRAP_CODE_FIRQ_3:       rte_handler = __neorv32_rte_vector_lut[RTE_TRAP_FIRQ_3]; break;
198
    default: break;
199
  }
200
 
201
  // execute handler
202
  void (*handler_pnt)(void);
203
  handler_pnt = (void*)rte_handler;
204
  (*handler_pnt)();
205 2 zero_gravi
}
206
 
207
 
208
/**********************************************************************//**
209
 * NEORV32 runtime environment: Debug exception handler, printing various exception/interrupt information via UART.
210 14 zero_gravi
 * @note This function is used by neorv32_rte_exception_uninstall(void) only.
211 2 zero_gravi
 **************************************************************************/
212
static void __neorv32_rte_debug_exc_handler(void) {
213
 
214 6 zero_gravi
  neorv32_uart_printf("\n\n<< NEORV32 Runtime Environment >>\n");
215 2 zero_gravi
 
216
  neorv32_uart_printf("System time: 0x%x_%x\n", neorv32_cpu_csr_read(CSR_TIMEH), neorv32_cpu_csr_read(CSR_TIME));
217
 
218 7 zero_gravi
  register uint32_t trap_cause = neorv32_cpu_csr_read(CSR_MCAUSE);
219
  register uint32_t trap_addr  = neorv32_cpu_csr_read(CSR_MEPC);
220
  register uint32_t trap_inst;
221 2 zero_gravi
 
222 7 zero_gravi
  asm volatile ("lh %[result], 0(%[input_i])" : [result] "=r" (trap_inst) : [input_i] "r" (trap_addr));
223
 
224 12 zero_gravi
 
225 7 zero_gravi
  if (trap_cause & 0x80000000) {
226 2 zero_gravi
    neorv32_uart_printf("INTERRUPT");
227
  }
228
  else {
229
    neorv32_uart_printf("EXCEPTION");
230 7 zero_gravi
    if ((trap_inst & 3) == 3) {
231
      trap_addr -= 4;
232 6 zero_gravi
    }
233
    else {
234 7 zero_gravi
      trap_addr -= 2;
235 6 zero_gravi
    }
236 2 zero_gravi
  }
237 7 zero_gravi
  neorv32_uart_printf(" at instruction address: 0x%x\n", trap_addr);
238 2 zero_gravi
 
239
  neorv32_uart_printf("Cause: ");
240 7 zero_gravi
  switch (trap_cause) {
241 14 zero_gravi
    case TRAP_CODE_I_MISALIGNED: neorv32_uart_printf("Instruction address misaligned"); break;
242
    case TRAP_CODE_I_ACCESS:     neorv32_uart_printf("Instruction access fault"); break;
243
    case TRAP_CODE_I_ILLEGAL:    neorv32_uart_printf("Illegal instruction"); break;
244
    case TRAP_CODE_BREAKPOINT:   neorv32_uart_printf("Breakpoint (EBREAK)"); break;
245
    case TRAP_CODE_L_MISALIGNED: neorv32_uart_printf("Load address misaligned"); break;
246
    case TRAP_CODE_L_ACCESS:     neorv32_uart_printf("Load access fault"); break;
247
    case TRAP_CODE_S_MISALIGNED: neorv32_uart_printf("Store address misaligned"); break;
248
    case TRAP_CODE_S_ACCESS:     neorv32_uart_printf("Store access fault"); break;
249
    case TRAP_CODE_MENV_CALL:    neorv32_uart_printf("Environment call from M-mode"); break;
250
    case TRAP_CODE_MSI:          neorv32_uart_printf("Machine software interrupt"); break;
251
    case TRAP_CODE_MTI:          neorv32_uart_printf("Machine timer interrupt"); break;
252
    case TRAP_CODE_MEI:          neorv32_uart_printf("Machine external interrupt"); break;
253
    case TRAP_CODE_FIRQ_0:       neorv32_uart_printf("Fast interrupt channel 0"); break;
254
    case TRAP_CODE_FIRQ_1:       neorv32_uart_printf("Fast interrupt channel 1"); break;
255
    case TRAP_CODE_FIRQ_2:       neorv32_uart_printf("Fast interrupt channel 2"); break;
256
    case TRAP_CODE_FIRQ_3:       neorv32_uart_printf("Fast interrupt channel 3"); break;
257
    default:                     neorv32_uart_printf("Unknown (0x%x)", trap_cause); break;
258 2 zero_gravi
  }
259
 
260
  // fault address
261 14 zero_gravi
  neorv32_uart_printf("\nFaulting instruction (low half word): 0x%x", trap_inst);
262 2 zero_gravi
 
263 7 zero_gravi
  if ((trap_inst & 3) != 3) {
264 14 zero_gravi
    neorv32_uart_printf(" (decompressed)\n");
265 2 zero_gravi
  }
266 6 zero_gravi
 
267 14 zero_gravi
  neorv32_uart_printf("\nMTVAL: 0x%x\n", neorv32_cpu_csr_read(CSR_MTVAL));
268
 
269 6 zero_gravi
  neorv32_uart_printf("Trying to resume application @ 0x%x...", neorv32_cpu_csr_read(CSR_MEPC));
270
 
271
  neorv32_uart_printf("\n<</NEORV32 Runtime Environment >>\n\n");
272
}
273
 
274
 
275
/**********************************************************************//**
276
 * NEORV32 runtime environment: Print hardware configuration information via UART
277
 **************************************************************************/
278
void neorv32_rte_print_hw_config(void) {
279
 
280
  uint32_t tmp;
281
  int i;
282
  char c;
283
 
284
  neorv32_uart_printf("\n\n<< NEORV32 Hardware Configuration Overview >>\n");
285
 
286
  // CPU configuration
287
  neorv32_uart_printf("\n-- Central Processing Unit --\n");
288
 
289
  // Hart ID
290 12 zero_gravi
  neorv32_uart_printf("Hart ID:          %u\n", neorv32_cpu_csr_read(CSR_MHARTID));
291 6 zero_gravi
 
292 12 zero_gravi
  // Custom user code
293
  neorv32_uart_printf("User code:        0x%x\n", SYSINFO_USER_CODE);
294
 
295 6 zero_gravi
  // HW version
296
  neorv32_uart_printf("Hardware version: ");
297 12 zero_gravi
  neorv32_rte_print_hw_version();
298 6 zero_gravi
  neorv32_uart_printf(" (0x%x)\n", neorv32_cpu_csr_read(CSR_MIMPID));
299
 
300
  // CPU architecture
301
  neorv32_uart_printf("Architecture:     ");
302
  tmp = neorv32_cpu_csr_read(CSR_MISA);
303
  tmp = (tmp >> 30) & 0x03;
304
  if (tmp == 0) {
305
    neorv32_uart_printf("unknown");
306
  }
307
  if (tmp == 1) {
308
    neorv32_uart_printf("RV32");
309
  }
310
  if (tmp == 2) {
311
    neorv32_uart_printf("RV64");
312
  }
313
  if (tmp == 3) {
314
    neorv32_uart_printf("RV128");
315
  }
316
 
317
  // CPU extensions
318
  neorv32_uart_printf("\nCPU extensions:   ");
319
  tmp = neorv32_cpu_csr_read(CSR_MISA);
320
  for (i=0; i<26; i++) {
321
    if (tmp & (1 << i)) {
322
      c = (char)('A' + i);
323
      neorv32_uart_putc(c);
324
      neorv32_uart_putc(' ');
325
    }
326
  }
327
  neorv32_uart_printf("(0x%x)\n", tmp);
328
 
329
  // Clock speed
330 12 zero_gravi
  neorv32_uart_printf("Clock speed:      %u Hz\n", SYSINFO_CLK);
331 6 zero_gravi
 
332
  // Memory configuration
333
  neorv32_uart_printf("\n-- Memory Configuration --\n");
334
 
335 12 zero_gravi
  uint32_t size = SYSINFO_ISPACE_SIZE;
336
  uint32_t base = SYSINFO_ISPACE_BASE;
337 6 zero_gravi
  neorv32_uart_printf("Instruction memory:   %u bytes @ 0x%x\n", size, base);
338
  neorv32_uart_printf("Internal IMEM:        ");
339 12 zero_gravi
  __neorv32_rte_print_true_false(SYSINFO_FEATURES & (1 << SYSINFO_FEATURES_MEM_INT_IMEM));
340 6 zero_gravi
  neorv32_uart_printf("Internal IMEM as ROM: ");
341 12 zero_gravi
  __neorv32_rte_print_true_false(SYSINFO_FEATURES & (1 << SYSINFO_FEATURES_MEM_INT_IMEM_ROM));
342 6 zero_gravi
 
343 12 zero_gravi
  size = SYSINFO_DSPACE_SIZE;
344
  base = SYSINFO_DSPACE_BASE;
345 6 zero_gravi
  neorv32_uart_printf("Data memory:          %u bytes @ 0x%x\n", size, base);
346
  neorv32_uart_printf("Internal DMEM:        ");
347 12 zero_gravi
  __neorv32_rte_print_true_false(SYSINFO_FEATURES & (1 << SYSINFO_FEATURES_MEM_INT_DMEM));
348 6 zero_gravi
 
349
  neorv32_uart_printf("Bootloader:           ");
350 12 zero_gravi
  __neorv32_rte_print_true_false(SYSINFO_FEATURES & (1 << SYSINFO_FEATURES_BOOTLOADER));
351 6 zero_gravi
 
352
  neorv32_uart_printf("External interface:   ");
353 12 zero_gravi
  __neorv32_rte_print_true_false(SYSINFO_FEATURES & (1 << SYSINFO_FEATURES_MEM_EXT));
354 6 zero_gravi
 
355
  // peripherals
356
  neorv32_uart_printf("\n-- Peripherals --\n");
357 12 zero_gravi
  tmp = SYSINFO_FEATURES;
358 6 zero_gravi
 
359
  neorv32_uart_printf("GPIO:    ");
360 12 zero_gravi
  __neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_GPIO));
361 6 zero_gravi
 
362
  neorv32_uart_printf("MTIME:   ");
363 12 zero_gravi
  __neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_MTIME));
364 6 zero_gravi
 
365
  neorv32_uart_printf("UART:    ");
366 12 zero_gravi
  __neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_UART));
367 6 zero_gravi
 
368
  neorv32_uart_printf("SPI:     ");
369 12 zero_gravi
  __neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_SPI));
370 6 zero_gravi
 
371
  neorv32_uart_printf("TWI:     ");
372 12 zero_gravi
  __neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_TWI));
373 6 zero_gravi
 
374
  neorv32_uart_printf("PWM:     ");
375 12 zero_gravi
  __neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_PWM));
376 6 zero_gravi
 
377
  neorv32_uart_printf("WDT:     ");
378 12 zero_gravi
  __neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_WDT));
379 6 zero_gravi
 
380
  neorv32_uart_printf("TRNG:    ");
381 12 zero_gravi
  __neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_TRNG));
382 6 zero_gravi
 
383
  neorv32_uart_printf("DEVNULL: ");
384 12 zero_gravi
  __neorv32_rte_print_true_false(tmp & (1 << SYSINFO_FEATURES_IO_DEVNULL));
385 6 zero_gravi
}
386
 
387
 
388
/**********************************************************************//**
389
 * NEORV32 runtime environment: Private function to print true or false.
390
 * @note This function is used by neorv32_rte_print_hw_config(void) only.
391
 *
392
 * @param[in] state Print TRUE when !=0, print FALSE when 0
393
 **************************************************************************/
394
static void __neorv32_rte_print_true_false(int state) {
395
 
396
  if (state) {
397
    neorv32_uart_printf("True\n");
398
  }
399 2 zero_gravi
  else {
400 6 zero_gravi
    neorv32_uart_printf("False\n");
401 2 zero_gravi
  }
402 6 zero_gravi
}
403 2 zero_gravi
 
404
 
405 6 zero_gravi
/**********************************************************************//**
406 12 zero_gravi
 * NEORV32 runtime environment: Function to show the processor version in human-readable format.
407 6 zero_gravi
 **************************************************************************/
408 12 zero_gravi
void neorv32_rte_print_hw_version(void) {
409 6 zero_gravi
 
410
  uint32_t i;
411
  char tmp, cnt;
412
  uint32_t version = neorv32_cpu_csr_read(CSR_MIMPID);
413
 
414
  for (i=0; i<4; i++) {
415
 
416
    tmp = (char)(version >> (24 - 8*i));
417
 
418
    // serial division
419
    cnt = 0;
420
    while (tmp >= 10) {
421
      tmp = tmp - 10;
422
      cnt++;
423
    }
424
 
425
    if (cnt) {
426
      neorv32_uart_putc('0' + cnt);
427
    }
428
    neorv32_uart_putc('0' + tmp);
429
    if (i < 3) {
430
      neorv32_uart_putc('.');
431
    }
432
  }
433 2 zero_gravi
}
434 11 zero_gravi
 
435
 
436
/**********************************************************************//**
437
 * NEORV32 runtime environment: Print project credits
438
 **************************************************************************/
439
void neorv32_rte_print_credits(void) {
440
 
441
  neorv32_uart_print("\n\nThe NEORV32 Processor Project\n"
442
                     "by Stephan Nolting\n"
443
                     "https://github.com/stnolting/neorv32\n"
444
                     "made in Hannover, Germany\n\n");
445
}
446
 

powered by: WebSVN 2.1.0

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