Jump to content
yatung

How to get/use the written/read event of sc_fifo?

Recommended Posts

Hello Everyone,

I am a beginner at systemc.

I am interested in sc_fifo channel and investigated the OSCI simulator source code.

I found sc_fifo has a member function named "data_written_event" and its prototype is like below:

virtual const sc_event& data_written_event() const;

I want to get a callback/notify when a specific sc_fifo channel is written or read. My solution is:

- Preface

I used the sc_get_top_level_objects() and get_child_objects() to iterate out all the sc_object.

(This is the way I get the sc_fifo object)

- Make a callback/sensitive by user code

1. Try to get the written/read event data member of sc_fifo

2. Use the add_static() member function of sc_event to register a written/read event callback

for this sc_fifo

Is the solution above workable?

----------------------------------------------

- My Test Result

1. Try to get the written/read event data member of sc_fifo

==> Because of the "operator=" is overwritten as private:

sc_fifo& operator = ( const sc_fifo<T>& );

I canNOT get the event in user code.

ex: sc_event e; e = sc_fifo_obj->data_written_event(); //<-- Error! Of course.

2. add_static() is s private member function of sc_event class and I can neither use it in

user code.

Can you experts guide me how to do it or give me any hint?

Appreciate your feedback.

by yaTung

Share this post


Link to post
Share on other sites

I am interested in sc_fifo channel and investigated the OSCI simulator source code.

First of all, you should refer to the standardized API in the IEEE Std. 1666-2011, instead of looking at the source code of the proof-of-concept implementation. This way you make sure that your solution works in other standards-compliant implementations as well.

I want to get a callback/notify when a specific sc_fifo channel is written or read. My solution is:

- Preface

I used the sc_get_top_level_objects() and get_child_objects() to iterate out all the sc_object.

(This is the way I get the sc_fifo object)

I assume there are specific reasons, why you can't use a proper sc_port (e.g. sc_fifo_in/out), connected to the particular sc_fifo instance of interest? Looping through the design hierarchy to manipulate the model structure is a rather special case in SystemC.

- Make a callback/sensitive by user code

1. Try to get the written/read event data member of sc_fifo

2. Use the add_static() member function of sc_event to register a written/read event callback

for this sc_fifo

Is the solution above workable?

No. As you have seen in your tests, the add_static function is private and non-standard. It is an implementation artefact. Instead, you should spawn a process, which is then sensitive to the events. Processes are the natural way to specify event-triggered functionality in SystemC.

1. Try to get the written/read event data member of sc_fifo

==> Because of the "operator=" is overwritten as private:

sc_fifo& operator = ( const sc_fifo<T>& );

I canNOT get the event in user code.

ex: sc_event e; e = sc_fifo_obj->data_written_event(); //<-- Error! Of course.

If you need to keep a handle to an event, you can use a C++ reference (or pointer), instead of creating a new event instance. Events have "identity" and can not be copied or assigned. This is the case for many structural elements in SystemC.

sc_event const & ev_ref = sc_fifo_obj->data_written_event();

In the easiest case, you can just create a plain SC_METHOD process, being sensitive to your event. Of course, this requires to wrap the "callback" in a module instance. To make sure your FIFO has been created already, you should create this process in the end_of_elaboration callback of the module:

SC_MODULE( fifo_callback_handler )
{
 // ...
 void callback_process();
 void end_of_elaboration()
 {
// ... find fifo object
SC_METHOD(callback_process);
  sensitive << sc_fifo_obj->data_written_event();
  dont_initialize(); // do not run at start of simulation
 }
};

You can also use dynamic processes (sc_spawn, sc_bind) to create processes dynamically during the simulation. See 1666-2011, Section 5.5.

Greetings from Oldenburg,

Philipp

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

×