2022-08-01 22:01:24 +08:00
|
|
|
#include <atomic>
|
2022-07-29 23:25:14 +08:00
|
|
|
#include <chrono>
|
|
|
|
#include <iostream>
|
2022-07-27 15:07:16 +08:00
|
|
|
|
2022-08-01 22:01:24 +08:00
|
|
|
#include <signal.h>
|
|
|
|
|
2022-07-27 15:07:16 +08:00
|
|
|
#include "Vtestbench_top.h"
|
2022-07-29 23:25:14 +08:00
|
|
|
#include <verilated.h>
|
2022-07-27 15:07:16 +08:00
|
|
|
|
2022-08-01 22:01:24 +08:00
|
|
|
std::atomic<bool> ctrl_c_hit;
|
|
|
|
void ctrl_c_handler(int sig) { ctrl_c_hit = true; }
|
|
|
|
|
2022-07-27 15:07:16 +08:00
|
|
|
vluint64_t main_time = 0;
|
2022-07-29 23:25:14 +08:00
|
|
|
double sc_time_stamp() { return main_time; }
|
2022-07-27 15:07:16 +08:00
|
|
|
|
|
|
|
int main(int argc, char **argv, char **env) {
|
2022-08-01 22:01:24 +08:00
|
|
|
ctrl_c_hit = false;
|
|
|
|
signal(SIGINT, ctrl_c_handler);
|
|
|
|
|
2024-01-10 22:02:49 +08:00
|
|
|
unsigned int switch_sim = 0;
|
|
|
|
if (argc > 1)
|
|
|
|
switch_sim = atoi(argv[1]);
|
|
|
|
|
2022-07-29 17:44:11 +08:00
|
|
|
Verilated::commandArgs(argc, argv);
|
2022-07-27 15:07:16 +08:00
|
|
|
Verilated::randReset(2);
|
|
|
|
Verilated::traceEverOn(true);
|
|
|
|
Verilated::mkdir("logs");
|
|
|
|
|
|
|
|
const int reset_time = 10;
|
2022-08-01 22:01:24 +08:00
|
|
|
const int time_limit = 2900000; // {0xff, 2900000}
|
2022-07-27 15:07:16 +08:00
|
|
|
|
2022-07-29 17:44:11 +08:00
|
|
|
Vtestbench_top *top = new Vtestbench_top;
|
2022-07-27 15:07:16 +08:00
|
|
|
|
2022-07-29 23:25:14 +08:00
|
|
|
std::cout << "<<< Simulation Started >>>" << std::endl;
|
|
|
|
auto time_start = std::chrono::high_resolution_clock::now();
|
2022-07-27 15:07:16 +08:00
|
|
|
top->clk = 0;
|
2024-01-10 22:02:49 +08:00
|
|
|
top->switch_sim = ~switch_sim;
|
2022-07-29 17:44:11 +08:00
|
|
|
while (!Verilated::gotFinish() && main_time < time_limit) {
|
2022-08-01 22:01:24 +08:00
|
|
|
if (ctrl_c_hit)
|
|
|
|
break;
|
|
|
|
|
2022-07-27 15:07:16 +08:00
|
|
|
++main_time;
|
|
|
|
top->clk = !top->clk;
|
2022-07-29 17:44:11 +08:00
|
|
|
top->resetn = (main_time < reset_time) ? 0 : 1;
|
2024-01-10 22:02:49 +08:00
|
|
|
|
|
|
|
#if VM_COVERAGE
|
2022-07-29 23:25:14 +08:00
|
|
|
if (main_time < reset_time)
|
|
|
|
VerilatedCov::zero();
|
2024-01-10 22:02:49 +08:00
|
|
|
#endif
|
2022-07-29 17:44:11 +08:00
|
|
|
|
2022-07-27 15:07:16 +08:00
|
|
|
top->eval();
|
|
|
|
}
|
2022-07-29 23:25:14 +08:00
|
|
|
auto time_end = std::chrono::high_resolution_clock::now();
|
2022-07-27 15:07:16 +08:00
|
|
|
|
2022-07-29 17:44:11 +08:00
|
|
|
if (main_time == time_limit)
|
2022-07-29 23:25:14 +08:00
|
|
|
std::cout << "<<< Time Limit Reached >>>" << std::endl;
|
2022-08-01 22:01:24 +08:00
|
|
|
if (ctrl_c_hit)
|
|
|
|
std::cout << "<<< Ctrl-C >>>" << std::endl;
|
2022-07-29 23:25:14 +08:00
|
|
|
std::cout << "<<< Simulation Ended >>>" << std::endl;
|
|
|
|
std::cout << "Realworld Time: "
|
|
|
|
<< std::chrono::duration_cast<std::chrono::seconds>(time_end - time_start).count()
|
|
|
|
<< "s" << std::endl;
|
|
|
|
std::cout << "Simulation Time: " << main_time / 2 << " cycles" << std::endl;
|
2022-07-29 17:44:11 +08:00
|
|
|
|
2022-07-27 15:07:16 +08:00
|
|
|
top->final();
|
|
|
|
|
|
|
|
#if VM_COVERAGE
|
|
|
|
Verilated::mkdir("logs");
|
|
|
|
VerilatedCov::write("logs/coverage.dat");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
delete top;
|
|
|
|
top = NULL;
|
|
|
|
exit(0);
|
|
|
|
}
|