Zdenek Prikryl Posted January 26, 2017 Report Share Posted January 26, 2017 Hi, Recently I used the following Verilog code in my project: module dff8( input wire CLK, input wire RST, input wire [7:0] D0, output reg [7:0] Q0 ); always @( posedge CLK or negedge RST ) begin if ( RST == 1'b0 ) begin Q0 <= 8'b0; end else begin Q0 <= #10 D0; end end endmodule Is there any way how to model #<DELAY> in SystemC. The example of systemc register that I use is below. SC_MODULE(dff8) { // port declarations sc_in<bool> CLK; sc_in<bool> RST; sc_in<sc_uint<8> > D0; sc_out<sc_uint<8> > Q0; // process declaration void do_dff8() { if (RST.read() == 0) { Q0.write(0); } else { // HOW TO ADD DELAY HERE? Q0.write(D0.read()); } } SC_HAS_PROCESS(dff8); dff8(sc_module_name inst) : sc_module(inst) { SC_METHOD(do_dff8); sensitive << CLK.pos(); sensitive << RST.neg(); } }; Thanks for any help. Quote Link to comment Share on other sites More sharing options...
AmeyaVS Posted January 26, 2017 Report Share Posted January 26, 2017 Hello, In SystemC you can use SC_THREAD's to model delays by using wait statements but you will incur performance penalty. Instead you can use event's and event queues to model delays using in SystemC as mentioned here: http://workspace.accellera.org/Discussion_Forums/helpforum/archive/msg/msg?list_name=help_forum&monthdir=200803&msg=msg00061.html You can replace the SC_THREAD example given in the above mentioned link with SC_METHOD removing the infinite while loop. Here's the modified example listed from the above mentioned link: template<typename T> class delay_transport : public sc_module { public: sc_in<T> in; sc_out<T> out; SC_HAS_PROCESS(delay_transport); delay_transport(sc_module_name name_, sc_time tdelay_) : sc_module(name_), tdelay(tdelay_), in("in"), out("out") { SC_METHOD(mi); sensitive << in.default_event(); SC_METHOD(mo); sensitive << eq; } sc_time tdelay; void mi() { val = in.read(); vq.push(val); eq.notify(tdelay); } void mo() { val = vq.front(); out.write(val); vq.pop(); } sc_event_queue eq; std::queue<T> vq; T val; }; Regards, Ameya Vikram Singh Shashidhar, maehne and jatin jatin 1 2 Quote Link to comment Share on other sites More sharing options...
whmmy Posted December 16, 2022 Report Share Posted December 16, 2022 On 1/26/2017 at 7:04 PM, AmeyaVS said: Hello, In SystemC you can use SC_THREAD's to model delays by using wait statements but you will incur performance penalty. Instead you can use event's and event queues to model delays using in SystemC as mentioned here: http://workspace.accellera.org/Discussion_Forums/helpforum/archive/msg/msg?list_name=help_forum&monthdir=200803&msg=msg00061.html You can replace the SC_THREAD example given in the above mentioned link with SC_METHOD removing the infinite while loop. Here's the modified example listed from the above mentioned link: template<typename T> class delay_transport : public sc_module { public: sc_in<T> in; sc_out<T> out; SC_HAS_PROCESS(delay_transport); delay_transport(sc_module_name name_, sc_time tdelay_) : sc_module(name_), tdelay(tdelay_), in("in"), out("out") { SC_METHOD(mi); sensitive << in.default_event(); SC_METHOD(mo); sensitive << eq; } sc_time tdelay; void mi() { val = in.read(); vq.push(val); eq.notify(tdelay); } void mo() { val = vq.front(); out.write(val); vq.pop(); } sc_event_queue eq; std::queue<T> vq; T val; }; Regards, Ameya Vikram Singh Hello bro. The link you gave seems to be invalid now. Where can I find it? Quote Link to comment Share on other sites More sharing options...
Admin Posted December 16, 2022 Report Share Posted December 16, 2022 The link only works if you are an Accellera member and logged into the Accellera Workspace. Perhaps AmeyaVS can paste the information in this thread. Quote Link to comment Share on other sites More sharing options...
David Black Posted December 17, 2022 Report Share Posted December 17, 2022 Actually, there is an easier way to model that delay. Simply use a spawned SC_THREAD. // The following is just a small code snippet in the context of the original posting void do_dff8() { if (RST->read() == 0) { Q0->write(0); } else { sc_spawn( [&](){ wait( 10, SC_NS ); Q0->write(D0->read()); }); } } Quote Link to comment Share on other sites More sharing options...
AmeyaVS Posted December 18, 2022 Report Share Posted December 18, 2022 Hello @MagicLantern, As far as I remember I have reproduced the content as it is from the resource I had found earlier, with minor changes. You can take a look at suggestion from @David Black, which is an alternate approach to achieving the same desired behavior. Just remember to enable dynamic processes using the build compilation configuration when using it with the Open source implementation of the SystemC kernel. Regards, Ameya Vikram Singh Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.