Jump to content

sc_fifo reset

Ramon Fried

Recommended Posts

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"

#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();
  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

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.

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.

  • Create New...