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// test04.cpp -- Quick Test Of Synchronous Reset sc_process_handle Support
21//
22//  Original Author: John Aynsley, Doulos
23//
24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
25//
26// $Log: test04.cpp,v $
27// Revision 1.1  2011/02/05 21:13:26  acg
28//  Andy Goodrich: move of tests John Aynsley will replace.
29//
30// Revision 1.1  2011/01/20 16:55:07  acg
31//  Andy Goodrich: changes for IEEE 1666 2011.
32//
33
34#define SC_INCLUDE_DYNAMIC_PROCESSES
35
36#include <systemc>
37
38using namespace sc_core;
39using std::cout;
40using std::endl;
41
42struct M: sc_module
43{
44  M(sc_module_name _name)
45  {
46    SC_THREAD(ticker);
47    SC_THREAD(calling);
48    SC_THREAD(target);
49      t = sc_get_current_process_handle();
50  }
51
52  sc_process_handle t;
53  sc_event ev;
54
55  void ticker()
56  {
57    for (;;)
58    {
59      wait(10, SC_NS);
60      ev.notify();
61    }
62  }
63
64  void calling()
65  {
66    wait(15, SC_NS);
67    // Target runs at time 10 NS due to notification
68
69    t.sync_reset_on();
70    // Target does not run at time 15 NS
71
72    wait(10, SC_NS);
73    // Target is reset at time 20 NS due to notification
74
75    wait(10, SC_NS);
76    // Target is reset again at time 30 NS due to notification
77
78    t.sync_reset_off();
79    // Target does not run at time 35 NS
80
81    wait(10, SC_NS);
82    // Target runs at time 40 NS due to notification
83
84    sc_stop();
85  }
86
87  void target()
88  {
89    cout << "Target called/reset at " << sc_time_stamp() << endl;
90    for (;;)
91    {
92      wait(ev);
93      cout << "Target awoke at " << sc_time_stamp() << endl;
94    }
95  }
96
97  SC_HAS_PROCESS(M);
98};
99
100int sc_main(int argc, char* argv[])
101{
102  M m("m");
103
104  sc_start();
105
106  return 0;
107}
108
109