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