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// disable_enable.cpp -- test for
21//
22//  Original Author: John Aynsley, Doulos Inc.
23//
24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
25//
26// $Log: disable_enable.cpp,v $
27// Revision 1.2  2011/05/08 19:18:46  acg
28//  Andy Goodrich: remove extraneous + prefixes from git diff.
29//
30
31// disable() should take effect only the next evaluation phase
32
33#define SC_INCLUDE_DYNAMIC_PROCESSES
34
35#include <systemc>
36
37using namespace sc_core;
38using namespace std;
39
40struct Top: sc_module
41{
42  Top(sc_module_name _name)
43  : count(0)
44  {
45    SC_THREAD(control);
46    SC_THREAD(target);
47      t = sc_get_current_process_handle();
48
49    f0 = f1 = f2 = f3 = f4 = f5 = 0;
50  }
51
52  sc_process_handle t;
53  sc_event ev;
54  int count;
55  int f0, f1, f2, f3, f4, f5;
56
57  void control()
58  {
59    wait(SC_ZERO_TIME);
60
61    count = 1;
62    ev.notify();
63    wait(10, SC_NS);
64
65    count = 2;
66    ev.notify();
67    t.disable();
68    wait(SC_ZERO_TIME);
69
70    count = 3;
71    ev.notify();
72    wait(SC_ZERO_TIME);
73
74    count = 4;
75    t.enable();
76    ev.notify();
77    wait(10, SC_NS);
78
79    count = 5;
80    t.disable();
81    t.reset();
82    wait(10, SC_NS);
83
84    count = 6;
85    t.reset();
86    wait(10, SC_NS);
87
88    sc_stop();
89  }
90
91  void target()
92  {
93    //cout << "Target called at " << sc_time_stamp() << " with count = " << count << endl;
94    switch(count)
95    {
96        case  0: sc_assert(sc_time_stamp() == sc_time( 0, SC_NS)); f0 = 1; break;
97        case  5: sc_assert(sc_time_stamp() == sc_time(20, SC_NS)); f4 = 1; break;
98        case  6: sc_assert(sc_time_stamp() == sc_time(30, SC_NS)); f5 = 1; break;
99        default: sc_assert(false);
100    }
101    for (;;)
102    {
103      wait(ev);
104      //cout << "Target awoke at " << sc_time_stamp() << " with count = " << count << endl;
105      switch(count)
106      {
107        case  1: sc_assert(sc_time_stamp() == sc_time( 0, SC_NS)); f1 = 1; break;
108        case  2: sc_assert(sc_time_stamp() == sc_time(10, SC_NS)); f2 = 1; break;
109        case  4: sc_assert(sc_time_stamp() == sc_time(10, SC_NS)); f3 = 1; break;
110        default: sc_assert(false);
111      }
112    }
113  }
114
115  SC_HAS_PROCESS(Top);
116};
117
118int sc_main(int argc, char* argv[])
119{
120  Top top("top");
121
122  sc_start();
123
124  sc_assert( top.f0 );
125  sc_assert( top.f1 );
126  sc_assert( top.f2 );
127  sc_assert( top.f3 );
128  sc_assert( top.f4 );
129  sc_assert( top.f5 );
130  /*
131  */
132  cout << endl << "Success" << endl;
133  return 0;
134}
135
136