80 lines
1.7 KiB
C++
80 lines
1.7 KiB
C++
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "verilated.h"
|
|
#include "verilated_vcd_c.h"
|
|
#include "Vtop.h"
|
|
|
|
void tick(int tickcount, Vtop *tb, VerilatedVcdC* tfp) {
|
|
tb->eval();
|
|
if (tfp)
|
|
tfp->dump(tickcount * 10 - 2);
|
|
tb->i_clk = 1;
|
|
tb->eval();
|
|
if (tfp)
|
|
tfp->dump(tickcount * 10);
|
|
tb->i_clk = 0;
|
|
tb->eval();
|
|
if (tfp) {
|
|
tfp->dump(tickcount * 10 + 5);
|
|
tfp->flush();
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
// Call commandArgs first!
|
|
Verilated::commandArgs(argc, argv);
|
|
|
|
// Instantiate our design
|
|
Vtop *tb = new Vtop;
|
|
Verilated::traceEverOn(true);
|
|
VerilatedVcdC* tfp = new VerilatedVcdC;
|
|
|
|
tb->trace(tfp, 00);
|
|
tfp->open("build/waveform.vcd");
|
|
|
|
// initial state
|
|
tb->i_resetN = 1;
|
|
tb->i_startN = 1;
|
|
tb->i_stopN = 1;
|
|
unsigned tickcount = 0;
|
|
for (int k = 0; k < 2; k++)
|
|
tick(++tickcount, tb, tfp);
|
|
|
|
// reset pulse, then wait for a few clock cycles
|
|
tb->i_resetN = 0;
|
|
tick(++tickcount, tb, tfp);
|
|
tb->i_resetN = 1;
|
|
|
|
for (int k = 0; k < 3; k++)
|
|
tick(++tickcount, tb, tfp);
|
|
|
|
// relevant const
|
|
const unsigned int main_clk_Hz = 100 * 1000 * 1000; // 100 MHz
|
|
const unsigned int db_clk_Hz = 10; // 10 ms -> 10 Hz
|
|
const unsigned int db_ticks = main_clk_Hz / db_clk_Hz;
|
|
|
|
// start pulse
|
|
|
|
tb->i_startN = 0;
|
|
tick(++tickcount, tb, tfp);
|
|
tb->i_startN = 1;
|
|
|
|
for (int k = 0; k < 394; k++)
|
|
tick(++tickcount, tb, tfp);
|
|
|
|
// stop pulse
|
|
tb->i_stopN = 0;
|
|
tick(++tickcount, tb, tfp);
|
|
tb->i_stopN = 1;
|
|
|
|
for (int k = 0; k < (1<<16); k++)
|
|
tick(++tickcount, tb, tfp);
|
|
|
|
tb->i_resetN = 0;
|
|
tick(++tickcount, tb, tfp);
|
|
tb->i_resetN = 1;
|
|
|
|
for (int k = 0; k < 30; k++)
|
|
tick(++tickcount, tb, tfp);
|
|
}
|