Jump to content

How to Implement a Digital Delay Using a FIFO IN SystemC


anna

Recommended Posts

hi Ameya , 

thanks for your reply,

i want to synchronize many incoming delayed data with fifo ( each delayed data with one fifo) , so  i need to implement a constant delay for each data with a fifo )

my problem is how to introduce the delay in fifo designing.

this is the code of the fifo bloc:


#include "systemc.h"
#include <iostream>
#include <fstream>

#include <stdlib.h>

template<class T >

SC_MODULE(fifo)
{


sc_in<bool> clk;
sc_in<T> data_in;
sc_in<bool> valid_in;
sc_in<bool> ready_in;

sc_out<bool> ready_out;
sc_out<T> data_out;
sc_out<bool> valid_out;
 
unsigned  _size, _first, _items;
T* _data;
//int sampling_rate;


void initialize(){

assert (_size > 0);
_first = _items = 0;
ready_out.initialize(true);
valid_out.initialize(false);}


void hw_fifo_method()
{
_data = new T [_size];
if (valid_in.read() && ready_out.read())
{
// store new data item into fifo
_data[(_first + _items) % _size] = data_in;
++_items;
}

if (ready_in.read() && valid_out.read())
{
// discard data item that was just read from fifo
-- _items;
_first = (_first + 1) % _size ;
}

//Update all output signals.
//Valid on next delta-cycle
ready_out = (_items < _size);
valid_out = (_items >0);
data_out = _data[_first];

}


fifo(sc_module_name name, unsigned size){

SC_HAS_PROCESS(fifo);
SC_METHOD(hw_fifo_method);

sensitive << clk.pos();}
}; 

 

 

 

Link to comment
Share on other sites

hi  @AmeyaVS  , 

thanks for your reply,

i want to synchronize many incoming delayed data with fifo ( each delayed data with one fifo) , so  i need to implement a constant delay for each data with a fifo )

my problem is how to introduce the delay in fifo designing.

this is the code of the fifo bloc:


#include "systemc.h"
#include <iostream>
#include <fstream>

#include <stdlib.h>

template<class T >

SC_MODULE(fifo)
{


sc_in<bool> clk;
sc_in<T> data_in;
sc_in<bool> valid_in;
sc_in<bool> ready_in;

sc_out<bool> ready_out;
sc_out<T> data_out;
sc_out<bool> valid_out;
 
unsigned  _size, _first, _items;
T* _data;
//int sampling_rate;


void initialize(){

assert (_size > 0);
_first = _items = 0;
ready_out.initialize(true);
valid_out.initialize(false);}


void hw_fifo_method()
{
_data = new T [_size];
if (valid_in.read() && ready_out.read())
{
// store new data item into fifo
_data[(_first + _items) % _size] = data_in;
++_items;
}

if (ready_in.read() && valid_out.read())
{
// discard data item that was just read from fifo
-- _items;
_first = (_first + 1) % _size ;
}

//Update all output signals.
//Valid on next delta-cycle
ready_out = (_items < _size);
valid_out = (_items >0);
data_out = _data[_first];

}


fifo(sc_module_name name, unsigned size){

SC_HAS_PROCESS(fifo);
SC_METHOD(hw_fifo_method);

sensitive << clk.pos();}
}; 

 

 

 

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.

×
×
  • Create New...