Jump to content
ElliottCB

Process sensitivity with sc_vector

Recommended Posts

Greetings everyone,

I have a process that is sensitive to an sc_vector (specifically a vector of input ports) and was curious about how to handle the fact that values are maintained on each port in that vector on subsequent iterations of the process. This makes it very difficult to determine which values are actually new when the process is executed. I was hoping there would be a way to clear the value on a port once it had been read, but I could not find anything like this. The closest thing to a solution is to "latch" the value each time the process gets triggered and then compare the latch value with the port value to determine if anything new has arrived.

Is there a better way to do this? Thanks a bunch in advance.

Share this post


Link to post
Share on other sites

Assuming you're using plain signal ports, you can use the event member function to check, whether a specific port has been triggered in the current delta cycle:

sc_vector< sc_in< int> > in_vec;
// ...
SC_METHOD(proc);
 for( unsigned i= 0; i<in_vec.size(); ++i )
sensitive << in_vec[i];
// ...
void proc() {
 for( unsigned i= 0; i<in_vec.size(); ++i )
if( in_vec[i]->event() )
  std::cout << "in_vec[" << i << "] triggered." << std::endl;
}

Greetings from Oldenburg,

Philipp

Share this post


Link to post
Share on other sites

Hi Elliott,

one other thing - it's not clear from your original post what you mean by a new value - if you mean a change in value, then the event() method will tell you a value has changed *assuming* the ports are connected to sc_signal. If you want to detect an event even if the value hasn't changed (for instance if the same value is assigned twice) you can use the sc_buffer channel instead,

regards

Alan

Share this post


Link to post
Share on other sites

Dear Philipp,

 

If I am using a sc_vector for clock inputs. How can I get the difference between pos and neg?

 

Suppose I have the following code:

 

 

 

sc_vector<sc_in_clk > port_vec;   //ports

....

SC_METHOD(do_sth);
for( unsigned i= 0; i<port_vec.size(); ++i ) sensitive << port_vec[i];    // Id like to do sth like this: sensitive << port_vec[i].pos();

...




void Producer::do_sth(void) {


for( unsigned clk_id= 0; clk_id<port_vec.size(); ++clk_id )
   if(port_vec[clk_id]->event())   //or like this: port_vec[clk_id]->pos()
      std::cout << "in_vec[" << clk_id << "] triggered." << std::endl;


}
 

 

 

Regards

Pablo

Share this post


Link to post
Share on other sites

Pablo,
 

SC_METHOD(do_sth);
for( unsigned i= 0; i<port_vec.size(); ++i ) sensitive << port_vec[i];    // Id like to do sth like this: sensitive << port_vec[i].pos();

 
This should just work as is.

 

if(port_vec[clk_id]->event())   //or like this: port_vec[clk_id]->pos()

 

Here you should use the posedge/negedge functions:

if(port_vec[clk_id]->posedge())   //or like this: port_vec[clk_id]->pos()

This is equivalent to:

if( port_vec[clk_id]->event() && port_vec[clk_id]->read() )

 
Greetings from Oldenburg,
  Philipp

Share this post


Link to post
Share on other sites
2 minutes ago, Philipp A Hartmann said:


 

Why do you want to do this?

I think if use pointer, my code faster and save memory .

my project:

///APM.h
class APM: public sc_module
{

public:
    sc_in<bool>     clkAPM;
    sc_in<bool>              *IFA[4];
...
///APM.cpp
APM::APM(sc_module_name name)
        :sc_module(name)
	    // Initializing
        ,clkAPM("clkAPM")
{//{{{ 
    /// Initializing
    std::ostringstream port_name;
    for (unsigned int index = 0; index < 4; index++) {
        port_name.str("");
        port_name << "IFA" << index;
        IFA[index] = new sc_in<bool>(port_name.str().c_str());
        sc_assert(IFA[index] != NULL);
    }
    SC_METHOD(AMethod);
    dont_initialize();
    sensitive << (*IFA)[0];
...

I know this it old style code. So, I want to use sc_vector.

Thanks.

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