• SystemC学习(2)— D触发器的建模与测试


    SystemC学习(2)— D触发器的建模与测试

    一、前言

    二、D触发器建模

    编写D触发器模型文件dff.h文件如下所示:

    #ifndef __DFF_H
    #define __DFF_H
    
    #include "systemc.h"
    
    const int DSZIE = 8;
    
    SC_MODULE(dff){
        sc_in<bool> clk;
        sc_in<bool> reset;
        sc_in<sc_uint<DSIZE> > data_in;
        sc_in<sc_uint<DSIZE> > data_out;
    
        SC_CTOR(dff){
            SC_METHOD(prc_dff);    
            sensitive << clk.pos << reset.pos;
        }
    
        void prc_dff(){
            if(reset)
                data_out = 0;
            else
                data_out = data_in;
        }
    };
    
    #endif
    
    

    三、测试平台

    编写“driver.h”如下所示:

    #ifndef __DRIVER_H
    #define __DRIVER_H
    
    #include "dff.h"
    
    SC_MODULE(driver){
        sc_in<bool> clk;
        sc_in<sc_uint<DSIZE> > data_out;
        sc_out<bool> reset;
        sc_out<sc_uint<DSIZE> > data_in;
    
        SC_CTOR(driver){
            SC_THREAD(prc_test);
            sensitive << clk.pos();
            SC_METHOD(prc_check)
            sensitive << data_out;
        }
    
        void prc_test(){
            reset.write(1);
            wait();
            wait();
            reset.write(0);
            data_in.write(1);
            wait();
            data_in.write(2);
            wait();
            data_in.write(3);
            wait();
            data_in.write(4);
            wait();
            data_in.write(5);
            wait();
            data_in.write(6);
            wait();
            data_in.write(7);
            wait();
            data_in.write(8);
            wait();
            data_in.write(9);
            wait();
            data_in.write(10);
            wait();
            sc_stop();
        }
    
        void prc_check(){
            cout << "Output data is(@" << sc_time_stamp() << "): " << data_out.read() << endl;
        }
    };
    
    #endif
    
    

    编写“main.cpp”文件如下所示:

    #include "driver.h"
    
    int sc_main(int argc, char *argv[]){
        sc_clock clk("clk", 2, SC_NS);
        sc_signal<bool> reset;
        sc_signal<sc_uint<DSIZE> > data_in, data_out;
    
    
        driver drv("drv");
        drv.clk(clk);
        drv.reset(reset);
        drv.data_out(data_out);
        drv.data_in(data_in);
    
        dff dut("dut");
        dut.clk(clk);
        dut.reset(reset);
        dut.data_out(data_out);
        dut.data_in(data_in);
    
        sc_start();
    
        return 0;
    }
    
    

    四、测试运行

    使用如下命令进行编译:

    g++ main.cpp -I${SYSTEMC_HOME}/include/ -L${SYSTEMC_HOME}/lib-linux64 -lsystemc -o run.x
    

    运行命令:

    ./run.x
    

    运行结果如下所示:
    在这里插入图片描述

  • 相关阅读:
    Neo4j:一、CQL语句
    CRMEB 商城系统如何助力营销?
    基于OpenCV的轮廓检测(3)
    EasyExcel实现动态列解析和存表
    MyBatisPlus(二十一)乐观锁
    Vue3学习笔记:ref函数、reactive函数等常用Composition API、生命周期,Fragment、teleport等新的组件用法记录
    基于vue的移动端如何监听系统返回
    408王道操作系统强化——文件管理及大题解构
    .NET分布式Orleans - 6 - 事件溯源
    SpringBoot如何使用JDBC操作数据库呢?
  • 原文地址:https://blog.csdn.net/qq_38113006/article/details/143255700