source: latest/test_regression/09092005c/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.5 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
49  void f ()
50  {
51    int t = (int) (sc_time_stamp ().to_double());
52#if 0
53    cerr << "f = " << t << endl;
54#endif
55    o.write(t);
56  }
57
58  SC_HAS_PROCESS(generator);
59  generator(sc_module_name) : clk ("clk"),
60                              o   ("o")
61  {
62    SC_METHOD(f);
63    dont_initialize();
64    sensitive << clk.neg();
65#ifdef SYSTEMCASS_SPECIFIC
66#endif
67  }
68};
69
70struct top_level : sc_module
71{
72  sc_in_clk    clk;
73 
74  sc_out<int>    o;
75//  sc_out<int>  io;
76//  sc_signal<int> s;
77//  sc_signal<int> s2;
78
79  generator g;
80  observer  obs1, obs2;
81 
82  SC_HAS_PROCESS(top_level);
83  top_level(sc_module_name) : g   ("generator"), 
84                              obs1("observer1"),
85                              obs2("observer2"),
86                              clk ("clk"),
87                              o   ("o")/*,
88                              s   ("s")*/
89  {
90    g.clk    (clk);
91    obs1.clk (clk);
92    obs2.clk (clk);
93
94    g.o   (o);
95    obs1.i(o);
96    obs2.i(o);
97  }
98};
99
100int
101sc_main (int argc, char ** argv)
102{
103  int errnum = 0;
104  sc_clock       clk("top_clk");
105  sc_signal<int> out("top_out");
106
107  top_level t("top_level");
108
109  t.clk (clk);
110  t.o   (out);
111
112#if 0
113        /* Open trace file */
114        sc_trace_file *system_trace_file;
115        system_trace_file = sc_create_vcd_trace_file ("trace_file");
116       
117        /* clks waveforms are always useful */
118        sc_trace(system_trace_file, clk1, "clk1");
119        sc_trace(system_trace_file, clk2, "clk2");
120
121  /* others signals */
122  for (int i = 0; i < 10; ++i)
123    sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s"));
124#endif
125
126  /* initilization */
127#if 0 
128  cout << "initilization...\n";
129#endif
130  sc_initialize ();
131
132  /* simulation */
133#if 0 
134  cout << "simulation...\n";
135#endif
136  int i = 0;
137  while (i++ < 5)
138  {
139   sc_start (1);
140   ASSERT(out.read() == t.obs1.i.read())
141   ASSERT(out.read() == t.obs2.i.read())
142  }
143
144#if 0 
145  cout << "\ndone.\n"; 
146#endif
147
148  return 0;
149}
150
Note: See TracBrowser for help on using the repository browser.