test05.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/*****************************************************************************
21
22  test05.cpp -- Test reset_signal_is() and async_reset_signal_is() usage.
23
24  Original Author: Andy Goodrich, Forte Design Systems, 14 December 2006
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38#define SC_INCLUDE_DYNAMIC_PROCESSES
39#include "systemc.h"
40
41SC_MODULE(DUT)
42{
43    SC_CTOR(DUT)
44    {
45        SC_CTHREAD(creator,m_clk.pos());
46        SC_CTHREAD(resetter,m_clk.neg());
47
48        // SET UP STATICALLY DEFINED PROCESSES:
49
50        SC_CTHREAD(static_cthread,m_clk.pos());
51        async_reset_signal_is(m_areset,true);
52        reset_signal_is(m_sreset,true);
53        SC_METHOD(static_method);
54        reset_signal_is(m_areset,true);
55        SC_THREAD(static_thread_clocked);
56        sensitive << m_clk.pos();
57        dont_initialize();
58        async_reset_signal_is(m_areset,true);
59        reset_signal_is(m_sreset,true);
60        SC_THREAD(static_thread_event);
61        async_reset_signal_is(m_areset,true);
62        reset_signal_is(m_sreset,true);
63        SC_THREAD(static_thread_timed);
64        async_reset_signal_is(m_areset,true);
65        reset_signal_is(m_sreset,true);
66    }
67
68    // creator - create the dynamic processes after the start of simulation:
69    void creator()
70    {
71        sc_spawn_options options_method;
72        sc_spawn_options options_thread_clocked;
73        sc_spawn_options options_thread_event;
74        sc_spawn_options options_thread_timed;
75
76        wait(1);
77
78        options_method.reset_signal_is( m_areset, true );
79        options_method.spawn_method();
80        sc_spawn( sc_bind(&DUT::dynamic_method, this), "dynamic_method",
81            &options_method);
82
83        options_thread_clocked.async_reset_signal_is( m_areset, true );
84        options_thread_clocked.reset_signal_is( m_sreset, true );
85        options_thread_clocked.set_sensitivity( &m_clk.posedge_event() );
86        sc_spawn( sc_bind(&DUT::dynamic_thread_clocked, this),
87            "dynamic_thread_clocked", &options_thread_clocked);
88
89        options_thread_event.async_reset_signal_is( m_areset, true );
90        options_thread_event.reset_signal_is( m_sreset, true );
91        sc_spawn( sc_bind(&DUT::dynamic_thread_event, this),
92            "dynamic_thread_event", &options_thread_event);
93
94        options_thread_timed.async_reset_signal_is( m_areset, true );
95        options_thread_timed.reset_signal_is( m_sreset, true );
96        sc_spawn( sc_bind(&DUT::dynamic_thread_timed, this),
97            "dynamic_thread_timed", &options_thread_timed);
98
99    }
100
101    void dynamic_method()
102    {
103        cout << sc_time_stamp() << " ... dynamic method" << endl;
104        next_trigger(m_non_event);
105    }
106
107    void dynamic_thread_clocked()
108    {
109        cout << sc_time_stamp() << " ... dynamic thread clocked" << endl;
110        for (;;)
111        {
112            wait();
113        }
114    }
115
116    void dynamic_thread_event()
117    {
118        cout << sc_time_stamp() << " ... dynamic thread event wait" << endl;
119        for (;;)
120        {
121            wait(m_non_event);
122        }
123    }
124
125    void dynamic_thread_timed()
126    {
127        cout << sc_time_stamp() << " ... dynamic thread timed wait" << endl;
128        for (;;)
129        {
130            wait(1000, SC_NS);
131        }
132    }
133
134
135    void resetter()
136    {
137        for ( int wait_i = 1; wait_i < 3; wait_i++ )
138        {
139            wait(2);
140            cout << endl << sc_time_stamp() << " asserting asynchronous reset"
141                 << endl;
142            m_areset = true;
143            wait(wait_i);
144            cout << endl << sc_time_stamp() << " clearing asynchronous reset"
145                 << endl;
146            m_areset = false;
147            wait(2);
148            cout << endl << sc_time_stamp() << " asserting synchronous reset"
149                 << endl;
150            m_sreset = true;
151            wait(wait_i);
152            cout << endl << sc_time_stamp() << " clearing synchronous reset"
153                 << endl;
154            m_sreset = false;
155            wait(5);
156        }
157        cout << endl << sc_time_stamp() << " terminating simulation" << endl;
158        sc_stop();
159    }
160
161    void static_cthread()
162    {
163        cout << sc_time_stamp() << " ... static cthread" << endl;
164        for (;;)
165        {
166            wait();
167        }
168    }
169
170    void static_method()
171    {
172        cout << sc_time_stamp() << " ... static method" << endl;
173        next_trigger(m_non_event);
174    }
175
176    void static_thread_clocked()
177    {
178        cout << sc_time_stamp() << " ... static thread clocked" << endl;
179        for (;;)
180        {
181            wait();
182        }
183    }
184
185    void static_thread_event()
186    {
187        cout << sc_time_stamp() << " ... static thread event wait " << endl;
188        for (;;)
189        {
190            wait(m_non_event);
191        }
192    }
193
194    void static_thread_timed()
195    {
196        cout << sc_time_stamp() << " ... static thread timed wait " << endl;
197        for (;;)
198        {
199            wait(1000, SC_NS);
200        }
201    }
202
203    sc_signal<bool> m_areset;
204    sc_in<bool>     m_clk;
205    sc_event        m_non_event;
206    sc_signal<bool> m_sreset;
207};
208
209int sc_main(int argc, char* argv[])
210{
211    sc_clock        clock;
212    DUT             dut("dut");
213
214    dut.m_clk(clock);
215
216    sc_start();
217
218    cout << "Program completed" << endl;
219    return 0;
220}
221