SRachuj Posted April 12, 2017 Report Share Posted April 12, 2017 Hello, I have issues understanding sc_simcontext::next_time. The easiest way to describe what does not make sense for me is to give an example: #include <systemc> using namespace sc_core; SC_MODULE(A) { sc_out<bool> out; SC_CTOR(A) { SC_THREAD(t); } void t() { bool c = false; while (1) { wait(sc_time(1, SC_NS)); c = !c; out.write(c); } } }; SC_MODULE(B) { sc_in<bool> in; SC_CTOR(B) { SC_THREAD(t) } void t() { while (1) { wait(in.value_changed_event()); std::cout << "got: " << in.read() << std::endl; } } }; int sc_main(int argc, char** argv) { A a("a"); B b("b"); sc_signal<bool> s; a.out.bind(s); b.in.bind(s); while (1) { sc_time t; std::cout << sc_get_curr_simcontext()->next_time(t) << ": " << t << std::endl; sc_start(sc_time(1, SC_NS)); sleep(1); } } In this example, I would expect, that the output within the while loop of sc_main always prints 1 and the time until the next event happens (which should be 1 ns). However, when I run this program I get the following output: 0: 0 s 0: 0 s got: 1 0: 0 s got: 0 0: 0 s got: 1 0: 0 s got: 0 0: 0 s got: 1 0: 0 s got: 0 ^C Why do I always get "false" as the result for next_time? Did I misunderstand the what next_time does? Currently I'm using SystemC 2.3.1a. Thank you for your answers in advance! Quote Link to comment Share on other sites More sharing options...
AmeyaVS Posted April 12, 2017 Report Share Posted April 12, 2017 Hello @SRachuj, Please find the comment in-line: while (1) { sc_time t; std::cout << sc_get_curr_simcontext()->next_time(t) << ": " << t << std::endl; //< It hits the call to next_time(t) when the simulation has ended or did not even begin. sc_start(sc_time(1, SC_NS)); sleep(1); } You are calling the next_time(t): when the simulation has not even started so no events would be scheduled in the SystemC kernel. In the next pass once you have started the simulation for 1 ns. The simulation kernel will delete all the events which are scheduled after 1 ns. Try running putting the code in the module B. void t() { sc_time t; //< Added the sc_time state variable. while (1) { wait(in.value_changed_event()); std::cout << sc_get_curr_simcontext()->next_time(t) << ": " << t << std::endl; //< Added the next_time(t) in Module B. std::cout << "got: " << in.read() << std::endl; } } Regards, Ameya Vikram Singh Quote Link to comment Share on other sites More sharing options...
SRachuj Posted April 12, 2017 Author Report Share Posted April 12, 2017 Thank you @AmeyaVS for your response. Do you know of other approaches that achieve what I have written above? I thought, that it must be possible like this after reading a paper about distributing SystemC. But maybe, they didn't implement it in this way. Best Regards Quote Link to comment Share on other sites More sharing options...
maehne Posted April 13, 2017 Report Share Posted April 13, 2017 Have you looked at the functions defined in clause 4.5.7 Functions to detect pending activity of IEEE Std. 1666-2011? Using the simcontext directly is not advisable as its interface is not part of the SystemC standard. It is thus an implementation detail of the Accellera proof-of-concept implementation of SystemC on which you should not depend on if you want a portable solution. paulplusx, Philipp A Hartmann and SRachuj 3 Quote Link to comment Share on other sites More sharing options...
SRachuj Posted April 18, 2017 Author Report Share Posted April 18, 2017 Thank you very much, @maehne ! The example in the clause helped me a lot. I think, I can work with it, now. Best Regards 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.