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  disaproc1.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#include "systemc.h"
3912855Sgabeblack@google.com
4012855Sgabeblack@google.comint val1[17] = { 34329, 32492,  1034, 12000,  102, 12981,  1902, 19409,
4112855Sgabeblack@google.com                 10029,  2149, 12030, 20099,   90, 10009,  9345, 57483,
4212855Sgabeblack@google.com                 10903 };
4312855Sgabeblack@google.com
4412855Sgabeblack@google.comint val2[19] = {   239,   923,  1240,   129,  191,   101,  1010,   190,
4512855Sgabeblack@google.com                 19820,  2349, 24039, 34728, 5745, 78234, 17838, 37482,
4612855Sgabeblack@google.com                 17498,  1347,  3721 };
4712855Sgabeblack@google.com
4812855Sgabeblack@google.comSC_MODULE( aproc1 )
4912855Sgabeblack@google.com{
5012855Sgabeblack@google.com    SC_HAS_PROCESS( aproc1 );
5112855Sgabeblack@google.com
5212855Sgabeblack@google.com    const sc_signal<bool>& a;
5312855Sgabeblack@google.com    const sc_signal<bool>& b;
5412855Sgabeblack@google.com          sc_signal<bool>& c;
5512855Sgabeblack@google.com
5612855Sgabeblack@google.com    aproc1( sc_module_name NAME,
5712855Sgabeblack@google.com
5812855Sgabeblack@google.com            const sc_signal<bool>& A,
5912855Sgabeblack@google.com            const sc_signal<bool>& B,
6012855Sgabeblack@google.com                  sc_signal<bool>& C )
6112855Sgabeblack@google.com        : a(A), b(B), c(C)
6212855Sgabeblack@google.com    {
6312855Sgabeblack@google.com        SC_THREAD( entry );
6412855Sgabeblack@google.com        sensitive << a << b;
6512855Sgabeblack@google.com    }
6612855Sgabeblack@google.com    void entry();
6712855Sgabeblack@google.com};
6812855Sgabeblack@google.com
6912855Sgabeblack@google.comvoid
7012855Sgabeblack@google.comaproc1::entry()
7112855Sgabeblack@google.com{
7212855Sgabeblack@google.com    wait();
7312855Sgabeblack@google.com    c = a + b;
7412855Sgabeblack@google.com    cout << "c is (a + b)" << endl;
7512855Sgabeblack@google.com    wait();
7612855Sgabeblack@google.com    c = a - b;
7712855Sgabeblack@google.com    cout << "c is (a - b)" << endl;
7812855Sgabeblack@google.com    wait();
7912855Sgabeblack@google.com    cout << name() << " is exiting." << endl;
8012855Sgabeblack@google.com}
8112855Sgabeblack@google.com
8212855Sgabeblack@google.com
8312855Sgabeblack@google.comSC_MODULE( aproc2 )
8412855Sgabeblack@google.com{
8512855Sgabeblack@google.com    SC_HAS_PROCESS( aproc2 );
8612855Sgabeblack@google.com
8712855Sgabeblack@google.com    const sc_signal<bool>& a;
8812855Sgabeblack@google.com    const sc_signal<bool>& b;
8912855Sgabeblack@google.com          sc_signal<bool>& d;
9012855Sgabeblack@google.com
9112855Sgabeblack@google.com    aproc2( sc_module_name NAME,
9212855Sgabeblack@google.com
9312855Sgabeblack@google.com            const sc_signal<bool>& A,
9412855Sgabeblack@google.com            const sc_signal<bool>& B,
9512855Sgabeblack@google.com                  sc_signal<bool>& D )
9612855Sgabeblack@google.com        : a(A), b(B), d(D)
9712855Sgabeblack@google.com    {
9812855Sgabeblack@google.com        SC_THREAD( entry );
9912855Sgabeblack@google.com        sensitive << a << b;
10012855Sgabeblack@google.com    }
10112855Sgabeblack@google.com    void entry();
10212855Sgabeblack@google.com};
10312855Sgabeblack@google.com
10412855Sgabeblack@google.comvoid
10512855Sgabeblack@google.comaproc2::entry()
10612855Sgabeblack@google.com{
10712855Sgabeblack@google.com    wait();
10812855Sgabeblack@google.com    int loops = 0;
10912855Sgabeblack@google.com    while (true) {
11012855Sgabeblack@google.com        d = a * b;
11112855Sgabeblack@google.com        cout << "d is (a * b)" << endl;
11212855Sgabeblack@google.com        wait();
11312855Sgabeblack@google.com        if ((bool) b == 0) {
11412855Sgabeblack@google.com            d = a / (b + 1);
11512855Sgabeblack@google.com            cout << "d is (a / (b + 1))" << endl;
11612855Sgabeblack@google.com        } else {
11712855Sgabeblack@google.com            d = a / b;
11812855Sgabeblack@google.com            cout << "d is (a / b)" << endl;
11912855Sgabeblack@google.com        }
12012855Sgabeblack@google.com        wait();
12112855Sgabeblack@google.com        if (loops < 1) {
12212855Sgabeblack@google.com            // sc_assert( a.sensitive_aprocs_neg.size() == 2 );
12312855Sgabeblack@google.com            // sc_assert( a.sensitive_aprocs.size() == 2 );
12412855Sgabeblack@google.com        }
12512855Sgabeblack@google.com        if (loops > 5) {
12612855Sgabeblack@google.com            /* By this time aproc1 should have died. */
12712855Sgabeblack@google.com            // sc_assert( a.sensitive_aprocs_neg.size() == 1 );
12812855Sgabeblack@google.com            // sc_assert( a.sensitive_aprocs.size() == 1 );
12912855Sgabeblack@google.com        }
13012855Sgabeblack@google.com        loops++;
13112855Sgabeblack@google.com    }
13212855Sgabeblack@google.com}
13312855Sgabeblack@google.com
13412855Sgabeblack@google.comSC_MODULE( sync1 )
13512855Sgabeblack@google.com{
13612855Sgabeblack@google.com    SC_HAS_PROCESS( sync1 );
13712855Sgabeblack@google.com
13812855Sgabeblack@google.com    sc_in_clk clk;
13912855Sgabeblack@google.com
14012855Sgabeblack@google.com          sc_signal<bool>& a;
14112855Sgabeblack@google.com          sc_signal<bool>& b;
14212855Sgabeblack@google.com    const sc_signal<bool>& c;
14312855Sgabeblack@google.com    const sc_signal<bool>& d;
14412855Sgabeblack@google.com
14512855Sgabeblack@google.com    int count;
14612855Sgabeblack@google.com    sync1( sc_module_name NAME,
14712855Sgabeblack@google.com           sc_clock& CLK,
14812855Sgabeblack@google.com           sc_signal<bool>& A,
14912855Sgabeblack@google.com           sc_signal<bool>& B,
15012855Sgabeblack@google.com           const sc_signal<bool>& C,
15112855Sgabeblack@google.com           const sc_signal<bool>& D )
15212855Sgabeblack@google.com        :
15312855Sgabeblack@google.com          a(A), b(B), c(C), d(D)
15412855Sgabeblack@google.com
15512855Sgabeblack@google.com    {
15612855Sgabeblack@google.com        clk(CLK);
15712855Sgabeblack@google.com		SC_CTHREAD( entry, clk.pos() );
15812855Sgabeblack@google.com        count = 0;
15912855Sgabeblack@google.com    }
16012855Sgabeblack@google.com    void entry();
16112855Sgabeblack@google.com};
16212855Sgabeblack@google.com
16312855Sgabeblack@google.comvoid
16412855Sgabeblack@google.comsync1::entry()
16512855Sgabeblack@google.com{
16612855Sgabeblack@google.com    while (true) {
16712855Sgabeblack@google.com        a = (val1[count % (sizeof(val1)/sizeof(val1[0]))] & 1);
16812855Sgabeblack@google.com        b = (val2[count % (sizeof(val2)/sizeof(val2[0]))] & 1);
16912855Sgabeblack@google.com        count++;
17012855Sgabeblack@google.com        wait();
17112855Sgabeblack@google.com        cout << "  a =  " << a;
17212855Sgabeblack@google.com        cout << "  b =  " << b;
17312855Sgabeblack@google.com        cout << "  c =  " << c;
17412855Sgabeblack@google.com        cout << "  d =  " << d << endl;
17512855Sgabeblack@google.com    }
17612855Sgabeblack@google.com}
17712855Sgabeblack@google.com
17812855Sgabeblack@google.com
17912855Sgabeblack@google.com
18012855Sgabeblack@google.comint
18112855Sgabeblack@google.comsc_main(int argc, char** argv)
18212855Sgabeblack@google.com{
18312855Sgabeblack@google.com    sc_clock clk("clk");
18412855Sgabeblack@google.com    sc_signal<bool> a("a");
18512855Sgabeblack@google.com    sc_signal<bool> b("b");
18612855Sgabeblack@google.com    sc_signal<bool> c("c");
18712855Sgabeblack@google.com    sc_signal<bool> d("d");
18812855Sgabeblack@google.com
18912855Sgabeblack@google.com    a = 0;
19012855Sgabeblack@google.com    b = 0;
19112855Sgabeblack@google.com    c = 0;
19212855Sgabeblack@google.com    d = 0;
19312855Sgabeblack@google.com
19412855Sgabeblack@google.com    aproc1 p1("p1", a, b, c);
19512855Sgabeblack@google.com    aproc2 p2("p2", a, b, d);
19612855Sgabeblack@google.com    sync1  s1("s1", clk, a, b, c, d);
19712855Sgabeblack@google.com
19812855Sgabeblack@google.com    sc_start(2000, SC_NS);
19912855Sgabeblack@google.com    return 0;
20012855Sgabeblack@google.com}
201