58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
#include <iostream>
|
|
|
|
#include "Vpicorv32_wrapper.h"
|
|
#include "verilated_vcd_c.h"
|
|
|
|
int main(int argc, char** argv, char** env) {
|
|
printf("Built with %s %s.\n", Verilated::productName(),
|
|
Verilated::productVersion());
|
|
printf("Recommended: Verilator 4.0 or later.\n");
|
|
|
|
Verilated::commandArgs(argc, argv);
|
|
Vpicorv32_wrapper* top = new Vpicorv32_wrapper;
|
|
|
|
std::string hexfile;
|
|
if (argc > 1) {
|
|
hexfile = std::string(argv[1]);
|
|
} else {
|
|
hexfile = std::string("firmware/firmware.hex");
|
|
}
|
|
auto hex = (uint8_t*)(top->hex_file.data());
|
|
auto csr = hexfile.c_str();
|
|
for (int i = 0; i < hexfile.size(); i += 1) {
|
|
*(hex + (128 - i)) = *(uint8_t*)(csr + i);
|
|
}
|
|
|
|
// Tracing (vcd)
|
|
VerilatedVcdC* tfp = NULL;
|
|
const char* flag_vcd = Verilated::commandArgsPlusMatch("vcd");
|
|
if (flag_vcd && 0 == strcmp(flag_vcd, "+vcd")) {
|
|
Verilated::traceEverOn(true);
|
|
tfp = new VerilatedVcdC;
|
|
top->trace(tfp, 99);
|
|
tfp->open("testbench.vcd");
|
|
}
|
|
|
|
// Tracing (data bus, see showtrace.py)
|
|
FILE* trace_fd = NULL;
|
|
const char* flag_trace = Verilated::commandArgsPlusMatch("trace");
|
|
if (flag_trace && 0 == strcmp(flag_trace, "+trace")) {
|
|
trace_fd = fopen("testbench.trace", "w");
|
|
}
|
|
|
|
top->clk = 0;
|
|
top->rst = 1;
|
|
|
|
int t = 0;
|
|
while (!Verilated::gotFinish()) {
|
|
if (t > 200) top->rst = 0;
|
|
top->clk = !top->clk;
|
|
top->eval();
|
|
if (tfp) tfp->dump(t);
|
|
t += 5;
|
|
}
|
|
if (tfp) tfp->close();
|
|
delete top;
|
|
exit(0);
|
|
}
|