Last change
on this file since 54 was
1,
checked in by buchmann, 17 years ago
|
Initial import from CVS repository
|
File size:
2.2 KB
|
Line | |
---|
1 | #include <systemc.h> |
---|
2 | |
---|
3 | #define ASSERT(x) \ |
---|
4 | { \ |
---|
5 | if (!(x)) \ |
---|
6 | { \ |
---|
7 | cerr << "ASSERT : " #x "\n"; \ |
---|
8 | exit (1); \ |
---|
9 | } \ |
---|
10 | } |
---|
11 | |
---|
12 | using namespace std; |
---|
13 | |
---|
14 | struct inner1 : sc_module { |
---|
15 | sc_in_clk clk; |
---|
16 | sc_in <int> i1; |
---|
17 | sc_out<int> o1; |
---|
18 | |
---|
19 | void mealy () |
---|
20 | { |
---|
21 | cerr << "executing 'mealy' function at cycle #" << sc_simulation_time () |
---|
22 | << endl; |
---|
23 | o1 = i1.read() + 3; |
---|
24 | } |
---|
25 | |
---|
26 | SC_HAS_PROCESS(inner1); |
---|
27 | inner1 (sc_module_name) |
---|
28 | { |
---|
29 | SC_METHOD(mealy); |
---|
30 | sensitive << clk.neg() << i1; |
---|
31 | } |
---|
32 | }; |
---|
33 | |
---|
34 | struct inner2 : sc_module { |
---|
35 | sc_in_clk clk; |
---|
36 | sc_in <bool> resetn; |
---|
37 | sc_in <int> i1; |
---|
38 | sc_out<int> o1; |
---|
39 | sc_signal<int> reg1; |
---|
40 | |
---|
41 | void transition () |
---|
42 | { |
---|
43 | //reg1 = 0; |
---|
44 | if (resetn.read()) |
---|
45 | reg1 = i1.read(); |
---|
46 | else |
---|
47 | reg1 = 0; |
---|
48 | } |
---|
49 | void generation () |
---|
50 | { |
---|
51 | o1 = reg1.read(); |
---|
52 | } |
---|
53 | |
---|
54 | SC_HAS_PROCESS(inner2); |
---|
55 | inner2 (sc_module_name) |
---|
56 | { |
---|
57 | SC_METHOD(transition); |
---|
58 | sensitive << clk.pos(); |
---|
59 | SC_METHOD(generation); |
---|
60 | sensitive << clk.neg(); |
---|
61 | } |
---|
62 | }; |
---|
63 | |
---|
64 | struct test : sc_module { |
---|
65 | sc_in_clk clk; |
---|
66 | sc_in<bool> resetn; |
---|
67 | |
---|
68 | sc_signal<int> sig; |
---|
69 | |
---|
70 | inner1 comp1; |
---|
71 | inner2 comp2; |
---|
72 | |
---|
73 | sc_in <int> i1; |
---|
74 | sc_out<int> o1; |
---|
75 | |
---|
76 | SC_HAS_PROCESS(test); |
---|
77 | test (sc_module_name n) : sc_module (n), |
---|
78 | comp1("comp1"), |
---|
79 | comp2("comp2"), |
---|
80 | clk("clk") |
---|
81 | { |
---|
82 | comp1.clk (clk); |
---|
83 | comp1.i1 (i1); |
---|
84 | comp1.o1 (sig); |
---|
85 | comp2.clk (clk); |
---|
86 | comp2.resetn(resetn); |
---|
87 | comp2.i1 (sig); |
---|
88 | comp2.o1 (o1); |
---|
89 | }; |
---|
90 | }; |
---|
91 | |
---|
92 | int sc_main (int argc, char *argv[]) |
---|
93 | { |
---|
94 | sc_clock signal_clk("my_clock",1, 0.5); |
---|
95 | sc_signal<bool> resetn("resetn"); |
---|
96 | sc_signal<int > s01("s01"); |
---|
97 | sc_signal<int > s02("s02"); |
---|
98 | |
---|
99 | test test1("test1"); |
---|
100 | test1.clk (signal_clk); |
---|
101 | test1.resetn (resetn); |
---|
102 | test1.i1 (s01); |
---|
103 | test1.o1 (s02); |
---|
104 | |
---|
105 | // Init & run |
---|
106 | sc_start (0); |
---|
107 | |
---|
108 | s01 = 1; |
---|
109 | resetn = false; |
---|
110 | sc_start (4); |
---|
111 | resetn = true; |
---|
112 | sc_start (1); |
---|
113 | ASSERT(s02.read() == 4); |
---|
114 | sc_start (2); |
---|
115 | ASSERT(s02.read() == 4); |
---|
116 | s01 = 10; |
---|
117 | sc_start (20); |
---|
118 | ASSERT(s02.read() == 13); |
---|
119 | |
---|
120 | return EXIT_SUCCESS; |
---|
121 | } |
---|
122 | |
---|
123 | #undef sc_inout |
---|
Note: See
TracBrowser
for help on using the repository browser.