Jump to content

Doubts regarding sc_fifo


Recommended Posts

Hello,

I am learning sc_fifo and I cant find anything on below points. it will be helpful if someone can answer or at least point me where i can get more info.
What i have done:
1. I have a sc_fifo shared between producer and consumer
the consumer is declared sensitive to sc_fifo data_written_event by using 

SC_METHOD(consumer_read_shared_sc_fifo)
sensitive << shared_sc_fifo.data_written_event()

2. I write 3 entries to shared_sc_fifo within same function producer_write_shared_sc_fifo as follows

shared_sc_fifo.write(msg1)
shared_sc_fifo.write(msg2)

where msg1 and msg 2 are the two messages of struct Message I have defined

What noticing is that the function producer_write_shared_sc_fifo returns successfully implying that data is now in shared_sc_fifo

My Questions/ Doubts are

1. I  am expecting that consumer_read_shared_sc_fifo will be called twice but it is called once even though the available count (value returned by num_available() method) is 2. 
I think this is because i am writing in the same function. Am I right?

2. I am thinking of calling nb_write() instead of write() as I dont want to block if there is insufficient space . However, I am not sure the behaviour of caller i.e., producer_write_share_sc_fifo() in case space is not  available. i know it will return false. What I am not sure is, what should be the behaviour in case nb_write returns false. Do i have to try this nb_write again?

3. When does the delta cycle end for 
write 
nb_write
 

Regards

Moreshwar

Edited by Moreshwar Salpekar
proper labeling and numbering
Link to comment
Share on other sites

2 hours ago, Moreshwar Salpekar said:

Now I  am expecting that consumer_read_shared_sc_fifo will be called twice but it is called once even though the available count (value returned by num_available() method) is 2. 
I think this is because i am writing in the same function.

Yes, you are writing 2 elements into the fifo in the same evaluation phase. This results in a single notification of the data wrtitten event.

2 hours ago, Moreshwar Salpekar said:

I am thinking of calling nb_write() instead of write() as I dont want to block if there is insufficient space . However, I am not sure the behaviour of caller i.e., producer_write_share_sc_fifo() in case space is not  available. i know it will return false. What I am not sure is, what should be the behaviour in case nb_write returns false. Do i have to try this nb_write again?

The returned value tells you if the write was succesfull or not. How to react on that depends on your model. At least you have to try it again at a later time (e.g. when the fifo has room for the new element).

 

2 hours ago, Moreshwar Salpekar said:

3. When does the delta cycle end for 
write 
nb_write

The delta cycle does not change. But I guess you mean when does the function return. For this you can consult the LRM. But in short: nb_write returns immediately, it is non-blockin (or nb). Therefore you can use it in an SC_METHOD. write is blocking which means internally wait is called and it returns once the element has been placed in the fifo. Therefor write can only be used in SC_THREAD since the call to wait() is not allowed in SC_METHOD.

Link to comment
Share on other sites

Thanks for the clarifications. I will try to check your clarifications in code. I  may have some questions after reading the specification with respect to your clarification and my trials. I just wanted a reconfirmation for the following

If producer_write_share_sc_fifo() writes to one sc_fifo, then there is one notification irrespective of number of entries written to that sc_fifo

If producer_write_share_sc_fifo() writes to more than one sc_fifo, then there will be one notification per sc_fifo assuming there is one method per sc_fifo that is sensitive to the data_written_event() of the sc_fifo. To be clearer with an example:

If have 3 sc_fifos: sc_fifo1, sc_fifo2 and sc_fifo3

method1 is sensitive to data_written_event of sc_fifo1

method2 is sensitive to data_written_event of sc_fifo2

method3 is sensitive to data_written_event of sc_fifo3

producer_write_share_sc_fifo() writes multiple messages to sc_fifo1, sc_fifo2 and sc_fifo3.  I think I can expect each of method1, method2 and method3 to be called once at least.

Link to comment
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.

 Share

×
×
  • Create New...