| /* | |
| * Current simulation time | |
| * This is a 64-bit integer to reduce wrap over issues and | |
| * allow modulus. You can also use a double, if you wish. | |
| */ | |
| vluint64_t main_time = 0; | |
| /* | |
| * Called by $time in Verilog | |
| * converts to double, to match | |
| * what SystemC does | |
| */ | |
| double sc_time_stamp(void) | |
| { | |
| return main_time; | |
| } | |
| VerilatedVcdC *tfp; | |
| void tick(Vtoplevel *top) | |
| { | |
| top->ext_clk = 1; | |
| top->eval(); | |
| if (tfp) | |
| tfp->dump((double) main_time); | |
| main_time++; | |
| top->ext_clk = 0; | |
| top->eval(); | |
| if (tfp) | |
| tfp->dump((double) main_time); | |
| main_time++; | |
| } | |
| void uart_tx(unsigned char tx); | |
| unsigned char uart_rx(void); | |
| int main(int argc, char **argv) | |
| { | |
| Verilated::commandArgs(argc, argv); | |
| // init top verilog instance | |
| Vtoplevel* top = new Vtoplevel; | |
| // init trace dump | |
| Verilated::traceEverOn(true); | |
| tfp = new VerilatedVcdC; | |
| top->trace(tfp, 99); | |
| tfp->open("microwatt-verilator.vcd"); | |
| // Reset | |
| top->ext_rst = 0; | |
| for (unsigned long i = 0; i < 5; i++) | |
| tick(top); | |
| top->ext_rst = 1; | |
| while(!Verilated::gotFinish()) { | |
| tick(top); | |
| uart_tx(top->uart0_txd); | |
| top->uart0_rxd = uart_rx(); | |
| } | |
| tfp->close(); | |
| delete tfp; | |
| delete top; | |
| } | |