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// test02.cpp -- Test Method Suspending Itself
21//
22//  Original Author: John Aynsley, Doulos
23//
24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
25//
26// $Log: test02.cpp,v $
27// Revision 1.3  2011/03/07 19:32:19  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.2  2011/02/20 13:44:06  acg
32//  Andy Goodrich: updates for IEEE 1666 2011.
33//
34// Revision 1.1  2011/02/05 21:13:26  acg
35//  Andy Goodrich: move of tests John Aynsley will replace.
36//
37// Revision 1.1  2011/01/20 16:54:54  acg
38//  Andy Goodrich: changes for IEEE 1666 2011.
39//
40
41#define SC_INCLUDE_DYNAMIC_PROCESSES
42
43#include <systemc>
44
45using namespace sc_core;
46using std::cout;
47using std::endl;
48
49struct M5: sc_module
50{
51  M5(sc_module_name _name)
52  {
53    SC_THREAD(ticker);
54    SC_THREAD(calling);
55    SC_METHOD(target);
56      sensitive << ev;
57      dont_initialize();
58      t = sc_get_current_process_handle();
59    suspend_target = false;
60    resume_target = false;
61  }
62
63  sc_process_handle t;
64  sc_event ev;
65  bool suspend_target;
66  bool resume_target;
67
68  void ticker()
69  {
70    for (;;)
71    {
72      wait(10, SC_NS);
73      ev.notify();
74    }
75  }
76
77  void calling()
78  {
79    wait(15, SC_NS);
80    // Target runs at 10 NS
81
82    suspend_target = true;
83    wait(10, SC_NS);
84    // Target runs at 20 NS and suspends itself
85
86    wait(10, SC_NS);
87    // Target does not run at 30 NS
88
89    suspend_target = false;
90    t.resume();
91    // Target runs at 35 NS
92
93    wait(10, SC_NS);
94    // Target runs at 40 NS
95
96    suspend_target = true;
97    resume_target = true;
98    wait(10, SC_NS);
99    // Target runs at 50 NS
100
101    sc_stop();
102  }
103
104  void target()
105  {
106    cout << "Target called at " << sc_time_stamp() << endl;
107    if (suspend_target)
108      t.suspend();
109    if (resume_target)
110    {
111      t.resume();
112      suspend_target = false;
113    }
114  }
115
116  SC_HAS_PROCESS(M5);
117};
118
119int sc_main(int argc, char* argv[])
120{
121  M5 m("m");
122
123  sc_core::sc_allow_process_control_corners = true;
124  sc_start();
125
126  return 0;
127}
128
129