112855Sgabeblack@google.com/*****************************************************************************
212855Sgabeblack@google.com
312855Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412855Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512855Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612855Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712855Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812855Sgabeblack@google.com  License.  You may obtain a copy of the License at
912855Sgabeblack@google.com
1012855Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112855Sgabeblack@google.com
1212855Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312855Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412855Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512855Sgabeblack@google.com  implied.  See the License for the specific language governing
1612855Sgabeblack@google.com  permissions and limitations under the License.
1712855Sgabeblack@google.com
1812855Sgabeblack@google.com *****************************************************************************/
1912855Sgabeblack@google.com
2012855Sgabeblack@google.com/*****************************************************************************
2112855Sgabeblack@google.com
2212855Sgabeblack@google.com  test4.cpp --
2312855Sgabeblack@google.com
2412855Sgabeblack@google.com  Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15
2512855Sgabeblack@google.com
2612855Sgabeblack@google.com *****************************************************************************/
2712855Sgabeblack@google.com
2812855Sgabeblack@google.com/*****************************************************************************
2912855Sgabeblack@google.com
3012855Sgabeblack@google.com  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
3112855Sgabeblack@google.com  changes you are making here.
3212855Sgabeblack@google.com
3312855Sgabeblack@google.com      Name, Affiliation, Date:
3412855Sgabeblack@google.com  Description of Modification:
3512855Sgabeblack@google.com
3612855Sgabeblack@google.com *****************************************************************************/
3712855Sgabeblack@google.com
3812855Sgabeblack@google.com/*
3912855Sgabeblack@google.com  Corner case testing for new scheduler.
4012855Sgabeblack@google.com  Case 4: Checking gated clocks and triggering of processes
4112855Sgabeblack@google.com  */
4212855Sgabeblack@google.com
4312855Sgabeblack@google.com#include "systemc.h"
4412855Sgabeblack@google.com
4512855Sgabeblack@google.comSC_MODULE( cgater )
4612855Sgabeblack@google.com{
4712855Sgabeblack@google.com  SC_HAS_PROCESS( cgater );
4812855Sgabeblack@google.com
4912855Sgabeblack@google.com  const sc_signal<bool>& gate;
5012855Sgabeblack@google.com  sc_in<bool>  clock_in;
5112855Sgabeblack@google.com  sc_out<bool> clock_out;
5212855Sgabeblack@google.com
5312855Sgabeblack@google.com  cgater(sc_module_name NAME,
5412855Sgabeblack@google.com	 const sc_signal<bool>& GATE,
5512855Sgabeblack@google.com	 sc_signal_in_if<bool>& CLOCK_IN,
5612855Sgabeblack@google.com	 sc_signal_out_if<bool>& CLOCK_OUT)
5712855Sgabeblack@google.com    : gate(GATE)
5812855Sgabeblack@google.com  {
5912855Sgabeblack@google.com    clock_in(CLOCK_IN);
6012855Sgabeblack@google.com    clock_out(CLOCK_OUT);
6112855Sgabeblack@google.com    SC_METHOD( entry );
6212855Sgabeblack@google.com    sensitive << gate;
6312855Sgabeblack@google.com    sensitive << clock_in;
6412855Sgabeblack@google.com  }
6512855Sgabeblack@google.com
6612855Sgabeblack@google.com  void entry()
6712855Sgabeblack@google.com  {
6812855Sgabeblack@google.com    clock_out = clock_in & gate;
6912855Sgabeblack@google.com  }
7012855Sgabeblack@google.com};
7112855Sgabeblack@google.com
7212855Sgabeblack@google.comSC_MODULE( watcher )
7312855Sgabeblack@google.com{
7412855Sgabeblack@google.com  SC_HAS_PROCESS( watcher );
7512855Sgabeblack@google.com
7612855Sgabeblack@google.com  const sc_signal<bool>& gate;
7712855Sgabeblack@google.com  sc_in<bool> clock;
7812855Sgabeblack@google.com  sc_in<bool> dclock;
7912855Sgabeblack@google.com  const sc_signal<int>& a;
8012855Sgabeblack@google.com
8112855Sgabeblack@google.com  watcher(sc_module_name NAME,
8212855Sgabeblack@google.com	  const sc_signal<bool>& GATE,
8312855Sgabeblack@google.com	  sc_signal_in_if<bool>& CLOCK,
8412855Sgabeblack@google.com	  sc_signal_in_if<bool>& DCLOCK,
8512855Sgabeblack@google.com	  const sc_signal<int>& A)
8612855Sgabeblack@google.com    : gate(GATE), a(A)
8712855Sgabeblack@google.com  {
8812855Sgabeblack@google.com    clock(CLOCK);
8912855Sgabeblack@google.com    dclock(DCLOCK);
9012855Sgabeblack@google.com    SC_METHOD( entry );
9112855Sgabeblack@google.com    sensitive << clock;
9212855Sgabeblack@google.com    sensitive << a;
9312855Sgabeblack@google.com    sensitive << gate;
9412855Sgabeblack@google.com    sensitive << dclock;
9512855Sgabeblack@google.com  }
9612855Sgabeblack@google.com
9712855Sgabeblack@google.com  void entry()
9812855Sgabeblack@google.com  {
9912855Sgabeblack@google.com    cout << "[ ";
10012855Sgabeblack@google.com    if (clock.posedge()) cout << "Posedge - ";
10112855Sgabeblack@google.com    if (clock.negedge()) cout << "Negedge - ";
10212855Sgabeblack@google.com    if (dclock.posedge()) cout << "Posedge(D) - ";
10312855Sgabeblack@google.com    if (dclock.negedge()) cout << "Negedge(D) - ";
10412855Sgabeblack@google.com    if (a.event()) cout << "A = " << a.read() << " - ";
10512855Sgabeblack@google.com    if (gate.event()) cout << "Gate = " << gate.read() << " - ";
10612855Sgabeblack@google.com    cout << "]" << endl;
10712855Sgabeblack@google.com  }
10812855Sgabeblack@google.com};
10912855Sgabeblack@google.com
11012855Sgabeblack@google.com
11112855Sgabeblack@google.comSC_MODULE( gategen )
11212855Sgabeblack@google.com{
11312855Sgabeblack@google.com  SC_HAS_PROCESS( gategen );
11412855Sgabeblack@google.com
11512855Sgabeblack@google.com  sc_in<bool> clk;
11612855Sgabeblack@google.com
11712855Sgabeblack@google.com  sc_signal<bool>& gate;
11812855Sgabeblack@google.com
11912855Sgabeblack@google.com  gategen(sc_module_name NAME,
12012855Sgabeblack@google.com	  sc_signal_in_if<bool>& CLK,
12112855Sgabeblack@google.com	  sc_signal<bool>& GATE)
12212855Sgabeblack@google.com    : gate(GATE)
12312855Sgabeblack@google.com  {
12412855Sgabeblack@google.com    clk(CLK);
12512855Sgabeblack@google.com    SC_CTHREAD( entry, clk.pos() );
12612855Sgabeblack@google.com    gate = 1;
12712855Sgabeblack@google.com  }
12812855Sgabeblack@google.com
12912855Sgabeblack@google.com  void entry()
13012855Sgabeblack@google.com  {
13112855Sgabeblack@google.com    while (true) {
13212855Sgabeblack@google.com      gate = 1; wait(3);
13312855Sgabeblack@google.com      gate = 0; wait (3);
13412855Sgabeblack@google.com    }
13512855Sgabeblack@google.com  }
13612855Sgabeblack@google.com};
13712855Sgabeblack@google.com
13812855Sgabeblack@google.comSC_MODULE( trigp )
13912855Sgabeblack@google.com{
14012855Sgabeblack@google.com  SC_HAS_PROCESS( trigp );
14112855Sgabeblack@google.com
14212855Sgabeblack@google.com  sc_in<bool> clk;
14312855Sgabeblack@google.com
14412855Sgabeblack@google.com  sc_signal<int>& out;
14512855Sgabeblack@google.com
14612855Sgabeblack@google.com  trigp(sc_module_name NAME,
14712855Sgabeblack@google.com	sc_signal_in_if<bool>& CLK,
14812855Sgabeblack@google.com	sc_signal<int>& OUT_)
14912855Sgabeblack@google.com    : out(OUT_)
15012855Sgabeblack@google.com  {
15112855Sgabeblack@google.com    clk(CLK);
15212855Sgabeblack@google.com    SC_CTHREAD( entry, clk.pos() );
15312855Sgabeblack@google.com    out = 0;
15412855Sgabeblack@google.com  }
15512855Sgabeblack@google.com
15612855Sgabeblack@google.com  void entry()
15712855Sgabeblack@google.com  {
15812855Sgabeblack@google.com    int i = 11;
15912855Sgabeblack@google.com    while (true) {
16012855Sgabeblack@google.com      out = i++;
16112855Sgabeblack@google.com      wait();
16212855Sgabeblack@google.com    }
16312855Sgabeblack@google.com  }
16412855Sgabeblack@google.com};
16512855Sgabeblack@google.com
16612855Sgabeblack@google.comint
16712855Sgabeblack@google.comsc_main(int ac, char *av[])
16812855Sgabeblack@google.com{
16912855Sgabeblack@google.com  // sc_clock clock1("Clock1", 20, SC_NS, 0.5);
17012855Sgabeblack@google.com  // sc_clock dclock("Derived");
17112855Sgabeblack@google.com  sc_signal<bool> clock1( "Clock1" );
17212855Sgabeblack@google.com  sc_signal<bool> dclock( "Derived" );
17312855Sgabeblack@google.com
17412855Sgabeblack@google.com  sc_signal<bool> Gate;
17512855Sgabeblack@google.com  sc_signal<int> Output;
17612855Sgabeblack@google.com
17712855Sgabeblack@google.com  cgater CG("CG", Gate, clock1, dclock);
17812855Sgabeblack@google.com  watcher W("W", Gate, clock1, dclock, Output);
17912855Sgabeblack@google.com  gategen G("G", clock1, Gate);
18012855Sgabeblack@google.com  trigp T("T", dclock, Output);
18112855Sgabeblack@google.com
18212855Sgabeblack@google.com  sc_trace_file *tf = sc_create_vcd_trace_file("systemc");
18312855Sgabeblack@google.com  sc_trace(tf, clock1, "Clock");
18412855Sgabeblack@google.com  sc_trace(tf, dclock, "Dclock");
18512855Sgabeblack@google.com  sc_trace(tf, Gate, "Gate");
18612855Sgabeblack@google.com  sc_trace(tf, Output, "Out");
18712855Sgabeblack@google.com
18812855Sgabeblack@google.com  sc_start(0, SC_NS);
18912855Sgabeblack@google.com  clock1.write(0);
19012855Sgabeblack@google.com  sc_start(5, SC_NS);
19112855Sgabeblack@google.com  for (int i=0; i < 30; i++) {
19212855Sgabeblack@google.com    clock1.write(1);
19312855Sgabeblack@google.com    sc_start(5, SC_NS);
19412855Sgabeblack@google.com    clock1.write(0);
19512855Sgabeblack@google.com    sc_start(5, SC_NS);
19612855Sgabeblack@google.com  }
19712855Sgabeblack@google.com
19812855Sgabeblack@google.com  return 0;
19912855Sgabeblack@google.com}
200