summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/communication/sc_export/test01/test01.cpp
blob: 9b23884217c44c373230269b7a1589d1bf80fa80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "systemc.h"

SC_MODULE(READ_LEAF) 
{
    SC_CTOR(READ_LEAF) 
    {
        SC_METHOD(delta);
        sensitive << in;
    }
    void delta()
    {
        cout << "READ_LEAF: change " << (int)in->read() << endl;
    }
    sc_in<sc_uint<8> >     in;
};

SC_MODULE(WRITE_LEAF) 
{
    SC_CTOR(WRITE_LEAF) : out("out"), clk("clk")
    {
                my_export(out);
		SC_METHOD(sync)
		sensitive << clk.pos();
    }
	void sync()
	{
		out = out.read() + 1;
	}
    sc_signal<sc_uint<8> > out;
    sc_export<sc_signal_in_if<sc_uint<8> > >     my_export;
	sc_in_clk			   clk;
};

SC_MODULE(MIDDLE) 
{
    SC_CTOR(MIDDLE) : reader("reader"), writer("writer")
    {
		writer.clk(clk);     // Bind clk going down the module hierarchy.
        my_port(writer.my_export); // Bind my_port coming up the module hierarchy.
        reader.in(my_port);  // Bind my_port going down the module hierarchy.
    }
	sc_in_clk			   clk;
    sc_export<sc_signal_in_if<sc_uint<8> > >     my_port;
	READ_LEAF			   reader;
	WRITE_LEAF			   writer;
};

SC_MODULE(TOP) 
{
    SC_CTOR(TOP) : down("down")
    {
		down.clk(clk);    // Bind clk going down the module hierarchy.
        in(down.my_port); // Bind in coming up the module hierarchy.
        SC_METHOD(delta);
        sensitive << in;
    }
    void delta()
    {
        cout << "TOP: change " << (int)in.read() << endl;
    }
	sc_in_clk			   clk;
    sc_in<sc_uint<8> >     in;
	MIDDLE     			   down;
};

int sc_main(int argc, char* arg[])
{
    sc_clock clock;
    TOP top("top");
	top.clk(clock);

    sc_start(10, SC_NS);
    return 0;
}