dataflow.cpp revision 12855:588919e0e4aa
1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22  dataflow.cpp --
23
24  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38#include "systemc.h"
39
40SC_MODULE( sawtooth )
41{
42  SC_HAS_PROCESS( sawtooth );
43
44  sc_in_clk clk;
45
46  sc_fifo<int>& out1;
47  sc_fifo<int>& out2;
48
49  sawtooth( sc_module_name NAME,
50	    sc_clock& CLK,
51	    sc_fifo<int>& OUT1,
52	    sc_fifo<int>& OUT2 )
53    : out1(OUT1), out2(OUT2)
54  {
55    clk(CLK);
56	SC_THREAD( entry );
57	sensitive << clk.pos();
58  }
59
60  void entry();
61};
62
63void sawtooth::entry()
64{
65  int index = 0;
66  while (true) {
67     wait();
68    out1.write(index % 17);
69    out2.write(index % 17);
70    index++;
71  }
72}
73
74SC_MODULE( delay )
75{
76  SC_HAS_PROCESS( delay );
77
78  sc_in_clk clk;
79
80  sc_fifo<int>& in;
81  sc_fifo<int>& out;
82
83  delay( sc_module_name NAME,
84	 sc_clock& CLK,
85	 sc_fifo<int>& IN_,
86	 sc_fifo<int>& OUT_ )
87    : in(IN_), out(OUT_)
88  {
89    clk(CLK);
90	SC_THREAD( entry );
91	sensitive << clk.pos();
92  }
93
94  void entry();
95};
96
97void delay::entry()
98{
99  int buffer = 0;
100
101  while (true) {
102    out.write(buffer);
103    buffer = in.read();
104  }
105}
106
107SC_MODULE( downsample )
108{
109  SC_HAS_PROCESS( downsample );
110
111  sc_in_clk clk;
112
113  sc_fifo<int>& in;
114  sc_fifo<int>& out;
115
116  downsample( sc_module_name NAME,
117	      sc_clock& CLK,
118	      sc_fifo<int>& IN_,
119	      sc_fifo<int>& OUT_ )
120    : in(IN_), out(OUT_)
121  {
122    clk(CLK);
123	SC_THREAD( entry );
124	sensitive << clk.pos();
125  }
126
127  void entry();
128};
129
130void downsample::entry()
131{
132  int temp;
133  while (true) {
134    temp = in.read();
135    temp = in.read();
136    out.write(temp);
137  }
138}
139
140SC_MODULE( upsample )
141{
142  SC_HAS_PROCESS( upsample );
143
144  sc_in_clk clk;
145
146  sc_fifo<int>& in;
147  sc_fifo<int>& out;
148
149  upsample( sc_module_name NAME,
150	    sc_clock& CLK,
151	    sc_fifo<int>& IN_,
152	    sc_fifo<int>& OUT_ )
153    : in(IN_), out(OUT_)
154  {
155    clk(CLK);
156	SC_THREAD( entry );
157	sensitive << clk.pos();
158  }
159
160  void entry();
161};
162
163void upsample::entry()
164{
165  while(true) {
166    out.write(in.read());
167    out.write(0);
168  }
169}
170
171SC_MODULE( adder )
172{
173  SC_HAS_PROCESS( adder );
174
175  sc_in_clk clk;
176
177  sc_fifo<int>& a;
178  sc_fifo<int>& b;
179
180  adder( sc_module_name NAME,
181	 sc_clock& CLK,
182	 sc_fifo<int>& A,
183	 sc_fifo<int>& B )
184    : a(A), b(B)
185  {
186    clk(CLK);
187	SC_THREAD( entry );
188	sensitive << clk.pos();
189  }
190
191  void entry();
192};
193
194void adder::entry()
195{
196  while(true) {
197    int tmp = a.read() + b.read();
198    cout << "Sum = " << tmp << endl;
199  }
200}
201
202
203int sc_main(int ac, char *av[])
204{
205  sc_fifo<int> st1("ST1", 2), st2("ST2", 2);
206  sc_fifo<int> a1("A1", 2), a2("A2", 2), a3("A3", 2);
207  sc_fifo<int> b1("B1", 2), b2("B2", 2), b3("B3", 2);
208
209  sc_clock clock("CLOCK");
210
211  sawtooth ST("TB1", clock, st1, st2);
212
213  delay D1("D1", clock, st1, a1);
214  downsample DN1("DN1", clock, a1, a2);
215  upsample UP1("UP1", clock, a2, a3);
216
217  downsample DN2("DN2", clock, st2, b1);
218  upsample UP2("UP2", clock, b1, b2);
219  delay D2("D2", clock, b2, b3);
220
221  adder A ("A", clock, a3, b3);
222
223  sc_start(100, SC_NS);
224
225  return 0;
226}
227