-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathtb_Top.cpp
More file actions
48 lines (40 loc) · 1.21 KB
/
tb_Top.cpp
File metadata and controls
48 lines (40 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <verilated.h>
#include "verilated_vcd_c.h"
#include "VTop.h"
#define MAX_SIM_TIME 10000000 // In cycles
int main(int argc, char **argv, char **env) {
if (false && argc && argv && env) {}
Verilated::mkdir("logs");
const std::unique_ptr<VerilatedContext> contextp {new VerilatedContext};
contextp->commandArgs(argc, argv);
contextp->traceEverOn(true);
VerilatedVcdC *tfp = new VerilatedVcdC;
const std::unique_ptr<VTop> top {
new VTop {contextp.get(), "TOP"}
};
top->trace(tfp, 5);
tfp->open("logs/top.vcd");
unsigned int sim_time = 0;
top->clock = 1;
while (!contextp->gotFinish() && sim_time < MAX_SIM_TIME) {
top->clock ^= 1; // Toggle clock
if (sim_time <= 1) {
top->reset = 1; // Assert reset
} else {
top->reset = 0; // Deassert reset
}
top->eval(); // Evaluate model
tfp->dump(sim_time);
if (top->io_rvfi_valid_0 == 1 && top->io_rvfi_mem_wmask_0 == 15) {
if (top->io_rvfi_mem_addr_0 == 0x40000004) {
printf("%.8x\n", top->io_rvfi_mem_wdata_0); // Dump signature
} else if (top->io_rvfi_mem_addr_0 == 0x40000008 && top->io_rvfi_mem_wdata_0 == 0xCAFECAFE) {
break; // Terminate simulation
}
}
++sim_time;
}
top->final();
tfp->close();
return 0;
}