source: latest/test_regression/15092005/system.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.7 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#if 0
124        /* Open trace file */
125        sc_trace_file *system_trace_file;
126        system_trace_file = sc_create_vcd_trace_file ("trace_file");
127       
128        /* clks waveforms are always useful */
129        sc_trace(system_trace_file, clk1, "clk1");
130        sc_trace(system_trace_file, clk2, "clk2");
131
132  /* others signals */
133  for (int i = 0; i < 10; ++i)
134    sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s"));
135#endif
136
137  /* initilization */
138#if 0 
139  cout << "initilization...\n";
140#endif
141  sc_initialize ();
142
143  /* simulation */
144#if 0 
145  cout << "simulation...\n";
146#endif
147  int i = 0;
148  while (i++ < 5)
149  {
150   sc_start (1);
151   ASSERT(out.read() == t.obs1.i.read())
152   ASSERT(out.read() == t.obs2.i.read())
153  }
154
155#if 0 
156  cout << "\ndone.\n"; 
157#endif
158
159  return 0;
160}
161
Note: See TracBrowser for help on using the repository browser.