Skip to content

Commit 2affd6c

Browse files
[rom_ctrl, test] rom_ctrl smoketest added
* new testcase implemented among top level sw tests * the new test reads the compile time initialized ROM values * if any comparision fails (expected values differs from read value) test is terminated with an error
1 parent 66f9803 commit 2affd6c

File tree

8 files changed

+151
-1
lines changed

8 files changed

+151
-1
lines changed

sw/device/lib/hal/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
# SPDX-License-Identifier: Apache-2.0
44

5-
set(SRCS clkmgr.c gpio.c i2c.c mailbox.c mocha.c plic.c rstmgr.c spi_device.c timer.c uart.c)
5+
set(SRCS clkmgr.c gpio.c i2c.c mailbox.c mocha.c plic.c rstmgr.c spi_device.c timer.c uart.c rom_ctrl.c)
66

77
mocha_add_library(NAME hal LIBRARIES SOURCES ${SRCS})

sw/device/lib/hal/mocha.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
#include <cheriintrin.h>
1212
#endif /* defined(__riscv_zcherihybrid) */
1313

14+
static const uintptr_t rom_base = 0x80000ul;
1415
static const uintptr_t mailbox_base = 0x20010000ul;
1516
static const uintptr_t dv_test_status_base = 0x20020000ul;
1617
static const uintptr_t gpio_base = 0x40000000ul;
1718
static const uintptr_t clkmgr_base = 0x40020000ul;
1819
static const uintptr_t rstmgr_base = 0x40030000ul;
20+
static const uintptr_t rom_ctrl_base = 0x40050000ul;
1921
static const uintptr_t uart_base = 0x41000000ul;
2022
static const uintptr_t i2c_base = 0x42000000ul;
2123
static const uintptr_t spi_device_base = 0x43000000ul;
@@ -42,6 +44,15 @@ static void *create_mmio_capability(uintptr_t address, size_t length)
4244
}
4345
#endif /* defined(__riscv_zcherihybrid) */
4446

47+
rom_t mocha_system_rom(void)
48+
{
49+
#if defined(__riscv_zcherihybrid)
50+
return (uart_t)create_mmio_capability(rom_base, 0x48u);
51+
#else /* !defined(__riscv_zcherihybrid) */
52+
return (uart_t)rom_base;
53+
#endif /* defined(__riscv_zcherihybrid) */
54+
}
55+
4556
mailbox_t mocha_system_mailbox(void)
4657
{
4758
#if defined(__riscv_zcherihybrid)
@@ -78,6 +89,15 @@ rstmgr_t mocha_system_rstmgr(void)
7889
#endif /* defined(__riscv_zcherihybrid) */
7990
}
8091

