marcorondinini Posted November 7, 2012 Report Share Posted November 7, 2012 Hello, I am working on a project in which I have a SC_MODULE running a SC_METHOD that is sensitive to clock.pos(). I also have an untime SC_MODULE running a SC_THREAD which monitors multiple sc_fifos through which it reads data from different entities (in my case I have several robots sending packets to this modules using sc_fifos). Since I have multiple sc_fifos (10 in my case), I use this code to trigger the packet processing: while(1){ for(int i=0;i<10;i++){ if(fifo_in.nb_read(packet)){ cout << "Packet received from Robot " << i << "\n"; // processing } } } I noticed that if I do so, the SC_MODULE that is sensitive to the clock is never triggered. My guess is that with this infinite loop, the thread never suspends and time doesn't pass. How can I have a SC_THREAD to monitor several sc_fifos and at the same time having other clock-sensitive SC_MODULES evolve? Thank you Quote Link to comment Share on other sites More sharing options...
apfitch Posted November 7, 2012 Report Share Posted November 7, 2012 Hi, one simple way would be to put a delay in that loop - even a delta delay should work, e.g. while(1){ for(int i=0;i<10;i++){ if(fifo_in[i].nb_read(packet)){ cout << "Packet received from Robot " << i << "\n"; wait(SC_ZERO_TIME); // let other processes run // processing } } } Another solution might be to use the TLM1 tlm_fifo - that has a peek interface, and also an ok_to_get() which notifies an event when something is in the fifo. You could wait on the result of the OR of all the ok_to_get() calls. regards Alan Quote Link to comment Share on other sites More sharing options...
David Black Posted November 7, 2012 Report Share Posted November 7, 2012 You are correct in the assessment that you have an infinite loop. You need some form of wait. wait(SC_ZERO_TIME) is not the best solution though. How about waiting on the sc_fifo::data_written_event()? Also, with the new version of SystemC (2.3.0), you can even create an sc_event_or_list so you can do the following (untested): sc_event_or_list fifo_written_event; for(int i=0; i!=10; ++i) { fifo_written_event |=fifo.data_written_event(); } while(1){ wait(fifo_written_event); for(int i=0; i!=10; ++i) { // Process all received if(fifo_in.nb_read(packet)){ cout << "Packet received from Robot " << i << "\n"; // processing } } 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.