source: latest/test_regression/15092005/system4.cpp @ 1

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

Initial import from CVS repository

File size: 2.8 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    SC_METHOD(f);
64    dont_initialize();
65    sensitive << clk.neg() << i;
66#ifdef SYSTEMCASS_SPECIFIC
67    o(i);
68#endif
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#ifdef SYSTEMCASS_SPECIFIC
104    o     (i); // wrong declaration that needs detection (no sc_method)
105#endif
106  }
107};
108
109int
110sc_main (int argc, char ** argv)
111{
112  int errnum = 0;
113  sc_clock       clk("top_clk");
114  sc_signal<int> out("top_out");
115  sc_signal<int> in ("top_in");
116
117  top_level t("top_level");
118
119  t.clk (clk);
120  t.o   (out);
121  t.i   (in);
122
123#ifdef SYSTEMCASS_SPECIFIC
124  t.o(t.i);
125#endif
126
127#if 0
128        /* Open trace file */
129        sc_trace_file *system_trace_file;
130        system_trace_file = sc_create_vcd_trace_file ("trace_file");
131       
132        /* clks waveforms are always useful */
133        sc_trace(system_trace_file, clk1, "clk1");
134        sc_trace(system_trace_file, clk2, "clk2");
135
136  /* others signals */
137  for (int i = 0; i < 10; ++i)
138    sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s"));
139#endif
140
141  /* initilization */
142#if 0 
143  cout << "initilization...\n";
144#endif
145  sc_initialize ();
146
147  /* simulation */
148#if 0 
149  cout << "simulation...\n";
150#endif
151  int i = 0;
152  while (i++ < 5)
153  {
154   sc_start (1);
155   ASSERT(out.read() == t.obs1.i.read())
156   ASSERT(out.read() == t.obs2.i.read())
157  }
158
159#if 0 
160  cout << "\ndone.\n"; 
161#endif
162
163  return 0;
164}
165
Note: See TracBrowser for help on using the repository browser.