|
| 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/mmio.h" |
| 6 | +#include "hal/mocha.h" |
| 7 | +#include "hal/rom_ctrl.h" |
| 8 | +#include "hal/uart.h" |
| 9 | +#include "runtime/print.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 | + uint32_t address; |
| 18 | + uint8_t address_length = 3; |
| 19 | + uint8_t data_length = 4; |
| 20 | + |
| 21 | + // ROM Address values |
| 22 | + const uint32_t expected_addresses[3] = { 0x00000000, 0x00004000, 0x00007FF0 }; |
| 23 | + |
| 24 | + // ROM Init values |
| 25 | + const uint32_t expected_data[3][4] = { { 0xDEADBEEF, 0xCAFEBABE, 0x00000001, 0xEEEEEEEE }, |
| 26 | + { 0x01234567, 0x10000001, 0x20000002, 0x30000003 }, |
| 27 | + { 0xF000000F, 0x0EEEEEE0, 0x0FFFFFF0, 0x01010101 } }; |
| 28 | + |
| 29 | + uprintf(console, "\nRead ROM!\n"); |
| 30 | + |
| 31 | + // Reading and comparing |
| 32 | + for (uint8_t address_idx = 0; address_idx < address_length; address_idx++) { |
| 33 | + for (uint8_t word_idx = 0; word_idx < data_length; word_idx++) { |
| 34 | + address = 4 * word_idx + expected_addresses[address_idx]; |
| 35 | + data = read_rom(rom, address); |
| 36 | + uprintf(console, "[%lx] | ", (unsigned long)(uintptr_t)(rom + address)); |
| 37 | + uprintf(console, "0x%x \n", data); |
| 38 | + |
| 39 | + if (expected_data[address_idx][word_idx] != data) { |
| 40 | + uprintf(console, "Expected: 0x%x\n", expected_data[address_idx][word_idx]); |
| 41 | + uprintf(console, "ROM Content mismatch Error. Terminating ROM CTRL read test\n"); |
| 42 | + |
| 43 | + return false; |
| 44 | + } |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + return true; |
| 49 | +} |
| 50 | + |
| 51 | +bool test_main() |
| 52 | +{ |
| 53 | + rom_t rom = mocha_system_rom(); |
| 54 | + uart_t console = mocha_system_uart(); |
| 55 | + bool read_test_res; |
| 56 | + |
| 57 | + uart_init(console); |
| 58 | + |
| 59 | + read_test_res = rom_read_test(rom, console); |
| 60 | + |
| 61 | + return read_test_res; |
| 62 | +} |
0 commit comments