9086/system/testbench.cpp

53 lines
957 B
C++
Raw Permalink Normal View History

2023-03-04 08:37:43 +00:00
#include "Vsystem.h"
#include "verilated.h"
#include "stdio.h"
Vsystem *system_state;
VerilatedContext* contextp;
/*In hz */
#define CPU_SPEED 1000
#define timeinc CPU_SPEED*1000000/2
2023-03-04 08:37:43 +00:00
void tick() {
system_state->clock = 1;
contextp->timeInc(timeinc);
2023-03-04 08:37:43 +00:00
system_state->eval();
system_state->clock = 0;
contextp->timeInc(timeinc);
2023-03-04 08:37:43 +00:00
system_state->eval();
}
int main(int argc, char** argv) {
contextp = new VerilatedContext;
// Set debug level, 0 is off, 9 is highest presently used
// May be overridden by commandArgs argument parsing
contextp->debug(0);
// Verilator must compute traced signals
contextp->traceEverOn(true);
2023-03-04 08:37:43 +00:00
contextp->commandArgs(argc, argv);
system_state = new Vsystem{contextp};
2023-03-04 08:37:43 +00:00
system_state->reset=1;
tick();
system_state->reset=0;
tick();
system_state->reset=1;
// Simulate until $finish
2023-03-04 08:37:43 +00:00
while(!contextp->gotFinish()){
tick();
}
system_state->final();
2023-03-04 08:37:43 +00:00
delete system_state;
delete contextp;
return 0;
}