Jump to content

SC_METHOD use next_tirgger() delay time once like SC_THREAD use wait()


Recommended Posts

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;
}

```

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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(). 

Link to comment
Share on other sites

  • 2 weeks later...

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;
};

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...