test01.cpp revision 12855:588919e0e4aa
1#include "systemc.h" 2 3SC_MODULE(READ_LEAF) 4{ 5 SC_CTOR(READ_LEAF) 6 { 7 SC_METHOD(delta); 8 sensitive << in; 9 } 10 void delta() 11 { 12 cout << "READ_LEAF: change " << (int)in->read() << endl; 13 } 14 sc_in<sc_uint<8> > in; 15}; 16 17SC_MODULE(WRITE_LEAF) 18{ 19 SC_CTOR(WRITE_LEAF) : out("out"), clk("clk") 20 { 21 my_export(out); 22 SC_METHOD(sync) 23 sensitive << clk.pos(); 24 } 25 void sync() 26 { 27 out = out.read() + 1; 28 } 29 sc_signal<sc_uint<8> > out; 30 sc_export<sc_signal_in_if<sc_uint<8> > > my_export; 31 sc_in_clk clk; 32}; 33 34SC_MODULE(MIDDLE) 35{ 36 SC_CTOR(MIDDLE) : reader("reader"), writer("writer") 37 { 38 writer.clk(clk); // Bind clk going down the module hierarchy. 39 my_port(writer.my_export); // Bind my_port coming up the module hierarchy. 40 reader.in(my_port); // Bind my_port going down the module hierarchy. 41 } 42 sc_in_clk clk; 43 sc_export<sc_signal_in_if<sc_uint<8> > > my_port; 44 READ_LEAF reader; 45 WRITE_LEAF writer; 46}; 47 48SC_MODULE(TOP) 49{ 50 SC_CTOR(TOP) : down("down") 51 { 52 down.clk(clk); // Bind clk going down the module hierarchy. 53 in(down.my_port); // Bind in coming up the module hierarchy. 54 SC_METHOD(delta); 55 sensitive << in; 56 } 57 void delta() 58 { 59 cout << "TOP: change " << (int)in.read() << endl; 60 } 61 sc_in_clk clk; 62 sc_in<sc_uint<8> > in; 63 MIDDLE down; 64}; 65 66int sc_main(int argc, char* arg[]) 67{ 68 sc_clock clock; 69 TOP top("top"); 70 top.clk(clock); 71 72 sc_start(10, SC_NS); 73 return 0; 74} 75 76