1#include "systemc.h" 2 3typedef sc_biguint<121> atom; // Value to be pipe delayed. 4 5//============================================================================== 6// esc_dpipe<T,N> - DELAY PIPELINE FOR AN ARBITRARY CLASS: 7//============================================================================== 8template<class T, int N> 9SC_MODULE(esc_dpipe) { 10 public: 11 typedef sc_export<sc_signal_inout_if<T> > in; // To pipe port type. 12 typedef sc_export<sc_signal_in_if<T> > out; // From pipe port type. 13 14 public: 15 SC_CTOR(esc_dpipe) 16 { 17 m_in(m_pipe[0]); 18 m_out(m_pipe[N-1]); 19 SC_METHOD(rachet); 20 sensitive << m_clk.pos(); 21 } 22 23 protected: 24 void rachet() 25 { 26 for ( int i = N-1; i > 0; i-- ) 27 { 28 m_pipe[i].write(m_pipe[i-1].read()); 29 } 30 } 31 32 public: 33 sc_in_clk m_clk; // Pipe synchronization. 34 in m_in; // Input to delay pipe. 35 out m_out; // Output from delay pipe. 36 37 protected: 38 sc_signal<T> m_pipe[N]; // Pipeline stages. 39}; 40 41 42// Testbench reader of values from the pipe: 43 44SC_MODULE(Reader) 45{ 46 SC_CTOR(Reader) 47 { 48 SC_METHOD(extract) 49 sensitive << m_clk.pos(); 50 dont_initialize(); 51 } 52 53 void extract() 54 { 55 cout << sc_time_stamp() << ": " << m_from_pipe.read() << endl; 56 } 57 58 sc_in_clk m_clk; // Module synchronization. 59 sc_in<atom > m_from_pipe; // Output from delay pipe. 60}; 61 62 63 64// Testbench writer of values to the pipe: 65 66SC_MODULE(Writer) 67{ 68 SC_CTOR(Writer) 69 { 70 SC_METHOD(insert) 71 sensitive << m_clk.pos(); 72 m_counter = 0; 73 } 74 75 void insert() 76 { 77 m_to_pipe.write(m_counter); 78 m_counter++; 79 } 80 81 sc_in_clk m_clk; // Module synchronization. 82 atom m_counter; // Write value. 83 sc_inout<atom > m_to_pipe; // Input for delay pipe. 84}; 85 86// Main program 87 88int sc_main(int argc, char* argv[]) 89{ 90 sc_clock clock; 91 esc_dpipe<atom,4> delay("pipe"); 92 Reader reader("reader"); 93 Writer writer("writer"); 94 95 delay.m_clk(clock); 96 97 reader.m_clk(clock); 98 reader.m_from_pipe(delay.m_out); 99 100 writer.m_clk(clock); 101 writer.m_to_pipe(delay.m_in); 102 103 sc_start(50, SC_NS); 104 105 return 0; 106} 107