tut4 with busy and request
This commit is contained in:
60
fsm-tut4/sim/top.cc
Normal file
60
fsm-tut4/sim/top.cc
Normal file
@@ -0,0 +1,60 @@
|
||||
#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, 99);
|
||||
tfp->open("build/waveform.vcd");
|
||||
|
||||
int last_led, last_state = 0, state = 0;
|
||||
printf("Initial state is: 0x%02x\n", tb->o_led);
|
||||
unsigned tickcount = 0;
|
||||
last_led = tb->o_led;
|
||||
|
||||
tb->i_request = 1;
|
||||
|
||||
for (int k = 0; k < 4; k++) {
|
||||
tick(++tickcount, tb, tfp);
|
||||
}
|
||||
|
||||
tick(++tickcount, tb, tfp);
|
||||
tb->i_request = 0;
|
||||
tick(++tickcount, tb, tfp);
|
||||
tb->i_request = 1;
|
||||
|
||||
for(int k=0; k<(1 << 16); k++) {
|
||||
tick(++tickcount, tb, tfp);
|
||||
|
||||
// if (last_led != tb->o_led) {
|
||||
// printf("k = %7d, led = %d\n", k, tb->o_led);
|
||||
// }
|
||||
|
||||
last_led = tb->o_led;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user