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)
20    {
21		SC_METHOD(sync)
22		sensitive << clk.pos();
23    }
24	void sync()
25	{
26		out = out.read() + 1;
27	}
28    sc_signal<sc_uint<8> > out;
29	sc_in_clk			   clk;
30};
31
32SC_MODULE(MIDDLE)
33{
34    SC_CTOR(MIDDLE) : reader("reader"), writer("writer")
35    {
36		writer.clk(clk);     // Bind clk going down the module hierarchy.
37        reader.in(my_port);  // Bind my_port going down the module hierarchy.
38        my_port(writer.out); // Bind my_port coming up the module hierarchy.
39    }
40	sc_in_clk			   clk;
41    sc_in<sc_uint<8> >     my_port;
42	READ_LEAF			   reader;
43	WRITE_LEAF			   writer;
44};
45
46SC_MODULE(TOP)
47{
48    SC_CTOR(TOP) : down("down")
49    {
50		down.clk(clk);    // Bind clk going down the module hierarchy.
51        in(down.my_port); // Bind in coming up the module hierarchy.
52        SC_METHOD(delta);
53        sensitive << in;
54    }
55    void delta()
56    {
57        cout << "TOP: change " << (int)in.read() << endl;
58    }
59	sc_in_clk			   clk;
60    sc_in<sc_uint<8> >     in;
61	MIDDLE     			   down;
62};
63
64int sc_main(int argc, char* arg[])
65{
66    sc_clock clock;
67    TOP top("top");
68	top.clk(clock);
69
70    sc_start(10, SC_NS);
71    return 0;
72}
73
74