source: sources/test_regression/09092005c/system.cpp@ 57

Last change on this file since 57 was 56, checked in by meunier, 13 years ago
  • Tried to fix a problem with echo
  • Started to resolve some tests failing (often because of the test itself)
File size: 2.3 KB
RevLine 
[55]1
[1]2#include "systemc.h"
[55]3
[1]4#include <iostream>
5
[55]6#include "test.h"
[1]7
8using namespace std;
9
10
[55]11struct observer : sc_module {
12 sc_in_clk clk;
[1]13
[55]14 sc_in<int> i;
[1]15
[55]16 void f() {}
[1]17
[55]18 SC_HAS_PROCESS(observer);
19 observer(sc_module_name) : clk ("clk"),
20 i("i") {
21 SC_METHOD(f);
22 sensitive << clk.pos();
23 dont_initialize();
24 }
[1]25};
26
27
[55]28struct generator : sc_module {
29 sc_in_clk clk;
30 sc_out<int> o;
[1]31
[55]32 void f() {
33 int t = (int) (sc_time_stamp().to_double());
[56]34#ifdef SYSTEMCASS_SPECIFIC
35 t = t * 1000;
36#endif
[55]37 o.write(t);
38 }
[1]39
[55]40 SC_HAS_PROCESS(generator);
41 generator(sc_module_name) : clk("clk"), o("o") {
42 SC_METHOD(f);
[56]43 sensitive << clk.pos();
[55]44 dont_initialize();
45 }
46
[1]47};
48
49
50
[55]51struct top_level : sc_module {
52 sc_in_clk clk;
53
54 sc_out<int> o;
55
56 generator g;
57 observer obs1, obs2;
58
59 SC_HAS_PROCESS(top_level);
60 top_level(sc_module_name) :
61 clk("clk"),
62 o("o"),
63 g("generator"),
64 obs1("observer1"),
[56]65 obs2("observer2") {
[55]66 g.clk(clk);
67 obs1.clk(clk);
68 obs2.clk(clk);
69
70 g.o(o);
71 obs1.i(o);
72 obs2.i(o);
73 }
74
[1]75};
76
77
[55]78int sc_main (int argc, char ** argv) {
[56]79 sc_clock clk("top_clk", sc_time(1, sc_core::SC_NS));
[55]80 sc_signal<int> out("top_out");
[1]81
[55]82 top_level t("top_level");
[1]83
[55]84 t.clk(clk);
[56]85 t.o(out);
[55]86
87 // QM : pourquoi est-ce tout commenté ??
[1]88#if 0
[55]89 /* Open trace file */
90 sc_trace_file *system_trace_file;
91 system_trace_file = sc_create_vcd_trace_file ("trace_file");
[1]92
[55]93 /* clks waveforms are always useful */
94 sc_trace(system_trace_file, clk1, "clk1");
95 sc_trace(system_trace_file, clk2, "clk2");
[1]96
[55]97 /* others signals */
98 for (int i = 0; i < 10; ++i)
99 sc_trace(system_trace_file, s[i], sc_gen_unique_name ("s"));
[1]100#endif
101
[55]102 sc_start(sc_time(0, sc_core::SC_NS));
[1]103
[55]104 /* simulation */
105 int i = 0;
106 while (i++ < 5) {
107 sc_start(sc_time(1, sc_core::SC_NS));
108 cout << out.read() << " - " << t.obs1.i.read() << " - " << t.obs2.i.read() << endl;
109 }
110 return 0;
[1]111}
112
[55]113
114/*
115# Local Variables:
116# tab-width: 4;
117# c-basic-offset: 4;
118# c-file-offsets:((innamespace . 0)(inline-open . 0));
119# indent-tabs-mode: nil;
120# End:
121#
122# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
123*/
124
Note: See TracBrowser for help on using the repository browser.