92+
rom_ctrl_t mocha_system_rom_ctrl(void)
93+
{
94+
#if defined(__riscv_zcherihybrid)
95+
return (rom_ctrl_t)create_mmio_capability(rom_ctrl_base, 0x48u);
96+
#else /* !defined(__riscv_zcherihybrid) */
97+
return (rom_ctrl_t)rom_ctrl_base;
98+
#endif /* defined(__riscv_zcherihybrid) */
99+
}
100+
81101
uart_t mocha_system_uart(void)
82102
{
83103
#if defined(__riscv_zcherihybrid)

sw/device/lib/hal/mocha.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "hal/gpio.h"
1111
#include "hal/i2c.h"
1212
#include "hal/mailbox.h"
13+
#include "hal/rom_ctrl.h"
1314
#include "hal/plic.h"
1415
#include "hal/rstmgr.h"
1516
#include "hal/spi_device.h"
@@ -29,6 +30,8 @@ gpio_t mocha_system_gpio(void);
2930
clkmgr_t mocha_system_clkmgr(void);
3031
rstmgr_t mocha_system_rstmgr(void);
3132
uart_t mocha_system_uart(void);
33+
rom_t mocha_system_rom(void);
34+
rom_ctrl_t mocha_system_rom_ctrl(void);
3235
i2c_t mocha_system_i2c(void);
3336
spi_device_t mocha_system_spi_device(void);
3437
timer_t mocha_system_timer(void);

sw/device/lib/hal/rom_ctrl.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright lowRISC contributors (COSMIC project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#include "hal/rom_ctrl.h"
6+
#include "hal/mmio.h"
7+
#include "hal/mocha.h"
8+
#include <stdint.h>
9+
10+
/* Read specific word_idx-th word from ROM memory */
11+
uint32_t read_rom(rom_t rom, uint8_t word_idx)
12+
{
13+
uint32_t res;
14+
15+
res = DEV_READ(rom + 4*word_idx);
16+
17+
return res;
18+
}
19+

sw/device/lib/hal/rom_ctrl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright lowRISC contributors (COSMIC project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#pragma once
6+
7+
#include <stdbool.h>
8+
#include <stdint.h>
9+
10+
#define ROM_CTRL_REG (0x0)
11+
#define FATAL_ALERT_CAUSE (0x4)
12+
13+
typedef void *rom_ctrl_t;
14+
typedef void *rom_t;
15+
16+
#define ROM_CTRL_FROM_BASE_ADDR(addr) ((rom_ctrl_t)(addr))
17+
#define ROM_FROM_BASE_ADDR(addr) ((rom_t)(addr))
18+
19+
uint32_t read_rom(rom_t rom, uint8_t word_idx);
20+

sw/device/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ mocha_add_test(NAME tag_controller_tag_test SOURCES tag_controller/tag_test.c LI
1818
mocha_add_test(NAME timer_smoketest SOURCES timer/smoketest.c LIBRARIES ${LIBS} FPGA)
1919
mocha_add_test(NAME timer_interrupt_test SOURCES timer/interrupt.c LIBRARIES ${LIBS})
2020
mocha_add_test(NAME uart_smoketest SOURCES uart/smoketest.c LIBRARIES ${LIBS})
21+
mocha_add_test(NAME rom_ctrl_smoketest SOURCES rom_ctrl/smoketest.c LIBRARIES ${LIBS})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@00000000
2+
DEADBEEF
3+
CAFEBABE
4+
00000000
5+
00000001
6+
FFFFFFFF
7+
EEEEEEEE
8+
01234567
9+
10000001
10+
20000002
11+
30000003
12+
40000004
13+
50000005
14+
F000000F
15+
0EEEEEE0
16+
0FFFFFF0
17+
01010101
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright lowRISC contributors (COSMIC project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#include "hal/rom_ctrl.h"
6+
#include "hal/uart.h"
7+
#include "runtime/print.h"
8+
#include "hal/mmio.h"
9+
#include "hal/mocha.h"
10+
#include <stdbool.h>
11+
#include <stdint.h>
12+
13+
// Check ROM init values
14+
static bool rom_read_test(rom_t rom, uart_t console)
15+
{
16+
uint32_t data;
17+
uint8_t rom_length = 16;
18+
19+
// ROM Init values
20+
const uint32_t expected[] = {
21+
0xDEADBEEF,
22+
0xCAFEBABE,
23+
0x00000000,
24+
0x00000001,
25+
0xFFFFFFFF,
26+
0xEEEEEEEE,
27+
0x01234567,
28+
0x10000001,
29+
0x20000002,
30+
0x30000003,
31+
0x40000004,
32+
0x50000005,
33+
0xF000000F,
34+
0x0EEEEEE0,
35+
0x0FFFFFF0,
36+
0x01010101
37+
};
38+
39+
uprintf(console, "\nRead ROM!\n");
40+
41+
// Reading and comparing
42+
for (uint8_t word_idx = 0; word_idx < rom_length; word_idx++) {
43+
data = read_rom(rom, word_idx);
44+
uprintf(console, "data[%lx]:", (unsigned long)(uintptr_t)(rom + 4*word_idx));
45+
uprintf(console, "0x%x\n", data);
46+
47+
if (expected[word_idx] != data) {
48+
uprintf(console, "ROM Content mismatch Error.\n");
49+
uprintf(console, "Expected: 0x%x\n", expected[word_idx]);
50+
uprintf(console, "Terminating ROM CTRL read test.\n");
51+
52+
return false;
53+
}
54+
}
55+
56+
return true;
57+
}
58+
59+
bool test_main()
60+
{
61+
rom_t rom = mocha_system_rom();
62+
uart_t console = mocha_system_uart();
63+
bool read_test_res;
64+
65+
uart_init(console);
66+
67+
read_test_res = rom_read_test(rom, console);
68+
69+
return read_test_res;
70+
}

0 commit comments

Comments
 (0)