【问题标题】:Delay in bitvector Output assignment位向量输出分配延迟
【发布时间】:2020-05-03 03:17:18
【问题描述】:

我是 SystemC 的初学者,我真的需要您的帮助来解决时间问题。

请在下面找到 stimuli.h 代码,

    SC_MODULE(datagen)
{
    public: 
    sc_out<sc_bv<8>> busin_o;   
    SC_CTOR(datagen);

    /*private:*/

    void testgen(void);
    void asTakt(void);
};
    void datagen::testgen(void)
{       
    busin_o->write("11111111");
    cout<< "-------------------------------------"<< endl;
    cout << "In dataGen::testgen: @"
         << sc_time_stamp()
         << " Busin in datagen: "<< busin_o       
         <<endl;    

    wait(1,SC_NS);
    cout<< sc_delta_count() << endl;    
    busin_o->write("00111111");
    cout<< "-------------------------------------"<< endl;
    cout << "In dataGen::testgen: @"
         << sc_time_stamp()
         << " Busin in datagen: "<< busin_o       
         <<endl;  

    wait(1,SC_NS);  
    busin_o->write("10000111");
    cout<< "-------------------------------------"<< endl;
    cout << "In dataGen::testgen: @"
         << sc_time_stamp()
         << " Busin in datagen: "<< busin_o       
         <<endl;  
    wait(1,SC_NS);
    busin_o->write("11111110");
    cout<< "-------------------------------------"<< endl;
    cout << "In dataGen::testgen: @"
         << sc_time_stamp()
         << " Busin in datagen: "<< busin_o       
         <<endl; 
    cout<<"Intended end of simulation"<< endl;
    sc_stop();  
}

inputs2.h

    SC_MODULE(inputs)
{
    public:

    sc_in<sc_bv<8>> busin;
    sc_out<sc_bv<8>> pout;
    sc_out<sc_bv<8>> out;
    SC_CTOR(inputs);

    private:
    /* method*/
    void mydesign(void);
};

inputs2.cpp

inputs::inputs(sc_module_name inst)
    : sc_module(inst)
{   
    cout<<"Constructor- inputs: "<< name() <<endl;
    SC_METHOD(mydesign);
    sensitive << busin;
}
void inputs::mydesign()
{

    cout<< "-------------------------------------"<< endl;
    cout<<"Mydesign Activated @ "<<sc_time_stamp() <<endl;
    cout<< "-------------------------------------"<< endl;
    cout << "In Inputs::mydesign: @"
         << sc_time_stamp()
         << " Busin in Inputs: "<< busin       
         <<endl;  
    pout-> write(busin.read());
    cout << "In Inputs::mydesign: @"
         << sc_time_stamp()
         << " pout in Inputs: "<< pout
         <<endl;    
}

在终端中看到的输出如下所示。

    Copyright (c) 1996-2018 by all Contributors,
    ALL RIGHTS RESERVED
    Warning: (W506) illegal characters: data generator substituted by data_generator
    In file: ../../../src/sysc/kernel/sc_object.cpp:247
    Constructor- datagen: topblock.data_generator
    Constructor- inputs: topblock.inputs
    Constructor- top :topblock
    Simulation started time resolution :1 ps
    -------------------------------------
    Mydesign Activated @ 0 s
    -------------------------------------
    In Inputs::mydesign: @0 s Busin in Inputs: 00000000
    In Inputs::mydesign: @0 s pout in Inputs: 00000000
    -------------------------------------
    In dataGen::testgen: @0 s Busin in datagen: 00000000
    -------------------------------------
    Mydesign Activated @ 0 s
    -------------------------------------
    In Inputs::mydesign: @0 s Busin in Inputs: 11111111
    In Inputs::mydesign: @0 s pout in Inputs: 00000000
    2
    -------------------------------------
    In dataGen::testgen: @1 ns Busin in datagen: 11111111
    -------------------------------------
    Mydesign Activated @ 1 ns
    -------------------------------------
    In Inputs::mydesign: @1 ns Busin in Inputs: 00111111
    In Inputs::mydesign: @1 ns pout in Inputs: 11111111
    -------------------------------------
    In dataGen::testgen: @2 ns Busin in datagen: 00111111    
    -------------------------------------
    Mydesign Activated @ 2 ns
    -------------------------------------
    In Inputs::mydesign: @2 ns Busin in Inputs: 10000111
    In Inputs::mydesign: @2 ns pout in Inputs: 00111111
    -------------------------------------
    In dataGen::testgen: @3 ns Busin in datagen: 10000111    
    Intended end of simulation
    Info: /OSCI/SystemC: Simulation stopped by user.

我有两个问题,

1) mydesign 块被调用两次 @ 0 NS

2) 为什么我的datagen文件中的busin在1ns后更新?我已经可以在 0 NS 处看到 inputs.cpp 中的值。 busin 怎么会在 datagen 中获得它的值,但首先在 inputs.cpp 中更新。 (注:Inputs.cpp 文件从 datagen 接收业务值) 如果您说行为是正确的并且我不必修改代码中的任何内容,那么一切都很好。

感谢任何帮助。提前致谢。

【问题讨论】:

    标签: systemc bitvector


    【解决方案1】:

    对于问题#1,在零时间有两次激活,因为所有 SystemC 进程都将在零时间执行,而不会被敏感度触发。然后,第二次激活由您在零时间第一次写入总线触发。

    如果您不想在零时刻自动执行方法,请在指定方法后放置dont_initialize()

    SC_METHOD(mydesign);
    dont_initialize();     // this can go before or after sensitivities
    sensitive << busin;
    

    对于问题 #2inputs 块似乎更早地看到了该值,但真正的问题是 testgen 正在打印它之前写入总线的值。在您的代码中,busin_o 的值在写入后立即打印出来:

    busin_o->write("11111111");
    cout<< "-------------------------------------"<< endl;
    cout << "In dataGen::testgen: @"
         << sc_time_stamp()
         << " Busin in datagen: "<< busin_o       
         <<endl;    
    wait(1,SC_NS);
    

    当对sc_out(或sc_signal)执行write() 时,新值不会生效,直到您通过调用wait() 挂起线程。要查看应用的正确值,您需要在wait() 之后打印busin_o 的值。一种方法是在写入后放置一个零延迟等待:

    busin_o->write("11111111");
    wait(SC_ZERO_TIME);
    cout<< "-------------------------------------"<< endl;
    cout << "In dataGen::testgen: @"
         << sc_time_stamp()
         << " Busin in datagen: "<< busin_o       
         <<endl;    
    wait(1,SC_NS);
    

    请注意,您会看到与 pout 类似的行为。由于pout 的打印是在等待之前完成的,因此您正在打印pout 的先前值。

    要了解有关此行为的更多信息,请搜索术语“信号语义”和“延迟分配”。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多