Jump to content
katang

How to specify 'sensitive' using the alternative style in normal constructor?

Recommended Posts

I am using the alternative style offered in book SCFTGU. In the .cpp file, I am using a normal contructor.

The SC_HAS_PROCESS(MyObj);

compiles OK,   the

  SC_METHOD(MySub);

ditto, but next to it
        sensitive << in;

is refused with error message 'invalid static cast'. I guess that somehow the SC_CTOR() call is missing.

What is the correct syntax?

 

Share this post


Link to post
Share on other sites

Here goes the code:

#ifndef scMWE_h
#define scMWE_h
#include <systemc>
#include <iostream>

SC_MODULE(scMWE) {
    scMWE(sc_core::sc_module_name nm);
    void WritePseudo(int A );
    sc_core::sc_fifo_in<int> in[4];
};
#endif

 

#include "scMWE.h"

SC_HAS_PROCESS(scMWE);
scMWE::scMWE(sc_core::sc_module_name nm)
: sc_core::sc_module(nm)
{
     SC_METHOD(WritePseudo);
//        sensitive << in;
}

void scMWE::
WritePseudo(int A)
{
    std::cout << "MWE:A" <<  A << std::endl;
}

 

Share this post


Link to post
Share on other sites

Third point: You're using a C-style array of ports, which won't work either.
You should use an sc_vector (to name your ports) and use a loop to add the sensitivity (if you want to be sensitive to all ports in the vector):
 

// change member 
sc_core::sc_vector< sc_core::sc_fifo_in<int> > in;

// constructor

scMWE::scMWE(sc_core::sc_module_name nm)
  : sc_core::sc_module(nm)
  , in("in", 4) // initialize vector 
{
     SC_METHOD(WritePseudo);
       for( auto& in_x : in ) // or a plain loop over the elements, if you don't have C++11
          sensitive << in_x.data_written();
}


/Philipp

Share this post


Link to post
Share on other sites

Hm, I am starting to be proud of my ability to hide so many mistakes in a short MWE. :)

What is the reason that the compiler claims "invalid static_cast" rather than wrong signature?

(the rest of mistakes is just a consequence of the first unfixed one)

 

Share this post


Link to post
Share on other sites
20 hours ago, katang said:

What is the reason that the compiler claims "invalid static_cast" rather than wrong signature?

Hard to tell without details about what exact cast (i.e. between which types) is invalid.
My guess would be the use of an array instead of the individual ports.

/Philipp

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

×