test1.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  test1.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    while (true) {
74      val = in.read();
75      cout << "Proc1:: Read. Value = " << val << "\n";
76      wait( i );
77      i += 3;
78    }
79  }
80};
81
82SC_MODULE( proc2 )
83{
84  SC_HAS_PROCESS( proc2 );
85
86  sc_in_clk clk;
87
88  sc_fifo<int>& out;
89
90  // Constructor
91  proc2( sc_module_name NAME,
92	 sc_clock& CLOCK,
93	 sc_fifo<int>& OUT_ )
94    : out(OUT_)
95  {
96    clk( CLOCK );
97	SC_THREAD( entry );
98	sensitive << clk.pos();
99  }
100
101  void entry() {
102    cout << "Proc2:: Write\n";
103    out.write(1);
104    cout << "Proc2:: Write completed\n";
105    cout << "Proc2:: Wait 10 cycles before write\n";
106    wait( 10 );
107    cout << "Proc2:: Wait completed\n";
108    cout << "Proc2:: Write\n";
109    out.write(2);
110    cout << "Proc2:: Write Completed\n";
111    cout << "Proc2:: Write\n";
112    out.write(3);
113    cout << "Proc2:: Write Completed\n";
114    cout << "Proc2:: Loop start\n";
115    for (int i=4; i<10; i++) {
116      out.write(i);
117      wait( i + 2 );
118    }
119    sc_stop();
120  }
121};
122
123int sc_main(int ac, char *av[])
124{
125  sc_fifo<int> c("C");
126
127  sc_clock clock("CLK", 20, SC_NS);
128
129  proc1 p1("P1", clock, c);
130  proc2 p2("P2", clock, c);
131
132  sc_start();
133
134  return 0;
135}
136