Skip to content

Commit 9c92d3b

Browse files
committed
sw: simplify helloworld to minimum
1 parent 70444d4 commit 9c92d3b

File tree

2 files changed

+12
-78
lines changed

2 files changed

+12
-78
lines changed

sw/config.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
#pragma once
99

1010
// Address map
11-
#define SOCCTRL_BASE_ADDR 0x03000000
12-
#define UART_BASE_ADDR 0x03002000
13-
#define GPIO_BASE_ADDR 0x03005000
11+
#define DEBUG_BASE_ADDR 0x00000000
12+
#define BOOTROM_BASE_ADDR 0x02000000
13+
#define CLINT_BASE_ADDR 0x02040000
14+
#define SOCCTRL_BASE_ADDR 0x03000000
15+
#define UART_BASE_ADDR 0x03002000
16+
#define GPIO_BASE_ADDR 0x03005000
1417
#define OBI_TIMER_BASE_ADDR 0x0300A000
15-
#define IDMA_BASE_ADDR 0x0300B000
16-
#define CLINT_BASE_ADDR 0x02040000
18+
#define IDMA_BASE_ADDR 0x0300B000
19+
#define USER_ROM_BASE_ADDR 0x20000000
1720

1821
// Frequencies
1922
#define TB_FREQUENCY 20000000

sw/helloworld.c

Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,17 @@
11
// Copyright (c) 2024 ETH Zurich and University of Bologna.
22
// 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
44
//
55
// Authors:
66
// - Philippe Sauter <phsauter@iis.ee.ethz.ch>
77

88
#include "uart.h"
99
#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"
3511

3612
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");
8415
uart_write_flush();
8516
return 0;
8617
}

0 commit comments

Comments
 (0)