Skip to content

Commit

Permalink
Add cycle counter to servant testbench
Browse files Browse the repository at this point in the history
  • Loading branch information
olofk committed Feb 20, 2024
1 parent 086fff7 commit a92965b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions bench/servant_tb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "verilated_vcd_c.h"
#include "Vservant_sim.h"

#include <ctime>

using namespace std;

static bool done;
Expand Down Expand Up @@ -126,6 +128,14 @@ int main(int argc, char **argv, char **env)
if (arg_vcd_start[0])
vcd_start = atoi(arg_vcd_start+11);

int cur_cycle = 0;
int last_cycle = 0;
std::time_t last_time = std::time(nullptr);
int cps_file = 0;
const char *arg_cps = Verilated::commandArgsPlusMatch("cps=");
if (arg_cps[0])
cps_file = open("cps", O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);

bool dump = false;
top->wb_clk = 1;
bool q = top->q;
Expand Down Expand Up @@ -153,7 +163,16 @@ int main(int argc, char **argv, char **env)
top->wb_clk = !top->wb_clk;
main_time+=31.25;

if (cps_file) {
cur_cycle++;
if (std::time(nullptr) > last_time) {
dprintf(cps_file,"%d\n", (cur_cycle-last_cycle)/2);
last_cycle = cur_cycle;
last_time++;
}
}
}
close(cps_file);
close(tf);
if (tfp)
tfp->close();
Expand Down
6 changes: 6 additions & 0 deletions servant.core
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ targets:
parameters :
- RISCV_FORMAL
- "mdu? (MDU=1)"
- cps
- firmware
- memsize
- signature
Expand Down Expand Up @@ -577,6 +578,11 @@ parameters:
description : Enable/Disable the Compressed extension
paramtype : vlogparam

cps:
datatype : bool
description: Write simulated cycles per second to a text file named cps
paramtype : plusarg

firmware:
datatype : file
description : Preload RAM with a hex file at runtime (overrides memfile)
Expand Down

0 comments on commit a92965b

Please sign in to comment.