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  test01.cpp -- Test of suspend resume on processes
2312855Sgabeblack@google.com
2412855Sgabeblack@google.com  Original Author: Andy Goodrich
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  Revision log at end of the file to let __LINE__ give the same results
3712855Sgabeblack@google.com  after a check-in.
3812855Sgabeblack@google.com *****************************************************************************/
3912855Sgabeblack@google.com
4012855Sgabeblack@google.com
4112855Sgabeblack@google.com#include "systemc.h"
4212855Sgabeblack@google.com
4312855Sgabeblack@google.comSC_MODULE(DUT)
4412855Sgabeblack@google.com{
4512855Sgabeblack@google.com    SC_CTOR(DUT)
4612855Sgabeblack@google.com    {
4712855Sgabeblack@google.com        SC_CTHREAD(cthread,m_clk.pos());
4812855Sgabeblack@google.com        SC_METHOD(dynamic_method);
4912855Sgabeblack@google.com        SC_THREAD(dynamic_thread);
5012855Sgabeblack@google.com        SC_METHOD(static_method);
5112855Sgabeblack@google.com        sensitive << m_clk.pos();
5212855Sgabeblack@google.com        SC_THREAD(static_thread);
5312855Sgabeblack@google.com        sensitive << m_clk.pos();
5412855Sgabeblack@google.com        SC_CTHREAD(stimulus,m_clk.pos());
5512855Sgabeblack@google.com        reset_signal_is(m_reset, true);
5612855Sgabeblack@google.com    }
5712855Sgabeblack@google.com    void cthread()
5812855Sgabeblack@google.com    {
5912855Sgabeblack@google.com        m_cthread = sc_get_current_process_handle();
6012855Sgabeblack@google.com        for (;;)
6112855Sgabeblack@google.com        {
6212855Sgabeblack@google.com            wait();
6312855Sgabeblack@google.com            cout << sc_time_stamp() << ":      cthread (" << __LINE__ << ")"
6412855Sgabeblack@google.com                 << endl;
6512855Sgabeblack@google.com        }
6612855Sgabeblack@google.com    }
6712855Sgabeblack@google.com    void dynamic_method()
6812855Sgabeblack@google.com    {
6912855Sgabeblack@google.com        static int state = 0;
7012855Sgabeblack@google.com        switch ( state )
7112855Sgabeblack@google.com        {
7212855Sgabeblack@google.com          case 0:
7312855Sgabeblack@google.com            m_dynamic_method = sc_get_current_process_handle();
7412855Sgabeblack@google.com            next_trigger( m_clk.posedge_event() );
7512855Sgabeblack@google.com            cout << sc_time_stamp() << ":      dynamic method (" << __LINE__
7612855Sgabeblack@google.com                 << "," << state << ") initialization call " << endl;
7712855Sgabeblack@google.com            break;
7812855Sgabeblack@google.com          case 1:
7912855Sgabeblack@google.com            next_trigger( m_clk.posedge_event() );
8012855Sgabeblack@google.com            cout << sc_time_stamp() << ":      dynamic method (" << __LINE__
8112855Sgabeblack@google.com                 << "," << state << ") after wait on m_clk.posedge_event() "
8212855Sgabeblack@google.com                 << endl;
8312855Sgabeblack@google.com            break;
8412855Sgabeblack@google.com          case 2:
8512855Sgabeblack@google.com            next_trigger( m_clk.negedge_event() );
8612855Sgabeblack@google.com            cout << sc_time_stamp() << ":      dynamic method (" << __LINE__
8712855Sgabeblack@google.com                 << "," << state << ") after wait on m_clk.posedge_event() "
8812855Sgabeblack@google.com                 << endl;
8912855Sgabeblack@google.com            break;
9012855Sgabeblack@google.com          case 3:
9112855Sgabeblack@google.com            next_trigger( m_event1 & m_event2 );
9212855Sgabeblack@google.com            cout << sc_time_stamp() << ":      dynamic method (" << __LINE__
9312855Sgabeblack@google.com                 << "," << state << ") after wait on m_clk.negedge() " << endl;
9412855Sgabeblack@google.com            break;
9512855Sgabeblack@google.com          case 4:
9612855Sgabeblack@google.com            next_trigger( m_clk.posedge_event() );
9712855Sgabeblack@google.com            cout << sc_time_stamp() << ":      dynamic method (" << __LINE__
9812855Sgabeblack@google.com                 << "," << state << ") after wait on m_event1 & m_event2 "
9912855Sgabeblack@google.com                 << endl;
10012855Sgabeblack@google.com            break;
10112855Sgabeblack@google.com          default:
10212855Sgabeblack@google.com            next_trigger( m_clk.posedge_event() );
10312855Sgabeblack@google.com            cout << sc_time_stamp() << ":      dynamic method (" << __LINE__
10412855Sgabeblack@google.com                 << "," << state << ") after wait on m_clk.posedge_event() "
10512855Sgabeblack@google.com                 << endl;
10612855Sgabeblack@google.com            break;
10712855Sgabeblack@google.com        }
10812855Sgabeblack@google.com        state = state + 1;
10912855Sgabeblack@google.com        if ( state == 5 ) state = 1;
11012855Sgabeblack@google.com    }
11112855Sgabeblack@google.com    void dynamic_thread()
11212855Sgabeblack@google.com    {
11312855Sgabeblack@google.com        m_dynamic_thread = sc_get_current_process_handle();
11412855Sgabeblack@google.com        cout << sc_time_stamp() << ":      dynamic thread (" << __LINE__ << ")"
11512855Sgabeblack@google.com             << " initialization call " << endl;
11612855Sgabeblack@google.com        wait(m_clk.posedge_event());
11712855Sgabeblack@google.com        for (;;)
11812855Sgabeblack@google.com        {
11912855Sgabeblack@google.com            cout << sc_time_stamp() << ":      dynamic thread (" << __LINE__
12012855Sgabeblack@google.com                 << ") after wait on m_clk.posedge_event() " << endl;
12112855Sgabeblack@google.com            wait(m_clk.posedge_event());
12212855Sgabeblack@google.com            cout << sc_time_stamp() << ":      dynamic thread (" << __LINE__
12312855Sgabeblack@google.com                 << ") after wait on m_clk.posedge_event() " << endl;
12412855Sgabeblack@google.com            wait(m_clk.negedge_event());
12512855Sgabeblack@google.com            cout << sc_time_stamp() << ":      dynamic thread (" << __LINE__
12612855Sgabeblack@google.com                 << ") after wait on m_clk.negedge_event() " << endl;
12712855Sgabeblack@google.com            wait(m_event1 & m_event2 );
12812855Sgabeblack@google.com            cout << sc_time_stamp() << ":      dynamic thread (" << __LINE__
12912855Sgabeblack@google.com                 << ") after wait on m_event1 & m_event2 " << endl;
13012855Sgabeblack@google.com            wait(m_clk.posedge_event());
13112855Sgabeblack@google.com        }
13212855Sgabeblack@google.com    }
13312855Sgabeblack@google.com    void static_method()
13412855Sgabeblack@google.com    {
13512855Sgabeblack@google.com        m_static_method = sc_get_current_process_handle();
13612855Sgabeblack@google.com        cout << sc_time_stamp() << ":      static method (" << __LINE__ << ")"
13712855Sgabeblack@google.com             << endl;
13812855Sgabeblack@google.com    }
13912855Sgabeblack@google.com    void static_thread()
14012855Sgabeblack@google.com    {
14112855Sgabeblack@google.com        m_static_thread = sc_get_current_process_handle();
14212855Sgabeblack@google.com        for (;;)
14312855Sgabeblack@google.com        {
14412855Sgabeblack@google.com            wait();
14512855Sgabeblack@google.com            cout << sc_time_stamp() << ":      static thread (" << __LINE__
14612855Sgabeblack@google.com                 << ")" << endl;
14712855Sgabeblack@google.com        }
14812855Sgabeblack@google.com    }
14912855Sgabeblack@google.com    void stimulus()
15012855Sgabeblack@google.com    {
15112855Sgabeblack@google.com        for (;;)
15212855Sgabeblack@google.com        {
15312855Sgabeblack@google.com            wait();
15412855Sgabeblack@google.com            wait();
15512855Sgabeblack@google.com            cout << sc_time_stamp() << ": stimulus ("
15612855Sgabeblack@google.com                 << __LINE__ << ") - suspending all processes" << endl;
15712855Sgabeblack@google.com            m_cthread.suspend();
15812855Sgabeblack@google.com            m_dynamic_method.suspend();
15912855Sgabeblack@google.com            m_dynamic_thread.suspend();
16012855Sgabeblack@google.com            m_static_method.suspend();
16112855Sgabeblack@google.com            m_static_thread.suspend();
16212855Sgabeblack@google.com            wait();
16312855Sgabeblack@google.com            wait();
16412855Sgabeblack@google.com            wait();
16512855Sgabeblack@google.com            m_cthread.resume();
16612855Sgabeblack@google.com            m_dynamic_method.resume();
16712855Sgabeblack@google.com            m_dynamic_thread.resume();
16812855Sgabeblack@google.com            m_static_method.resume();
16912855Sgabeblack@google.com            m_static_thread.resume();
17012855Sgabeblack@google.com            cout << endl << sc_time_stamp() << ": stimulus ("
17112855Sgabeblack@google.com                 << __LINE__ << ") - resuming all processes" << endl;
17212855Sgabeblack@google.com            wait();
17312855Sgabeblack@google.com            cout << sc_time_stamp() << ": stimulus ("
17412855Sgabeblack@google.com                 << __LINE__ << ") - suspending all processes" << endl;
17512855Sgabeblack@google.com            m_cthread.suspend();
17612855Sgabeblack@google.com            m_dynamic_method.suspend();
17712855Sgabeblack@google.com            m_dynamic_thread.suspend();
17812855Sgabeblack@google.com            m_static_method.suspend();
17912855Sgabeblack@google.com            m_static_thread.suspend();
18012855Sgabeblack@google.com            wait();
18112855Sgabeblack@google.com            m_event1.notify(SC_ZERO_TIME);
18212855Sgabeblack@google.com            cout << sc_time_stamp() << ": stimulus ("
18312855Sgabeblack@google.com                 << __LINE__ << ") - firing event1 " << endl;
18412855Sgabeblack@google.com            wait();
18512855Sgabeblack@google.com            m_cthread.resume();
18612855Sgabeblack@google.com            m_dynamic_method.resume();
18712855Sgabeblack@google.com            m_dynamic_thread.resume();
18812855Sgabeblack@google.com            m_static_method.resume();
18912855Sgabeblack@google.com            m_static_thread.resume();
19012855Sgabeblack@google.com            cout << endl << sc_time_stamp() << ": stimulus ("
19112855Sgabeblack@google.com                 << __LINE__ << ") - resuming all processes" << endl;
19212855Sgabeblack@google.com            wait();
19312855Sgabeblack@google.com            m_event2.notify(SC_ZERO_TIME);
19412855Sgabeblack@google.com            cout << sc_time_stamp() << ": stimulus ("
19512855Sgabeblack@google.com                 << __LINE__ << ") - firing event2 " << endl;
19612855Sgabeblack@google.com            wait();
19712855Sgabeblack@google.com            wait();
19812855Sgabeblack@google.com            wait();
19912855Sgabeblack@google.com        }
20012855Sgabeblack@google.com    }
20112855Sgabeblack@google.com    sc_in<bool>       m_clk;
20212855Sgabeblack@google.com    sc_process_handle m_cthread;
20312855Sgabeblack@google.com    sc_process_handle m_dynamic_method;
20412855Sgabeblack@google.com    sc_process_handle m_dynamic_thread;
20512855Sgabeblack@google.com    sc_event          m_event1;
20612855Sgabeblack@google.com    sc_event          m_event2;
20712855Sgabeblack@google.com    sc_event          m_event3;
20812855Sgabeblack@google.com    sc_event          m_event4;
20912855Sgabeblack@google.com    sc_in<bool>       m_reset;
21012855Sgabeblack@google.com    sc_process_handle m_static_method;
21112855Sgabeblack@google.com    sc_process_handle m_static_thread;
21212855Sgabeblack@google.com};
21312855Sgabeblack@google.com
21412855Sgabeblack@google.comint sc_main(int argc, char* argv[])
21512855Sgabeblack@google.com{
21612855Sgabeblack@google.com    sc_core::sc_allow_process_control_corners = true;
21712855Sgabeblack@google.com    sc_clock        clock;
21812855Sgabeblack@google.com    DUT             dut("dut");
21912855Sgabeblack@google.com    sc_signal<bool> reset;
22012855Sgabeblack@google.com
22112855Sgabeblack@google.com    dut.m_clk(clock);
22212855Sgabeblack@google.com    dut.m_reset(reset);
22312855Sgabeblack@google.com
22412855Sgabeblack@google.com    sc_core::sc_allow_process_control_corners = true;
22512855Sgabeblack@google.com    reset = true;
22612855Sgabeblack@google.com    sc_start(1, SC_NS);
22712855Sgabeblack@google.com    reset = false;
22812855Sgabeblack@google.com    sc_start(21, SC_NS);
22912855Sgabeblack@google.com
23012855Sgabeblack@google.com    cout << "Program completed" << endl;
23112855Sgabeblack@google.com    return 0;
23212855Sgabeblack@google.com}
23312855Sgabeblack@google.com
23412855Sgabeblack@google.com// $Log: test01.cpp,v $
23512855Sgabeblack@google.com// Revision 1.5  2011/04/02 00:08:23  acg
23612855Sgabeblack@google.com//  Andy Goodrich: turn off corner case error checking.
23712855Sgabeblack@google.com//
23812855Sgabeblack@google.com// Revision 1.4  2011/03/07 19:32:10  acg
23912855Sgabeblack@google.com//  Andy Goodrich: addition to set sc_core::sc_allow_process_control_corners
24012855Sgabeblack@google.com//  to true so that this test avoids corner case error messages.
24112855Sgabeblack@google.com//
24212855Sgabeblack@google.com// Revision 1.3  2011/02/20 13:43:54  acg
24312855Sgabeblack@google.com//  Andy Goodrich: updates for IEEE 1666 2011.
24412855Sgabeblack@google.com//
24512855Sgabeblack@google.com// Revision 1.2  2011/02/14 16:59:58  acg
24612855Sgabeblack@google.com//  Andy Goodrich: updated copyright and added cvs logging information inline.
24712855Sgabeblack@google.com//
24812855Sgabeblack@google.com// Revision 1.1.1.1  2006/12/15 20:26:03  acg
24912855Sgabeblack@google.com// systemc_tests-2.3
25012855Sgabeblack@google.com//
25112855Sgabeblack@google.com// Revision 1.1  2006/12/14 21:39:59  acg
25212855Sgabeblack@google.com//  Andy Goodrich: moving test to new directory.
25312855Sgabeblack@google.com//
25412855Sgabeblack@google.com// Revision 1.2  2006/04/20 19:43:31  acg
25512855Sgabeblack@google.com//  Andy Goodrich: moved CVS log to end of file so that __LINE__ does not
25612855Sgabeblack@google.com//  change when a checkin is done.
25712855Sgabeblack@google.com//
25812855Sgabeblack@google.com// Revision 1.1  2006/04/17 20:10:55  acg
25912855Sgabeblack@google.com//  Andy Goodrich: First inclusion of test for suspend and resume support.
26012855Sgabeblack@google.com//
261