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  test09.cpp -- Test for hierarchical reset, try/catch and individual kill
2312855Sgabeblack@google.com                processes
2412855Sgabeblack@google.com
2512855Sgabeblack@google.com  Original Author: Andy Goodrich
2612855Sgabeblack@google.com
2712855Sgabeblack@google.com *****************************************************************************/
2812855Sgabeblack@google.com
2912855Sgabeblack@google.com/*****************************************************************************
3012855Sgabeblack@google.com
3112855Sgabeblack@google.com  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
3212855Sgabeblack@google.com  changes you are making here.
3312855Sgabeblack@google.com
3412855Sgabeblack@google.com      Name, Affiliation, Date:
3512855Sgabeblack@google.com  Description of Modification:
3612855Sgabeblack@google.com
3712855Sgabeblack@google.com *****************************************************************************/
3812855Sgabeblack@google.com// $Log: test09.cpp,v $
3912855Sgabeblack@google.com// Revision 1.4  2011/02/01 17:17:40  acg
4012855Sgabeblack@google.com//  Andy Goodrich: update of copyright notice, added visible CVS logging.
4112855Sgabeblack@google.com//
4212855Sgabeblack@google.com// Revision 1.3  2011/01/14 14:23:46  acg
4312855Sgabeblack@google.com//  Andy Goodrich: Fixes for 1666_2011
4412855Sgabeblack@google.com//
4512855Sgabeblack@google.com// Revision 1.2  2009/10/14 19:13:27  acg
4612855Sgabeblack@google.com//  Andy Goodrich: changes for SystemC 2.3
4712855Sgabeblack@google.com//
4812855Sgabeblack@google.com// Revision 1.1.1.1  2006/12/15 20:26:03  acg
4912855Sgabeblack@google.com// systemc_tests-2.3
5012855Sgabeblack@google.com//
5112855Sgabeblack@google.com// Revision 1.1  2006/04/17 20:10:04  acg
5212855Sgabeblack@google.com//  Andy Goodrich: first inclusion of test for expanded process support.
5312855Sgabeblack@google.com//
5412855Sgabeblack@google.com
5512855Sgabeblack@google.com
5612855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES
5712855Sgabeblack@google.com#include "systemc.h"
5812855Sgabeblack@google.com
5912855Sgabeblack@google.comSC_MODULE(DUT)
6012855Sgabeblack@google.com{
6112855Sgabeblack@google.com    SC_CTOR(DUT)
6212855Sgabeblack@google.com    {
6312855Sgabeblack@google.com        SC_CTHREAD(stimulus,m_clk.pos());
6412855Sgabeblack@google.com        reset_signal_is(m_reset, true);
6512855Sgabeblack@google.com        SC_THREAD(grand_parent);
6612855Sgabeblack@google.com        sensitive << m_clk.pos();
6712855Sgabeblack@google.com    }
6812855Sgabeblack@google.com
6912855Sgabeblack@google.com    void child()
7012855Sgabeblack@google.com    {
7112855Sgabeblack@google.com        sc_process_handle my_handle = sc_get_current_process_handle();
7212855Sgabeblack@google.com        cout << sc_time_stamp() << " " << my_handle.name()
7312855Sgabeblack@google.com             << " initialization" << endl;
7412855Sgabeblack@google.com        try {
7512855Sgabeblack@google.com            for (;;)
7612855Sgabeblack@google.com            {
7712855Sgabeblack@google.com                wait();
7812855Sgabeblack@google.com            }
7912855Sgabeblack@google.com        }
8012855Sgabeblack@google.com        catch(sc_core::sc_unwind_exception& ex)
8112855Sgabeblack@google.com        {
8212855Sgabeblack@google.com	    if ( !ex.is_reset() )
8312855Sgabeblack@google.com	    {
8412855Sgabeblack@google.com		cout << sc_time_stamp() << " " << my_handle.name()
8512855Sgabeblack@google.com		     << " got kill" << endl;
8612855Sgabeblack@google.com	    }
8712855Sgabeblack@google.com	    throw ex;
8812855Sgabeblack@google.com        }
8912855Sgabeblack@google.com    }
9012855Sgabeblack@google.com
9112855Sgabeblack@google.com    void grand_parent()
9212855Sgabeblack@google.com    {
9312855Sgabeblack@google.com        static bool       initialize = true;
9412855Sgabeblack@google.com        cout << sc_time_stamp() << " " << "dut.grand_parent initialization"
9512855Sgabeblack@google.com             << endl;
9612855Sgabeblack@google.com        cout << endl;
9712855Sgabeblack@google.com        if ( initialize )
9812855Sgabeblack@google.com        {
9912855Sgabeblack@google.com            m_grand_parent_handle = sc_get_current_process_handle();
10012855Sgabeblack@google.com            sc_spawn( sc_bind(&DUT::parent1, this), "parent1" );
10112855Sgabeblack@google.com            sc_spawn( sc_bind(&DUT::parent2, this), "parent2" );
10212855Sgabeblack@google.com            initialize = false;
10312855Sgabeblack@google.com        }
10412855Sgabeblack@google.com
10512855Sgabeblack@google.com        for (;;)
10612855Sgabeblack@google.com        {
10712855Sgabeblack@google.com            wait();
10812855Sgabeblack@google.com        }
10912855Sgabeblack@google.com    }
11012855Sgabeblack@google.com
11112855Sgabeblack@google.com    void parent1()
11212855Sgabeblack@google.com    {
11312855Sgabeblack@google.com        static bool initialize = true;
11412855Sgabeblack@google.com        sc_process_handle m_child1;
11512855Sgabeblack@google.com        sc_process_handle m_child2;
11612855Sgabeblack@google.com        sc_process_handle m_child3;
11712855Sgabeblack@google.com        sc_process_handle my_handle = sc_get_current_process_handle();
11812855Sgabeblack@google.com        cout << sc_time_stamp() << " " << my_handle.name()
11912855Sgabeblack@google.com             << " initialization" << endl;
12012855Sgabeblack@google.com        if ( initialize )
12112855Sgabeblack@google.com        {
12212855Sgabeblack@google.com            m_child1 = sc_spawn( sc_bind(&DUT::child, this), "child1" );
12312855Sgabeblack@google.com            m_child2 = sc_spawn( sc_bind(&DUT::child, this), "child2" );
12412855Sgabeblack@google.com            m_child3 = sc_spawn( sc_bind(&DUT::child, this), "child3" );
12512855Sgabeblack@google.com            initialize = false;
12612855Sgabeblack@google.com        }
12712855Sgabeblack@google.com
12812855Sgabeblack@google.com        for (;;)
12912855Sgabeblack@google.com        {
13012855Sgabeblack@google.com            wait();
13112855Sgabeblack@google.com        }
13212855Sgabeblack@google.com    }
13312855Sgabeblack@google.com
13412855Sgabeblack@google.com    void parent2()
13512855Sgabeblack@google.com    {
13612855Sgabeblack@google.com        sc_process_handle m_child1;
13712855Sgabeblack@google.com        sc_process_handle m_child2;
13812855Sgabeblack@google.com        sc_process_handle m_child3;
13912855Sgabeblack@google.com        sc_process_handle my_handle;
14012855Sgabeblack@google.com        for (;;)
14112855Sgabeblack@google.com        {
14212855Sgabeblack@google.com            try
14312855Sgabeblack@google.com            {
14412855Sgabeblack@google.com                my_handle = sc_get_current_process_handle();
14512855Sgabeblack@google.com                cout << sc_time_stamp() << " " << my_handle.name()
14612855Sgabeblack@google.com                     << " initialization" << endl;
14712855Sgabeblack@google.com                m_child1 = sc_spawn( sc_bind(&DUT::child, this), "child1" );
14812855Sgabeblack@google.com                m_child2 = sc_spawn( sc_bind(&DUT::child, this), "child2" );
14912855Sgabeblack@google.com                m_child3 = sc_spawn( sc_bind(&DUT::child, this), "child3" );
15012855Sgabeblack@google.com
15112855Sgabeblack@google.com                for (;;)
15212855Sgabeblack@google.com                {
15312855Sgabeblack@google.com                    wait();
15412855Sgabeblack@google.com                }
15512855Sgabeblack@google.com            }
15612855Sgabeblack@google.com            catch ( sc_core::sc_unwind_exception& ex )
15712855Sgabeblack@google.com            {
15812855Sgabeblack@google.com		if ( ex.is_reset() )
15912855Sgabeblack@google.com		{
16012855Sgabeblack@google.com		    cout << sc_time_stamp() << " " << my_handle.name()
16112855Sgabeblack@google.com			 << " removing children" << endl;
16212855Sgabeblack@google.com		    m_child1.kill();
16312855Sgabeblack@google.com		    m_child2.kill();
16412855Sgabeblack@google.com		    m_child3.kill();
16512855Sgabeblack@google.com		}
16612855Sgabeblack@google.com		throw ex;
16712855Sgabeblack@google.com            }
16812855Sgabeblack@google.com        }
16912855Sgabeblack@google.com    }
17012855Sgabeblack@google.com
17112855Sgabeblack@google.com    void stimulus()
17212855Sgabeblack@google.com    {
17312855Sgabeblack@google.com        for (;;)
17412855Sgabeblack@google.com        {
17512855Sgabeblack@google.com            wait();
17612855Sgabeblack@google.com            wait();
17712855Sgabeblack@google.com            wait();
17812855Sgabeblack@google.com            wait();
17912855Sgabeblack@google.com	    cout << sc_time_stamp() << " stimulus issuing reset" << endl;
18012855Sgabeblack@google.com            m_grand_parent_handle.reset(SC_INCLUDE_DESCENDANTS);
18112855Sgabeblack@google.com        }
18212855Sgabeblack@google.com    }
18312855Sgabeblack@google.com
18412855Sgabeblack@google.com    sc_in<bool>       m_clk;
18512855Sgabeblack@google.com    sc_process_handle m_grand_parent_handle;
18612855Sgabeblack@google.com    sc_in<bool>       m_reset;
18712855Sgabeblack@google.com};
18812855Sgabeblack@google.com
18912855Sgabeblack@google.comint sc_main(int argc, char* argv[])
19012855Sgabeblack@google.com{
19112855Sgabeblack@google.com    sc_clock        clock;
19212855Sgabeblack@google.com    DUT             dut("dut");
19312855Sgabeblack@google.com    sc_signal<bool> reset;
19412855Sgabeblack@google.com
19512855Sgabeblack@google.com    dut.m_clk(clock);
19612855Sgabeblack@google.com    dut.m_reset(reset);
19712855Sgabeblack@google.com
19812855Sgabeblack@google.com    reset = true;
19912855Sgabeblack@google.com    sc_start(1, SC_NS);
20012855Sgabeblack@google.com    reset = false;
20112855Sgabeblack@google.com    sc_start(20, SC_NS);
20212855Sgabeblack@google.com
20312855Sgabeblack@google.com    cout << "Program completed" << endl;
20412855Sgabeblack@google.com    return 0;
20512855Sgabeblack@google.com}
206