2011年5月21日 星期六

一個加了Waveform Dump的pipe例子

這個例子是從systemC的例子改過來的

#include "systemc.h"

typedef sc_biguint<8> atom; // Value to be pipe delayed.


//==============================================================================
// dpipe - DELAY PIPELINE FOR AN ARBITRARY CLASS:
//==============================================================================
template
SC_MODULE(dpipe) {
typedef sc_export > in; // To pipe port type.
typedef sc_export > out; // From pipe port type.

SC_CTOR(dpipe)
{
m_in(m_pipe[0]);
m_out(m_pipe[N-1]);

SC_METHOD(rachet);
sensitive << m_clk.pos();
}

void rachet()
{

for ( int i = N-1; i > 0; i-- )
{
m_pipe[i].write(m_pipe[i-1].read());
}
}

sc_in_clk m_clk; // Pipe synchronization.
in m_in; // Input to delay pipe.
out m_out; // Output from delay pipe.
sc_signal m_pipe[N]; // Pipeline stages.
};


// Testbench reader of values from the pipe:

SC_MODULE(Reader)
{
public:
SC_CTOR(Reader)
{
SC_METHOD(extract)

//SC_THREAD(extract);

sensitive << m_clk.pos();
dont_initialize();
}

protected:
void extract()
{
read_out_data = m_from_pipe.read() ;

cout << "Time :" <<
sc_time_stamp().to_double() << ": " << m_from_pipe.read()
<< endl;
}

public:

sc_in_clk m_clk; // Module synchronization.
sc_in reset;
sc_in m_from_pipe; // Output from delay pipe.
sc_signal read_out_data;
};



// Testbench writer of values to the pipe:

SC_MODULE(Writer)
{
SC_CTOR(Writer)
{
SC_METHOD(insert)
sensitive << m_clk.pos();
m_counter = 0;
}

void insert()
{
//wait(2, SC_NS);

m_to_pipe.write(m_counter);
m_counter++;

cout << "Time :" << sc_time_stamp().to_double() <<
" write data => " << m_counter << endl;
}

sc_in_clk m_clk; // Module synchronization.
sc_in reset;
atom m_counter; // Write value.
sc_inout m_to_pipe; // Input for delay pipe.
};

// Main program

int sc_main(int argc, char* argv[])
{
//sc_clock clock(;
sc_signal reset;
sc_signal m_out_data;

sc_clock clock("clock", 3, SC_NS, 0.5, 7, SC_NS, 0);

sc_trace_file *wf = sc_create_vcd_trace_file("sc_cycle");
wf->set_time_unit(100, SC_PS);

sc_trace(wf, clock, "clock");
// sc_trace(wf, reset, "reset");

dpipe delay("pipe");
Reader reader("reader");
Writer writer("writer");

delay.m_clk(clock);

reader.m_clk(clock);
reader.m_from_pipe(delay.m_out);

writer.m_clk(clock);
writer.m_to_pipe(delay.m_in);

sc_trace(wf, reader.read_out_data, "fifo_out_data");
sc_trace(wf, writer.m_counter, "fifo_in_data");

sc_start(30, SC_NS);

sc_close_vcd_trace_file(wf);

return 0;
}

沒有留言: