ElliottCB Posted January 25, 2013 Report Share Posted January 25, 2013 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. Quote Link to comment Share on other sites More sharing options...
apfitch Posted January 26, 2013 Report Share Posted January 26, 2013 What kind of port are you using? Alan Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted January 27, 2013 Report Share Posted January 27, 2013 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 maehne, apfitch and DS1701 3 Quote Link to comment Share on other sites More sharing options...
ElliottCB Posted January 28, 2013 Author Report Share Posted January 28, 2013 Philipp, This is 100% perfect. Thank you so much. Elliott Quote Link to comment Share on other sites More sharing options...
apfitch Posted January 28, 2013 Report Share Posted January 28, 2013 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 maehne 1 Quote Link to comment Share on other sites More sharing options...
pablomtz Posted May 16, 2013 Report Share Posted May 16, 2013 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 Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted May 16, 2013 Report Share Posted May 16, 2013 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 pablomtz 1 Quote Link to comment Share on other sites More sharing options...
pablomtz Posted May 16, 2013 Report Share Posted May 16, 2013 Thank you Philipp! Its woking now! Pablo Quote Link to comment Share on other sites More sharing options...
DS1701 Posted December 11, 2018 Report Share Posted December 11, 2018 Thanks @Philipp A Hartmann How to use sc_vector with pointer? sc_vector< sc_in< int> > *in_vec; Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted December 11, 2018 Report Share Posted December 11, 2018 3 hours ago, TRANG said: How to use sc_vector with pointer? sc_vector< sc_in< int> > *in_vec; Why do you want to do this? Quote Link to comment Share on other sites More sharing options...
DS1701 Posted December 11, 2018 Report Share Posted December 11, 2018 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. 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.