Qian Posted July 20 Report Share Posted July 20 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! Quote Link to comment Share on other sites More sharing options...
David Black Posted July 20 Report Share Posted July 20 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. Quote Link to comment Share on other sites More sharing options...
Qian Posted July 20 Author Report Share Posted July 20 Thank you for your explanation! Indeed the caller was a common C++ function, problem has been solved by using a SC_THREAD. 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.