Allen yang Posted November 12 Report Share Posted November 12 I have these code. And I want to execute it once print timestamp with SC_METHOD. But if I use next_trigger in the register function Push, it will print many time not once. SC_THREAD use wait() ``` class TestPlatform : public sc_module { public: SC_HAS_PROCESS(TestPlatform); TestPlatform(const sc_module_name& name, const int freq) : sc_module(name), { SC_THREAD(Push); }; void Push(); bool m_trigger_flag; }; void TestPlatform::Push() { wait(2, SC_NS); cout << sc_time_stamp() << endl; } ``` SC_METHOD use next_trigger implement. I use a memeber var m_trigger_flag to control it execute once. I wonder there is any better implement. ``` class TestPlatform : public sc_module { public: SC_HAS_PROCESS(TestPlatform); TestPlatform(const sc_module_name& name, const int freq) : sc_module(name), { SC_METHOD(Push); }; void Push(); bool m_trigger_flag; }; void TestPlatform::Push() { if (m_trigger_flag) { next_trigger(2, SC_NS); m_trigger_flag = false; return; } cout << sc_time_stamp() << endl; } ``` Quote Link to comment Share on other sites More sharing options...
Eyck Posted November 12 Report Share Posted November 12 When posting code it is best to show an example using https://www.edaplayground.com. I copied part of ypur code at https://www.edaplayground.com/x/NSAs The problem is the missing initialization of m_trigger_flag. Depending of your build settings and many more factors it might be true or false. When being false the method is only executed during the initial evalauation phase.... Allen yang 1 Quote Link to comment Share on other sites More sharing options...
Allen yang Posted November 12 Author Report Share Posted November 12 Thanks @Eyck. I have copy your edaplaygroud code to myself at https://www.edaplayground.com/x/7yHV. And I can run sc_method with next_trigger in 2ns only. I find that using the var m_trigger_flag to control delay execution on sc_mehtod register function is ugly. Is there any better way to implete like sc_thread using wait(). Quote Link to comment Share on other sites More sharing options...
Eyck Posted November 20 Report Share Posted November 20 If I got you rigth you want to trigger the method exactly once after 2ns, right? In that case I would write the TestPlatform differently: class TestPlatform : public sc_core::sc_module { public: SC_HAS_PROCESS(TestPlatform); TestPlatform(const sc_core::sc_module_name& name, const int freq) : sc_core::sc_module(name), m_trigger_flag(true) { SC_METHOD(Push); dont_initialize(); sensitive<<trigger_evt; trigger_evt.notify(sc_core::sc_time(2, sc_core::SC_NS)); }; void Push(){ std::cout << sc_core::sc_time_stamp() << std::endl; } private: sc_core::sc_event trigger_evt; }; 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.