source: branches/with_autoconf/test_regression/15092005/system3.cpp

Last change on this file was 1, checked in by buchmann, 19 years ago

Initial import from CVS repository

File size: 2.6 KB
Line 
1#include "systemc.h"
2#include <iostream>
3
4using namespace std;
5
6#define ASSERT(x) \
7 { errnum++; \
8 if (!(x)) \
9 { \
10 cerr << "ASSERT : " #x "\n"; \
11 exit (errnum); \
12 } \
13 }
14
15using namespace std;
16
17struct observer : sc_module
18{
19 sc_in_clk clk;
20
21 sc_in<int> i;
22
23 void f ()
24 {
25#if 0
26 cerr << i.read();
27#endif
28 }
29
30 SC_HAS_PROCESS(observer);
31 observer(sc_module_name) : clk ("clk"),
32 i ("i")
33
34 {
35 SC_METHOD(f);
36 dont_initialize();
37 sensitive << clk.pos();
38#ifdef SYSTEMCASS_SPECIFIC
39#endif
40 }
41};
42
43struct generator : sc_module
44{
45 sc_in_clk clk;
46
47 sc_out<int> o;
48 sc_in<int> i;
49
50 void f ()
51 {
52 int t = (int) (sc_time_stamp ().to_double());
53#if 0
54 cerr << "f = " << t << endl;
55#endif
56 o.write(t);
57 }
58
59 SC_HAS_PROCESS(generator);
60 generator(sc_module_name) : clk ("clk"),
61 o ("o")
62 {
63#ifdef SYSTEMCASS_SPECIFIC
64 o(i);
65#endif
66 SC_METHOD(f);
67 dont_initialize();
68 sensitive << clk.neg() << i;
69 }
70};
71
72struct top_level : sc_module
73{
74 sc_in_clk clk;
75
76 sc_out<int> o;
77 sc_in <int> i;
78// sc_out<int> io;
79// sc_signal<int> s;
80// sc_signal<int> s2;
81
82 generator g;
83 observer obs1, obs2;
84
85 SC_HAS_PROCESS(top_level);
86 top_level(sc_module_name) : g ("generator"),
87 obs1("observer1"),
88 obs2("observer2"),
89 clk ("clk"),
90 o ("o"),
91 i ("i")/*,
92 s ("s")*/
93 {
94 g.clk (clk);
95 obs1.clk (clk);
96 obs2.clk (clk);
97
98 g.i (i);
99 g.o (o);
100 obs1.i(o);
101 obs2.i(o);
102 }
103};
104
105int
106sc_main (int argc, char ** argv)
107{
108 int errnum = 0;
109 sc_clock clk("top_clk");
110 sc_signal<int> out("top_out");
111 sc_signal<int> in ("top_in");
112
113 top_level t("top_level");
114
115 t.clk (clk);
116 t.o (out);
117 t.i (in);
118
119#if 0
120 /* Open trace file */
121 sc_trace_file *system_trace_file;
122 system_trace_file = sc_create_vcd_trace_file ("trace_file");
123
124 /* clks waveforms are always useful */
125 sc_trace(system_trace_file, clk1, "clk1");
126 sc_trace(system_trace_file, clk2, "clk2");
127
128 /* others signals */
129 for (int i = 0; i < 10; ++i)
130 sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s"));
131#endif
132
133 /* initilization */
134#if 0
135 cout << "initilization...\n";
136#endif
137 sc_initialize ();
138
139 /* simulation */
140#if 0
141 cout << "simulation...\n";
142#endif
143 int i = 0;
144 while (i++ < 5)
145 {
146 sc_start (1);
147 ASSERT(out.read() == t.obs1.i.read())
148 ASSERT(out.read() == t.obs2.i.read())
149 }
150
151#if 0
152 cout << "\ndone.\n";
153#endif
154
155 return 0;
156}
157
Note: See TracBrowser for help on using the repository browser.