9086/system/testbench.cpp

53 lines
957 B
C++

#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
void tick() {
system_state->clock = 1;
contextp->timeInc(timeinc);
system_state->eval();
system_state->clock = 0;
contextp->timeInc(timeinc);
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);
contextp->commandArgs(argc, argv);
system_state = new Vsystem{contextp};
system_state->reset=1;
tick();
system_state->reset=0;
tick();
system_state->reset=1;
// Simulate until $finish
while(!contextp->gotFinish()){
tick();
}
system_state->final();
delete system_state;
delete contextp;
return 0;
}