Jump to content

sc_fifo reset


Recommended Posts

I'm wondering why there's no standard method to clear/reset a fifo.
Doing so activly, by looping and running:

while (nb_read(t))
 ;

has the unplesent effect of sending data_read_event().

What's the process of suggesting an addtional functionality to the spec ?

Link to comment
Share on other sites

You only get a single read event.

If you need more, simply implement your own fifo by derivation or composition. You might also consider the tlm_fifo, which has slightly more functionality but still no reset per se.

You could also disable the readers for one delta cycle if you know their identities. Perhaps override data_read_event to capture that information:

// File: my_fifo.h
#pragma once

#if __cplusplus < 201402L // Might allow C++11
  #error "Requires C++14 or better"
#endif

#include <systemc>
#include <forward_list>
struct my_fifo : sc_core::sc_fifo
{
  my_fifo( int size = 16 ) : sc_fifo{ size } { sc_assert( size >= 0 ); }
  const sc_core::sc_event& data_read_event() override {
    observer.push_back( sc_core::sc_get_current_process_handle() );
    return sc_core::data_read_event();
  }
  void reset() { //< blocking
    // Disable observers
    for( auto& observer : observers ) observer.disable();
    // Empty the fifo
    while( nb_read() );
    // Exit this delta cycle
    wait( SC_ZERO_TIME );
    // Reenable observers
    for( auto& observer : observers ) observer.enable();
  }
private:
  std::forward_list<sc_core::sc_process_handle> observers{};
};

Above is untested, and you might want to add a my_fifo_if.h to support the reset functionality via a port. YMMV

Link to comment
Share on other sites

Reflection: It might be better to store the observers in a std::unordered_set rather than the std::forward_list. This avoids the list getting duplicate entries and thus getting out of control (size). This would be the case if code dynamically waited on the event.

 

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...