I am a beginner in SystemC, and I really need your help in solving a timing issue.
Please find the stimuli.h code below,
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;
}
The output that is seen in the terminal is shown below.
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.
The two questions I have are,
1) mydesign block is being called twice @ 0 NS
2) Why does busin in my datagen file update after 1ns? I can already see the value in inputs.cpp at 0 NS. How can it happen that busin gets its value in datagen but updates in inputs.cpp first. (Note : Inputs.cpp file receives busin value from datagen) If you say that the behavior is correct and I don't have to modify anything in my code, then it's all good.
Any help is appreciated. Thanks in advance.
For question #1 , there are two activations at time zero because all SystemC processes will execute at time zero, without being triggered by sensitivities. The second activation is then triggered by your first write to the bus at time zero.
If you don't want automatic execution of the method at time zero, place dont_initialize()
after specifying the method:
SC_METHOD(mydesign);
dont_initialize(); // this can go before or after sensitivities
sensitive << busin;
For question #2 , the inputs
block looks to be seeing the value earlier, but the real problem is that testgen
is printing the previous value it had written to the bus. In your code, the value of busin_o
is printed immediately after writing it:
busin_o->write("11111111");
cout<< "-------------------------------------"<< endl;
cout << "In dataGen::testgen: @"
<< sc_time_stamp()
<< " Busin in datagen: "<< busin_o
<<endl;
wait(1,SC_NS);
When doing a write()
to an sc_out
(or sc_signal
), the new value does not take effect until you suspend the thread by calling wait()
. To see the correct value that was applied, you need to print the value of busin_o
after a wait()
. One approach could be to put a zero-delay wait after the write:
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);
Note that you're seeing similar behavior with pout
. Since the print of pout
is done before crossing a wait, you are printing the previous value of pout
.
To find more about this behavior, search for the terms "signal semantics" and "delayed assignment".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.