test01.cpp revision 12855:588919e0e4aa
1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20// test01.cpp -- Quick Test Of Process Control On Threads For IEEE 1666-2011
21//
22//  Original Author: John Aynsley, Doulos
23//
24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
25//
26// $Log: test01.cpp,v $
27// Revision 1.2  2011/03/07 19:32:18  acg
28//  Andy Goodrich: addition to set sc_core::sc_allow_process_control_corners
29//  to true so that this test avoids corner case error messages.
30//
31// Revision 1.1  2011/02/05 21:13:19  acg
32//  Andy Goodrich: move of tests John Aynsley will replace.
33//
34// Revision 1.1  2011/01/14 14:23:16  acg
35//  Andy Goodrich: new test.
36//
37
38#define SC_INCLUDE_DYNAMIC_PROCESSES
39#include <systemc>
40
41using namespace sc_core;
42using std::cout;
43using std::endl;
44
45SC_MODULE(Top)
46{
47  SC_CTOR(Top)
48  {
49    SC_THREAD(gen);
50    SC_THREAD(T1);
51      h1 = sc_get_current_process_handle();
52    SC_THREAD(T2);
53      h2 = sc_get_current_process_handle();
54  }
55
56  sc_event ev;
57
58  sc_process_handle h1, h2;
59
60  void gen()
61  {
62    for (;;)
63    {
64      wait(10, SC_NS);
65      ev.notify();
66    }
67  }
68
69  void T1()
70  {
71    wait(25, SC_NS);
72    cout << "suspend: time = " << sc_time_stamp() << endl;
73    h2.suspend();
74    wait(20, SC_NS);
75    cout << "resume: time = " << sc_time_stamp() << endl;
76    h2.resume();
77    wait(20, SC_NS);
78
79    cout << "disable: time = " << sc_time_stamp() << endl;
80    h2.disable();
81    wait(20, SC_NS);
82    cout << "enable: time = " << sc_time_stamp() << endl;
83    h2.enable();
84    wait(20, SC_NS);
85    sc_stop();
86  }
87
88  void T2()
89  {
90    for (;;)
91    {
92      wait(ev);
93      cout << "T2: time = " << sc_time_stamp() << endl;
94    }
95  }
96};
97
98int sc_main(int argc, char* argv[])
99{
100  Top top("top");
101  sc_core::sc_allow_process_control_corners = true;
102  sc_start();
103
104  cout << endl << "End Of Test" << endl;
105  return 0;
106}
107