source: sources/test_regression/15042009a/system.cpp @ 60

Last change on this file since 60 was 60, checked in by meunier, 7 years ago
  • Intégration des modifications de Clément, qui a intégré la version parallélisée de systemcass faite par Manuel.
File size: 2.9 KB
Line 
1
2#include <iostream>
3
4#include "systemc.h"
5#include "test.h"
6
7using namespace std;
8
9
10#define MASK 0x0000000FFFFFFFFFLLU
11
12
13typedef sc_uint<36> data_type; 
14
15struct observer : sc_module {
16    sc_in_clk clk;
17
18    sc_in<data_type> i;
19
20    void f() {
21        printf("0x%016llx\n", (unsigned long long int) i.read());
22        data_type t = i.read();
23
24        if (t == 7) {
25            cout << "(== 0x7)\n";
26        }
27        t <<= 1;
28
29        if (t == 14) {
30            cout << "((t << 1) == 0xe)\n";
31        }
32
33        t += 1;
34
35        if (t == 15) {
36            cout << "(((t << 1) + 1) == 0xf)\n";
37        }
38
39        t = t >> 1;
40
41        if (t == 7) {
42            cout << "((((t << 1) + 1) >> 1) == 0x7)\n";
43        }
44
45    }
46
47    SC_HAS_PROCESS(observer);
48    observer(sc_module_name) : clk ("clk"), i("i") {
49        SC_METHOD(f);
50        sensitive << clk.pos();
51        dont_initialize();
52    }
53
54};
55
56
57struct generator : sc_module {
58    sc_in_clk clk;
59
60    sc_out<data_type> o;
61    sc_in<data_type>  i;
62
63    long long int t;
64
65    void f() {
66        t <<= 1;
67        t++;
68        o.write(t);
69    }
70
71    SC_HAS_PROCESS(generator);
72    generator(sc_module_name) : clk ("clk"), o("o") {
73        t = 1;
74        SC_METHOD(f);
75        sensitive << clk.neg() << i;
76        dont_initialize();
77#ifdef SYSTEMCASS_SPECIFIC
78        o(i);
79#endif
80    }
81
82};
83
84struct top_level : sc_module {
85    sc_in_clk clk;
86
87    sc_out<data_type> o;
88    sc_in <data_type> i;
89
90    generator g;
91    observer obs1, obs2;
92
93    SC_HAS_PROCESS(top_level);
94    top_level(sc_module_name) :
95    clk ("clk"),
96    o("o"),
97    i("i"),
98    g("generator"), 
99    obs1("observer1"),
100    obs2("observer2") {
101        g.clk(clk);
102        obs1.clk(clk);
103        obs2.clk(clk);
104
105        g.i(i);
106        g.o(o);
107        obs1.i(o);
108        obs2.i(o);
109
110#ifdef SYSTEMCASS_SPECIFIC
111        o(i); // wrong declaration that needs detection (no sc_method)
112#endif
113    }
114
115};
116
117
118int sc_main(int argc, char ** argv) {
119    sc_clock             clk("top_clk");
120    sc_signal<data_type> out("top_out");
121    sc_signal<data_type> in("top_in");
122
123    top_level t("top_level");
124
125    // Setup number of threads open-mp to 1 with the macro threads_omp()
126    threads_omp();
127
128    t.clk(clk);
129    t.o(out);
130    t.i(in);
131
132    /* initilization */
133    sc_start(sc_time(0, sc_core::SC_NS));
134
135    /* simulation */
136    int i = 0;
137    while (i++ < 40) {
138        sc_start(sc_time(1, sc_core::SC_NS));
139        ASSERT(out.read() == t.obs1.i.read())
140        ASSERT(out.read() == t.obs2.i.read())
141        ASSERT(out.read() == (t.g.t & MASK))
142        printf("0x%08x - 0x%08x - 0x%08x - 0x%llx\n", (unsigned int) out.read(), (unsigned int) t.obs1.i.read(), (unsigned int) t.obs2.i.read(), (t.g.t & MASK));
143    }
144
145    return 0;
146}
147
148
149/*
150# Local Variables:
151# tab-width: 4;
152# c-basic-offset: 4;
153# c-file-offsets:((innamespace . 0)(inline-open . 0));
154# indent-tabs-mode: nil;
155# End:
156#
157# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
158*/
159
Note: See TracBrowser for help on using the repository browser.