hshake2.cpp revision 12855
12139SN/A/*****************************************************************************
22139SN/A
32139SN/A  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
42139SN/A  more contributor license agreements.  See the NOTICE file distributed
52139SN/A  with this work for additional information regarding copyright ownership.
62139SN/A  Accellera licenses this file to you under the Apache License, Version 2.0
72139SN/A  (the "License"); you may not use this file except in compliance with the
82139SN/A  License.  You may obtain a copy of the License at
92139SN/A
102139SN/A    http://www.apache.org/licenses/LICENSE-2.0
112139SN/A
122139SN/A  Unless required by applicable law or agreed to in writing, software
132139SN/A  distributed under the License is distributed on an "AS IS" BASIS,
142139SN/A  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
152139SN/A  implied.  See the License for the specific language governing
162139SN/A  permissions and limitations under the License.
172139SN/A
182139SN/A *****************************************************************************/
192139SN/A
202139SN/A/*****************************************************************************
212139SN/A
222139SN/A  hshake2.cpp --
232139SN/A
242139SN/A  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
252139SN/A
262139SN/A *****************************************************************************/
272139SN/A
282665Ssaidi@eecs.umich.edu/*****************************************************************************
292665Ssaidi@eecs.umich.edu
302139SN/A  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
312718Sstever@eecs.umich.edu  changes you are making here.
322139SN/A
332139SN/A      Name, Affiliation, Date:
342139SN/A  Description of Modification:
352139SN/A
362152SN/A *****************************************************************************/
372152SN/A
382152SN/A#include "systemc.h"
392152SN/A
402139SN/ASC_MODULE( proc1 )
412139SN/A{
422139SN/A  SC_HAS_PROCESS( proc1 );
432139SN/A
442139SN/A  sc_in_clk clk;
452152SN/A
462152SN/A  sc_fifo<int>& in;
472139SN/A  sc_fifo<bool>& done;
482139SN/A  sc_fifo<int>& out;
492139SN/A  sc_fifo<bool>& ready;
502984Sgblack@eecs.umich.edu
512439SN/A  // Constructor
523520Sgblack@eecs.umich.edu  proc1( sc_module_name NAME,
532139SN/A	 sc_clock& CLOCK,
543565Sgblack@eecs.umich.edu	 sc_fifo<int>& IN_,
553170Sstever@eecs.umich.edu	 sc_fifo<bool>& DONE,
563806Ssaidi@eecs.umich.edu	 sc_fifo<int>& OUT_,
572439SN/A	 sc_fifo<bool>& READY )
582460SN/A    : in(IN_), done(DONE), out(OUT_), ready(READY)
593536Sgblack@eecs.umich.edu  {
602439SN/A    clk(CLOCK);
612972Sgblack@eecs.umich.edu	SC_THREAD( entry );
622171SN/A	sensitive << clk.pos();
632439SN/A  }
642439SN/A
652170SN/A  void entry() {
662139SN/A    ready.write(1);
672139SN/A    bool done_ = done.read();
683546Sgblack@eecs.umich.edu    cout << "Done is " << done_ << endl;
693546Sgblack@eecs.umich.edu    for (int i=0; i < 100; i++) {
702152SN/A      out.write(i);
712152SN/A      int in_ = in.read();
722152SN/A      cout << "Input is " << in_ << endl;
732152SN/A    }
742152SN/A    ready.write(0);
752152SN/A  }
762152SN/A};
772152SN/A
782152SN/ASC_MODULE( proc2 )
792152SN/A{
802152SN/A  SC_HAS_PROCESS( proc2 );
812152SN/A
822504SN/A  sc_in_clk clk;
832504SN/A
842504SN/A  sc_fifo<int>& in;
852504SN/A  sc_fifo<bool>& done;
862152SN/A  sc_fifo<int>& out;
872504SN/A  sc_fifo<bool>& ready;
882152SN/A
892152SN/A  // Constructor
902152SN/A  proc2( sc_module_name NAME,
912152SN/A	 sc_clock& CLOCK,
922152SN/A	 sc_fifo<int>& IN_,
932152SN/A	 sc_fifo<bool>& DONE,
942152SN/A	 sc_fifo<int>& OUT_,
952152SN/A	 sc_fifo<bool>& READY)
962632Sstever@eecs.umich.edu    : in(IN_), done(DONE), out(OUT_), ready(READY)
972155SN/A  {
982155SN/A    clk(CLOCK);
992155SN/A	SC_THREAD( entry );
1002155SN/A	sensitive << clk.pos();
1012155SN/A  }
1022155SN/A
1032155SN/A  void entry() {
1042155SN/A    ready.write(1);
1052155SN/A    bool done_ = done.read();
1062155SN/A    cout << "Proc2::Done is " << done_ << endl;
1072152SN/A    for (int i=0; i < 100; i++) {
1082766Sktlim@umich.edu      out.write(i);
1092766Sktlim@umich.edu      int in_ = in.read();
1102766Sktlim@umich.edu      cout << "Proc2::Input is " << in_ << endl;
1112766Sktlim@umich.edu    }
1122766Sktlim@umich.edu    ready.write(0);
1132152SN/A  }
1142152SN/A};
1152152SN/A
1162155SN/Aint sc_main(int ac, char *av[])
1172152SN/A{
1182152SN/A  sc_fifo<bool> a(3);
1192718Sstever@eecs.umich.edu  sc_fifo<bool> b(10);
1202921Sktlim@umich.edu  sc_fifo<int> c("C", 10);
1212921Sktlim@umich.edu  sc_fifo<int> d("D", 2);
1222921Sktlim@umich.edu
1232921Sktlim@umich.edu  sc_clock clock("CLK", 20, SC_NS);
1242921Sktlim@umich.edu
1252921Sktlim@umich.edu  proc1 p1("P1", clock, c, a, d, b);
1262921Sktlim@umich.edu  proc2 p2("P2", clock, d, b, c, a);
1272921Sktlim@umich.edu
1282921Sktlim@umich.edu  sc_start(1000, SC_NS);
1292152SN/A  return 0;
1302152SN/A}
1312152SN/A