test2.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  test2.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( p1 )
41{
42  SC_HAS_PROCESS( p1 );
43
44  sc_fifo<int>& a;
45  sc_fifo<int>& b;
46  sc_in<bool> clk;
47
48  int init;
49
50  p1(sc_module_name name,
51     sc_fifo<int>& A,
52     sc_fifo<int>& B,
53     sc_signal_in_if<bool>& CLK,
54     int INIT)
55    : a(A), b(B)
56  {
57    clk(CLK);
58	init = INIT;
59    SC_THREAD( entry );
60    sensitive << clk;
61    // sensitive << b;
62  }
63
64  void entry() {
65    wait();
66    int i = init;
67    wait();
68    while (true) {
69      a.write(i);
70      int j = b.read();
71      cout << "Value sent = " << i << " Value read = " << j << endl;
72      wait(); i++;
73    }
74  }
75};
76
77SC_MODULE( p2 )
78{
79  SC_HAS_PROCESS( p2 );
80
81  sc_in_clk clk;
82
83  sc_fifo<int>& a;
84  sc_fifo<int>& b;
85
86  int init;
87
88  p2 (sc_module_name name,
89      sc_clock& CLK,
90      sc_fifo<int>& A,
91      sc_fifo<int>& B,
92      int INIT)
93    : a(A), b(B)
94  {
95    clk(CLK);
96	SC_CTHREAD( entry, clk.pos() );
97    init = INIT;
98  }
99
100  void entry() {
101    int i = init;
102    wait();
103    while (true) {
104      a.write(i);
105      int j = b.read();
106      cout << "Value sent = " << i << " Value read = " << j << endl;
107      wait(); i++;
108    }
109  }
110};
111
112int sc_main(int ac, char *av[])
113{
114  sc_fifo<int> a(2), b(2);
115  sc_clock clock("Clock", 20, SC_NS);
116
117  p1 Proc1("Proc1", a, b, clock, 10);
118  p2 Proc2("Proc2", clock, b, a, 129);
119
120  // sc_start(500, SC_NS);
121  sc_start(250, SC_NS);
122
123  return 0;
124}
125