Jump to content
katang

SC_METHOD and next_trigger() diagnostics

Recommended Posts

I receive the message

Error: (E520) next_trigger() is only allowed in SC_METHODs:
        in SC_THREADs and SC_CTHREADs use wait() instead

when running my code (the relevant fragments are shown below). Any idea, what could be wrong? (what else is needed?)
 

SC_MODULE(scMemory) {
    sc_core::sc_in<bool> Clock;  

public:
    void WaitAccessing(void)
       {    next_trigger(memory_accessed); }
    void ReceivedClock(void);
  sc_event memory_accessed;    // memory access finished
};

SC_HAS_PROCESS(scMemory);
scMemory::scMemory(sc_core::sc_module_name nm, int Size )
: sc_core::sc_module(nm),  mClocks(0), Length(Size), my_state(STANDBY)
{
   SC_METHOD(ReceivedClock);
   sensitive << Clock.pos();
   SC_METHOD(WaitAccessing);
   sensitive << memory_accessed;
   dont_initialize();  // Do not receive clock during initialization
}

the error message changes to

 

Error: (E519) wait() is only allowed in SC_THREADs and SC_CTHREADs:

in SC_METHODs use next_trigger() instead

if I change the code to

   SC_THREAD(WaitAccessing);

    void WaitAccessing(void)
       {    wait(memory_accessed); }

I surely do something wrong, but surely the diagnostic messages are not on the top, too.

 

Share this post


Link to post
Share on other sites

Most likely you are calling WaitAccessing from somewhere else, not shown in your code sample.  Just set a breakpoint on error and check call stack.

Also, why do you put  SC_HAS_PROCESS to global namespace?

Share this post


Link to post
Share on other sites

Well, the full code of the member function calling WaitAccessing() is

    byte_t
  getByte(scCore* FromCore, SC_ADDRESS_TYPE  Address){ 
       AccessMemory(FromCore, scMemoryRead, Address, 1);  // Request a content
       WaitAccessing();
       return storage->contents[Address];
    }

Of course I set a breakpoint in the member function above (this is the only place where WaitAccessing() is called from)  and it is exactly called from this place. Concerning your namespace question:

I simple followed the example in SCFTGU, page 55

//FILE: module_name.cpp
SC_HAS_PROCESS(module_name);
module_name::module_name(
sc_module_name instname[, other_args…])
: sc_module(instname)

Is it wrong (or can be wrong)?

Share this post


Link to post
Share on other sites

Can you give a complete small reproducer of your problem? Otherwise I can just guess. Who calls getByte? Some sc_thread?

About SC_HAS_PROCESS - it should be fine unless you defne couple of modules in same translation unit. 

Share this post


Link to post
Share on other sites

Re. SC_HAS_PROCESS

That would appear to be an error in the text. The best place to put SC_HAS_PROCESS is inside the constructor as the first line in the body of the constructor. It is syntactically legal there and the only things using it are the SC_METHOD, SC_THREAD, and SC_CTHREAD macros.

Share this post


Link to post
Share on other sites

Re. the error

SC_METHOD is called repeatedly (every time an element of the static sensitivity list triggers); however, SC_METHOD processes must execute in single delta cycle (zero time). Blocking methods such as wait() is illegal there. Methods such as sc_fifo::write() call wait() and are therefore also illegal. To wait 10 ns, you can do something like this:

#include <systemc>
#include <iostream>
struct Ex1 : sc_core::sc_module
{
  Ex1( void )
  {
    SC_HAS_PROCESS(Ex1);
    SC_METHOD(Method10ns);
  }
  void Method10ns( void )
  {
    next_trigger( 10, SC_NS );
    std::cout << "Now " << sc_core::sc_time_stamp() << sdt::endl;
  }
};

SC_THREAD is called only one, and therefore normally contains an infinite loop to properly model hardware. Thus the above is coded more simply as:

#include <systemc>
#include <iostream>
struct Ex1 : sc_core::sc_module
{
  Ex1( void )
  {
    SC_HAS_PROCESS(Ex1);
    SC_THREAD(Thread10ns);
  }
  void Thread10ns( void )
  {
    for(;;) {
      std::cout << "Now " << sc_core::sc_time_stamp() << sdt::endl;
      wait( 10, SC_NS );

    }
  }
};

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×