verilator仿真代码

顺手写了个带clk的.cpp,我的结果感觉clk还是有问题,不过嘛,和我一样的初学者也能勉强用了嘛不是

#include <verilated.h>          // 核心头文件
#include <verilated_vcd_c.h>    // 波形生成头文件
#include <iostream>
#include <fstream>
#include "Vtop.h"           // 译码器模块类
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>   
using namespace std;

Vtop*top;
VerilatedVcdC* tfp;             // 波形生成对象指针

vluint64_t main_time = 0;           // 仿真时间戳
const vluint64_t sim_time = 1024;   // 最大仿真时间戳


int main(int argc, char **argv){
// 一些初始化工作
    Verilated::commandArgs(argc, argv);
    Verilated::traceEverOn(true);
    // 为对象分配内存空间
    top = new Vtop;
    tfp = new VerilatedVcdC;
    top->reset = 0; // 把reset拉低
    // tfp初始化工作
    top->trace(tfp, 99);
    tfp->open("top.vcd");
	while (!Verilated::gotFinish() && main_time < sim_time) {
        if (main_time > 10) {
            top->reset = 1; // Deassert reset        // 拉高Reset,结束复位
        }
        if ((main_time % 10) == 1) {
            top->clk = 1; // 时钟翻转
        }
        if ((main_time % 10) == 6) {
            top->clk = 0; // 时钟翻转
        }
        top->eval(); // 计算输出
  tfp->dump(main_time);
  main_time++;
}
    // 清理工作
    tfp->close();
    delete top;
    delete tfp;
    exit(0);
return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值