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( proc1 )
41{
42  SC_HAS_PROCESS( proc1 );
43
44  sc_in_clk clk;
45
46  sc_fifo<int>& in;
47
48  // Constructor
49  proc1( sc_module_name NAME,
50	 sc_clock& CLOCK,
51	 sc_fifo<int>& IN_ )
52    : in(IN_)
53  {
54    clk( CLOCK );
55	SC_THREAD( entry );
56	sensitive << clk.pos();
57  }
58
59  void entry() {
60    int val;
61    cout << "Proc1:: Waiting 10 cycles before reading\n";
62    wait( 10 );
63    cout << "Proc1:: Wait completed\n";
64    val = in.read();
65    cout << "Proc1:: Read. Value = " << val << "\n";
66    cout << "Proc1:: Read\n";
67    val = in.read();
68    cout << "Proc1:: Read completed. Value = " << val << "\n";
69    val = in.read();
70    cout << "Proc1:: Read. Value = " << val << "\n";
71    cout << "Proc1:: Loop start\n";
72    int i = 1;
73    int j;
74    while (true) {
75      j = in;
76      cout << "Proc1:: Read. Value = " << j << "\n";
77      if (in > 5 && in < 7) cout << "Proc1:: Special value 6 read\n";
78      wait( i );
79      i += 3;
80    }
81  }
82};
83
84SC_MODULE( proc2 )
85{
86  SC_HAS_PROCESS( proc2 );
87
88  sc_in_clk clk;
89
90  sc_fifo<int>& out;
91
92  // Constructor
93  proc2( sc_module_name NAME,
94	 sc_clock& CLOCK,
95	 sc_fifo<int>& OUT_ )
96    : out(OUT_)
97  {
98    clk( CLOCK );
99	SC_THREAD( entry );
100	sensitive << clk.pos();
101  }
102
103  void entry() {
104    cout << "Proc2:: Write\n";
105    out = 1;
106    cout << "Proc2:: Write completed\n";
107    cout << "Proc2:: Wait 10 cycles before write\n";
108    wait( 10 );
109    cout << "Proc2:: Wait completed\n";
110    cout << "Proc2:: Write\n";
111    out = 2;
112    cout << "Proc2:: Write Completed\n";
113    cout << "Proc2:: Write\n";
114    out = 3;
115    cout << "Proc2:: Write Completed\n";
116    cout << "Proc2:: Loop start\n";
117    for (int i=4; i<10; i++) {
118      out = i;
119      wait( i + 2 );
120    }
121    sc_stop();
122  }
123};
124
125int sc_main(int ac, char *av[])
126{
127  sc_fifo<int> c("C");
128
129  sc_clock clock("CLK", 20, SC_NS);
130
131  proc1 p1("P1", clock, c);
132  proc2 p2("P2", clock, c);
133
134  sc_start();
135
136  return 0;
137}
138