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  test7.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 5: Checking multiple clock transitions at the same time
4112855Sgabeblack@google.com  */
4212855Sgabeblack@google.com
4312855Sgabeblack@google.com#include "systemc.h"
4412855Sgabeblack@google.com
4512855Sgabeblack@google.comSC_MODULE( triga )
4612855Sgabeblack@google.com{
4712855Sgabeblack@google.com  SC_HAS_PROCESS( triga );
4812855Sgabeblack@google.com
4912855Sgabeblack@google.com  sc_in<bool> clock;
5012855Sgabeblack@google.com  sc_signal<int>& out;
5112855Sgabeblack@google.com
5212855Sgabeblack@google.com  int i;
5312855Sgabeblack@google.com
5412855Sgabeblack@google.com  triga(sc_module_name NAME,
5512855Sgabeblack@google.com	sc_signal_in_if<bool>& CLOCK,
5612855Sgabeblack@google.com	sc_signal<int>& OUT_)
5712855Sgabeblack@google.com    : out(OUT_)
5812855Sgabeblack@google.com  {
5912855Sgabeblack@google.com    clock(CLOCK);
6012855Sgabeblack@google.com    SC_METHOD( entry );
6112855Sgabeblack@google.com    sensitive << clock;
6212855Sgabeblack@google.com    i = 0;
6312855Sgabeblack@google.com    out = i++;
6412855Sgabeblack@google.com  }
6512855Sgabeblack@google.com
6612855Sgabeblack@google.com  void entry()
6712855Sgabeblack@google.com  {
6812855Sgabeblack@google.com    out = i++;
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  sc_in<bool> clock1;
7712855Sgabeblack@google.com  sc_in<bool> clock2;
7812855Sgabeblack@google.com  const sc_signal<int>& in1;
7912855Sgabeblack@google.com  const sc_signal<int>& in2;
8012855Sgabeblack@google.com  const sc_signal<int>& in3;
8112855Sgabeblack@google.com  const sc_signal<int>& in4;
8212855Sgabeblack@google.com
8312855Sgabeblack@google.com  watcher(sc_module_name NAME,
8412855Sgabeblack@google.com	  sc_signal_in_if<bool>& CLOCK1,
8512855Sgabeblack@google.com	  sc_signal_in_if<bool>& CLOCK2,
8612855Sgabeblack@google.com	  const sc_signal<int>& IN1,
8712855Sgabeblack@google.com	  const sc_signal<int>& IN2,
8812855Sgabeblack@google.com	  const sc_signal<int>& IN3,
8912855Sgabeblack@google.com	  const sc_signal<int>& IN4)
9012855Sgabeblack@google.com    : in1(IN1), in2(IN2), in3(IN3), in4(IN4)
9112855Sgabeblack@google.com  {
9212855Sgabeblack@google.com    clock1(CLOCK1);
9312855Sgabeblack@google.com    clock2(CLOCK2);
9412855Sgabeblack@google.com    SC_METHOD( entry );
9512855Sgabeblack@google.com    sensitive << clock1 << clock2;
9612855Sgabeblack@google.com    sensitive << in1 << in2 << in3 << in4;
9712855Sgabeblack@google.com  }
9812855Sgabeblack@google.com
9912855Sgabeblack@google.com  void entry()
10012855Sgabeblack@google.com  {
10112855Sgabeblack@google.com    cout << "[ ";
10212855Sgabeblack@google.com    if (clock1.posedge()) cout << "Posedge(1) - ";
10312855Sgabeblack@google.com    if (clock1.negedge()) cout << "Negedge(1) - ";
10412855Sgabeblack@google.com    if (clock2.posedge()) cout << "Posedge(2) - ";
10512855Sgabeblack@google.com    if (clock2.negedge()) cout << "Negedge(2) - ";
10612855Sgabeblack@google.com    if (in1.event()) cout << "Sync1 Out = " << in1.read() << " - ";
10712855Sgabeblack@google.com    if (in2.event()) cout << "ASync1 Out = " << in2.read() << " - ";
10812855Sgabeblack@google.com    if (in3.event()) cout << "Sync2 Out = " << in3.read() << " - ";
10912855Sgabeblack@google.com    if (in4.event()) cout << "ASync2 Out = " << in4.read() << " - ";
11012855Sgabeblack@google.com    cout << "]" << endl;
11112855Sgabeblack@google.com  }
11212855Sgabeblack@google.com};
11312855Sgabeblack@google.com
11412855Sgabeblack@google.com
11512855Sgabeblack@google.comSC_MODULE( trigp )
11612855Sgabeblack@google.com{
11712855Sgabeblack@google.com  SC_HAS_PROCESS( trigp );
11812855Sgabeblack@google.com
11912855Sgabeblack@google.com  sc_in<bool> clk;
12012855Sgabeblack@google.com
12112855Sgabeblack@google.com  sc_signal<int>& out;
12212855Sgabeblack@google.com
12312855Sgabeblack@google.com  trigp(sc_module_name NAME,
12412855Sgabeblack@google.com	sc_signal_in_if<bool>& CLK,
12512855Sgabeblack@google.com	sc_signal<int>& OUT_)
12612855Sgabeblack@google.com    : out(OUT_)
12712855Sgabeblack@google.com  {
12812855Sgabeblack@google.com    clk(CLK);
12912855Sgabeblack@google.com    SC_CTHREAD( entry, clk.pos() );
13012855Sgabeblack@google.com    out = 0;
13112855Sgabeblack@google.com  }
13212855Sgabeblack@google.com
13312855Sgabeblack@google.com  void entry()
13412855Sgabeblack@google.com  {
13512855Sgabeblack@google.com    int i = 11;
13612855Sgabeblack@google.com    while (true) {
13712855Sgabeblack@google.com      out = i++;
13812855Sgabeblack@google.com      wait();
13912855Sgabeblack@google.com    }
14012855Sgabeblack@google.com  }
14112855Sgabeblack@google.com};
14212855Sgabeblack@google.com
14312855Sgabeblack@google.comint
14412855Sgabeblack@google.comsc_main(int ac, char *av[])
14512855Sgabeblack@google.com{
14612855Sgabeblack@google.com  sc_clock clock1("Clock1", 20, SC_NS, 0.5);
14712855Sgabeblack@google.com  sc_clock clock2("Clock2", 40, SC_NS, 0.5);
14812855Sgabeblack@google.com
14912855Sgabeblack@google.com  sc_signal<int> sig1, sig2, sig3, sig4;
15012855Sgabeblack@google.com
15112855Sgabeblack@google.com  triga T1("T1", clock1, sig2);
15212855Sgabeblack@google.com  triga T2("T2", clock2, sig4);
15312855Sgabeblack@google.com  trigp T3("T3", clock1, sig1);
15412855Sgabeblack@google.com  trigp T4("T4", clock2, sig3);
15512855Sgabeblack@google.com  watcher W("W", clock1, clock2, sig1, sig2, sig3, sig4);
15612855Sgabeblack@google.com
15712855Sgabeblack@google.com  sc_trace_file *tf = sc_create_vcd_trace_file("systemc");
15812855Sgabeblack@google.com  sc_trace(tf, clock1, "Clock1");
15912855Sgabeblack@google.com  sc_trace(tf, clock2, "Clock2");
16012855Sgabeblack@google.com  sc_trace(tf, sig1, "Sync1");
16112855Sgabeblack@google.com  sc_trace(tf, sig2, "Async1");
16212855Sgabeblack@google.com  sc_trace(tf, sig3, "Sync2");
16312855Sgabeblack@google.com  sc_trace(tf, sig4, "Async2");
16412855Sgabeblack@google.com
16512855Sgabeblack@google.com  sc_start(100, SC_NS);
16612855Sgabeblack@google.com  return 0;
16712855Sgabeblack@google.com}
168