Last change
on this file since 19 was
1,
checked in by buchmann, 17 years ago
|
Initial import from CVS repository
|
File size:
2.7 KB
|
Line | |
---|
1 | #include <systemc.h> |
---|
2 | #include <signal.h> |
---|
3 | #include "chrono.h" |
---|
4 | |
---|
5 | using namespace std; |
---|
6 | |
---|
7 | struct A : sc_module { |
---|
8 | sc_in_clk clk; |
---|
9 | sc_out<bool> o1; |
---|
10 | |
---|
11 | void eval () { |
---|
12 | o1 = (rand()%2) == 0; |
---|
13 | } |
---|
14 | |
---|
15 | SC_CTOR (A) : clk ("clk"), o1("o1") { |
---|
16 | SC_METHOD(eval); |
---|
17 | sensitive << clk.neg(); |
---|
18 | #ifdef SYSTEMCASS_SPECIFIC |
---|
19 | // s1(); |
---|
20 | #endif |
---|
21 | }; |
---|
22 | }; |
---|
23 | |
---|
24 | struct B : sc_module { |
---|
25 | sc_in_clk clk; |
---|
26 | sc_in<bool> i1; |
---|
27 | sc_in<bool> i2; |
---|
28 | sc_out<bool> o1; |
---|
29 | sc_out<bool> o2; |
---|
30 | |
---|
31 | void eval1 () { |
---|
32 | o1 = ~i1; |
---|
33 | } |
---|
34 | void eval2 () { |
---|
35 | o2 = ~i2; |
---|
36 | } |
---|
37 | |
---|
38 | SC_CTOR (B) : clk ("clk"), i1 ("i1"), o1("o1"), i2 ("i2"), o2 ("o2") { |
---|
39 | SC_METHOD(eval1); |
---|
40 | sensitive << clk.neg(); |
---|
41 | sensitive << i1; |
---|
42 | #ifdef SYSTEMCASS_SPECIFIC |
---|
43 | o1(i1); |
---|
44 | #endif |
---|
45 | SC_METHOD(eval2); |
---|
46 | sensitive << clk.neg(); |
---|
47 | sensitive << i2; |
---|
48 | #ifdef SYSTEMCASS_SPECIFIC |
---|
49 | o2(i2); |
---|
50 | #endif |
---|
51 | }; |
---|
52 | }; |
---|
53 | |
---|
54 | struct C : sc_module { |
---|
55 | sc_in_clk clk; |
---|
56 | sc_in<bool> i1; |
---|
57 | sc_in<bool> i2; |
---|
58 | sc_out<bool> o1; |
---|
59 | |
---|
60 | void eval1 () { |
---|
61 | o1 = i1 ^ i2; |
---|
62 | } |
---|
63 | |
---|
64 | SC_CTOR (C) : clk ("clk"), i1 ("i1"), o1("o1"), i2 ("i2") { |
---|
65 | SC_METHOD(eval1); |
---|
66 | sensitive << clk.neg(); |
---|
67 | sensitive << i1 << i2; |
---|
68 | #ifdef SYSTEMCASS_SPECIFIC |
---|
69 | o1(i1); |
---|
70 | o1(i2); |
---|
71 | #endif |
---|
72 | }; |
---|
73 | }; |
---|
74 | |
---|
75 | struct D : sc_module { |
---|
76 | sc_in_clk clk; |
---|
77 | sc_out<bool> o1; |
---|
78 | |
---|
79 | void eval () { |
---|
80 | o1 = (rand()%2) == 0; |
---|
81 | } |
---|
82 | |
---|
83 | SC_CTOR (D) : clk ("clk"), o1("o1") { |
---|
84 | SC_METHOD(eval); |
---|
85 | sensitive << clk.neg(); |
---|
86 | #ifdef SYSTEMCASS_SPECIFIC |
---|
87 | // s1(); |
---|
88 | #endif |
---|
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> s1("s1"),s2("s2"),s3("s3"),s4("s4"),s5("s5"); |
---|
96 | |
---|
97 | A a("a"); |
---|
98 | B b("b"); |
---|
99 | C c("c"); |
---|
100 | D d("d"); |
---|
101 | |
---|
102 | a.clk (signal_clk); |
---|
103 | b.clk (signal_clk); |
---|
104 | c.clk (signal_clk); |
---|
105 | d.clk (signal_clk); |
---|
106 | |
---|
107 | a.o1 (s1); |
---|
108 | b.i1 (s1); |
---|
109 | |
---|
110 | d.o1 (s2); |
---|
111 | c.i2 (s2); |
---|
112 | |
---|
113 | b.o1 (s3); |
---|
114 | c.i1 (s3); |
---|
115 | |
---|
116 | c.o1 (s4); |
---|
117 | b.i2 (s4); |
---|
118 | |
---|
119 | b.o2 (s5); |
---|
120 | |
---|
121 | // Init & run |
---|
122 | sc_initialize (); |
---|
123 | |
---|
124 | if (argc == 1) |
---|
125 | { |
---|
126 | cout << "Usage :\n" << argv[0] << " [#cycles]\n"; |
---|
127 | return EXIT_SUCCESS; |
---|
128 | } |
---|
129 | |
---|
130 | chrono_t chrono; |
---|
131 | chrono.start (); |
---|
132 | |
---|
133 | sc_start (atoi(argv[1])); |
---|
134 | |
---|
135 | chrono.stop (); |
---|
136 | unsigned int t = chrono; |
---|
137 | cout << "Time elapsed (sec) : " << t << endl; |
---|
138 | cout << "Cycles done : " << sc_simulation_time () << endl; |
---|
139 | cout << "Performance : " << sc_simulation_time () / t << endl; |
---|
140 | printf("\nPress <RETURN> to exit simulation."); |
---|
141 | char buf_ret[2]; |
---|
142 | cin.getline(buf_ret,1); |
---|
143 | return EXIT_SUCCESS; |
---|
144 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.