|
1 | 1 | // Copyright (c) 2024 ETH Zurich and University of Bologna. |
2 | 2 | // Licensed under the Apache License, Version 2.0, see LICENSE for details. |
3 | | -// SPDX-License-Identifier: Apache-2.0/ |
| 3 | +// SPDX-License-Identifier: Apache-2.0 |
4 | 4 | // |
5 | 5 | // Authors: |
6 | 6 | // - Philippe Sauter <phsauter@iis.ee.ethz.ch> |
7 | 7 |
|
8 | 8 | #include "uart.h" |
9 | 9 | #include "print.h" |
10 | | -#include "gpio.h" |
11 | | -#include "clint.h" |
12 | | -#include "util.h" |
13 | | - |
14 | | -/// @brief Example integer square root |
15 | | -/// @return integer square root of n |
16 | | -uint32_t isqrt(uint32_t n) { |
17 | | - uint32_t res = 0; |
18 | | - uint32_t bit = (uint32_t)1 << 30; |
19 | | - |
20 | | - while (bit > n) bit >>= 2; |
21 | | - |
22 | | - while (bit) { |
23 | | - if (n >= res + bit) { |
24 | | - n -= res + bit; |
25 | | - res = (res >> 1) + bit; |
26 | | - } else { |
27 | | - res >>= 1; |
28 | | - } |
29 | | - bit >>= 2; |
30 | | - } |
31 | | - return res; |
32 | | -} |
33 | | - |
34 | | -char receive_buff[16] = {0}; |
| 10 | +#include "config.h" |
35 | 11 |
|
36 | 12 | int main() { |
37 | | - uart_init(); // setup the uart peripheral |
38 | | - |
39 | | - // simple printf support (only prints text and hex numbers) |
40 | | - printf("Hello World!\n"); |
41 | | - // wait until uart has finished sending |
42 | | - uart_write_flush(); |
43 | | - |
44 | | - // uart loopback |
45 | | - uart_loopback_enable(); |
46 | | - printf("internal msg\n"); |
47 | | - clint_sleep_ms(1); |
48 | | - for (uint8_t idx = 0; idx < 15; idx++) { |
49 | | - receive_buff[idx] = uart_read(); |
50 | | - if (receive_buff[idx] == '\n') { |
51 | | - break; |
52 | | - } |
53 | | - } |
54 | | - uart_loopback_disable(); |
55 | | - |
56 | | - printf("Loopback received: "); |
57 | | - printf(receive_buff); |
58 | | - uart_write_flush(); |
59 | | - |
60 | | - // toggling some GPIOs |
61 | | - gpio_set_direction(0xFFFF, 0x000F); // lowest four as outputs |
62 | | - gpio_write(0x0A); // ready output pattern |
63 | | - gpio_enable(0xFF); // enable lowest eight |
64 | | - // wait a few cycles to give GPIO signal time to propagate |
65 | | - asm volatile("nop; nop; nop; nop; nop;"); |
66 | | - printf("GPIO (expect 0xA0): 0x%x\n", gpio_read()); |
67 | | - |
68 | | - gpio_toggle(0x0F); // toggle lower 8 GPIOs |
69 | | - asm volatile("nop; nop; nop; nop; nop;"); |
70 | | - printf("GPIO (expect 0x50): 0x%x\n", gpio_read()); |
71 | | - uart_write_flush(); |
72 | | - |
73 | | - // doing some compute |
74 | | - uint32_t start = get_mcycle(); |
75 | | - uint32_t res = isqrt(1234567890UL); |
76 | | - uint32_t end = get_mcycle(); |
77 | | - printf("Result: 0x%x, Cycles: 0x%x\n", res, end - start); |
78 | | - uart_write_flush(); |
79 | | - |
80 | | - // using the timer |
81 | | - printf("Tick\n"); |
82 | | - clint_sleep_ms(10); |
83 | | - printf("Tock\n"); |
| 13 | + uart_init(); |
| 14 | + printf("Hello World from Croc!\n"); |
84 | 15 | uart_write_flush(); |
85 | 16 | return 0; |
86 | 17 | } |
0 commit comments