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

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