diff --git a/examples/saif_example/counter.v b/examples/saif_example/counter.v new file mode 100644 index 000000000..9cf1356cd --- /dev/null +++ b/examples/saif_example/counter.v @@ -0,0 +1,51 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// Copyright 2025 by Antmicro. This program is free software; you can +// redistribute it and/or modify it under the terms of either the GNU +// Lesser General Public License Version 3 or the Perl Artistic License +// Version 2.0. +// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +module t ( + // Outputs + state, + // Inputs + clk); + + input clk; + reg rst; + output [7:0] state; + + counter c0 ( + .clk (clk), + .rst (rst), + .out (state)); + + int cyc; + + always @ (posedge clk) begin + cyc <= cyc + 1; + if (cyc == 0) begin + rst <= 1; + end + else if (cyc == 10) begin + rst <= 0; + end + else if (cyc == 11) begin + rst <= 1; + end + end +endmodule + +module counter ( + input clk, + input rst, + output reg[7:0] out); + + always @ (posedge clk) begin + if (!rst) + out <= 0; + else + out <= out + 1; + end +endmodule diff --git a/examples/saif_example/saif_trace.cpp b/examples/saif_example/saif_trace.cpp new file mode 100644 index 000000000..19c335cd3 --- /dev/null +++ b/examples/saif_example/saif_trace.cpp @@ -0,0 +1,55 @@ +// -*- mode: C++; c-file-style: "cc-mode" -*- +// +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2025 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +#include +#include + +#include + +#include "Vcounter.h" + +int errors = 0; + +unsigned long long main_time = 0; +double sc_time_stamp() { return static_cast(main_time); } + +const char* trace_name() { + static char name[1000]; + VL_SNPRINTF(name, 1000, "simx.saif"); + return name; +} + +int main(int argc, char** argv) { + Verilated::debug(0); + Verilated::traceEverOn(true); + Verilated::commandArgs(argc, argv); + + std::unique_ptr top{new Vcounter}; + + std::unique_ptr tfp{new VerilatedSaifC}; + + static constexpr int SIMULATION_DURATION{199}; + top->trace(tfp.get(), SIMULATION_DURATION); + + tfp->open(trace_name()); + + top->clk = 0; + + while (main_time < SIMULATION_DURATION) { + top->clk = !top->clk; + top->eval(); + tfp->dump(static_cast(main_time)); + ++main_time; + } + tfp->close(); + top->final(); + tfp.reset(); + top.reset(); + printf("*-* All Finished *-*\n"); + return errors; +}