Jump to content
marcorondinini

Timed and Untimed modules coexistence

Recommended Posts

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

}

}

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

×