SC_THREAD不会被其敏感度列表触发 [英] SC_THREAD does not get triggered by its sensitivity list

查看:344
本文介绍了SC_THREAD不会被其敏感度列表触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在SystemC中开发一个简单的NAND模块.按照规范,它应该有4 ns的延迟,因此我尝试使用带有"wait"语句和SC_THREAD的进程来描述它,如下所示:

I am developing a simple NAND module in SystemC. By specification, it should have a 4 ns delay so I tried to describe it with a process with a "wait" statement and SC_THREAD, as follows:

//file: nand.h
#include "systemc.h"

SC_MODULE(nand2){
    sc_in<bool> A, B; 
    sc_out<bool> F; 

    void do_nand2(){
        bool a, b, f;
        a = A.read();
        b = B.read();
        f = !(a && b);
        wait(4, SC_NS);
        F.write(f);
    }

    SC_CTOR(nand2){
        SC_THREAD(do_nand2);
        sensitive << A << B;
    }
};

为了模拟,我创建了另一个模块,输出用于NAND的激励,如下所示:

To simulate I've created another module the outputs the stimulus for the NAND, as follows:

//file: stim.h
#include "systemc.h"

SC_MODULE(stim){
    sc_out<bool> A, B;
    sc_in<bool> Clk;

    void stimGen(){
        wait();
        A.write(false);
        B.write(false);
        wait();
        A.write(false);
        B.write(true);
        wait();
        A.write(true);
        B.write(true);
        wait();
        A.write(true);
        B.write(false);
    }

    SC_CTOR(stim){
        SC_THREAD(stimGen);
        sensitive << Clk.pos();
    }
};

描述了这两个模块后,顶部模块(其中sc_main所在)看起来像这样:

Having these two modules described, the top module (where sc_main is) looks like this:

//file: top.cpp    
#include "systemc.h"
#include "nand.h"
#include "stim.h"

int sc_main(int argc, char* argv[]){
    sc_signal<bool> ASig, BSig, FSig;
    sc_clock Clk("Clock", 100, SC_NS, 0.5);

    stim Stim("Stimulus");
    Stim.A(ASig); Stim.B(BSig); Stim.Clk(Clk);

    nand2 nand2("nand2");
    nand2.A(ASig); nand2.B(BSig); nand2.F(FSig);

    sc_trace_file *wf = sc_create_vcd_trace_file("sim");
    sc_trace(wf, Stim.Clk, "Clock");
    sc_trace(wf, nand2.A, "A");
    sc_trace(wf, nand2.B, "B");
    sc_trace(wf, nand2.F, "F");

    sc_start(400, SC_NS);

    sc_close_vcd_trace_file(wf);

    return 0;
}

代码经过编译和仿真没有错误,但是当在gtkwave中可视化.vcd文件时,输出(F)停留在1,仅显示仿真开始时的延迟.

The code was compiled and simulated with no errors, however when visualizing the .vcd file in gtkwave the output (F) gets stuck in 1, only showing the delay in the beginning of the simulation.

要测试代码中是否有错误,我删除了"wait"语句,并在nand.h文件中将SC_THREAD更改为SC_METHOD,并再次进行了仿真,现在获得了正确的结果,但没有延迟当然.

To test if there were any errors in the code I removed the "wait" statements and changed SC_THREAD to SC_METHOD in the nand.h file and simulated again, now getting the correct results, but without the delays of course.

我在做什么错了?

推荐答案

只需解决问题:

代替

wait(4, SC_NS); 

使用SC_THREAD我使用

next_trigger(4, SC_NS);

SC_METHOD一起使用,效果很好.

with SC_METHOD and it worked just fine.

这篇关于SC_THREAD不会被其敏感度列表触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