Jump to content

how to model timing with interface method?


Qian

Recommended Posts

Hi, everyone.

I'm new to systemc and have some code as below. Slave module inherit and implement the write method of MyInterface, I have add a wait() statement to modeling the timing of write while get an error message saying "Error: (E519) wait() is only allowed in SC_THREADs and SC_CTHREADS: in SC_METHODS use next_trigger() instead".

So my question is how should I modeling timing with custom interface method? 

class Slave : public MyInterface, public sc_module {
  public:
    virtual void write(unsigned addr, char &data) {
      // slave takes 2 ns to finish
      wait(2, SC_NS);
      buf[addr] = data;
    }
}

Thank you for your comments!

Link to comment
Share on other sites

The code you wrote suits SC_THREAD processes but will not work with SC_METHOD processes. SC_THREADs allow yielding (i.e., calls to wait()) whereas SC_METHODs must execute in zero time and do not allow for waits. If you change the calling process to an SC_THREAD, then this would work; however, there are likely other things that need to change.

If you can use C++11, one solution would be to spawn a lambda to create a temporary SC_THREAD disconnected from the caller.

class Slave : public MyInterface, public sc_module {
  public:
    void write(unsigned addr, char &data) override {
      spawn( [&](){
        // slave takes 2 ns to finish
        wait(2, SC_NS);
        buf[addr] = data;
      } );
    }
}

A lot of this depends on the calling code, which you have not provided. The above solution may not work depending on how your SC_METHOD uses the results.

 

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