proc_ctrl_priority.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// proc_ctrl_priority.cpp -- test for
21//
22//  Original Author: John Aynsley, Doulus
23//
24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
25//
26// $Log: proc_ctrl_priority.cpp,v $
27// Revision 1.3  2011/09/05 21:23:35  acg
28//  Philipp A. Hartmann: eliminate compiler warnings.
29//
30// Revision 1.2  2011/05/08 19:18:46  acg
31//  Andy Goodrich: remove extraneous + prefixes from git diff.
32//
33
34// Priority of process control methods suspend, disable, sync_reset_on, reset
35
36#define SC_INCLUDE_DYNAMIC_PROCESSES
37
38#include <systemc>
39
40using namespace sc_core;
41using std::cout;
42using std::endl;
43
44struct Top: sc_module
45{
46  Top(sc_module_name _name)
47  {
48    SC_THREAD(calling);
49
50    SC_THREAD(target);
51      t = sc_get_current_process_handle();
52
53    count = 0;
54    f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0;
55    f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0;
56    f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0;
57  }
58
59  sc_process_handle t;
60  sc_event ev;
61  int count;
62  bool target_awoke;
63  int f1, f2, f3, f4, f5, f6, f7, f8, f9;
64  int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19;
65  int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29;
66
67  void calling()
68  {
69    count = 0;
70    wait(SC_ZERO_TIME);
71
72    count = 1;
73    ev.notify(5, SC_NS);
74    wait(10, SC_NS);
75
76    count = 2;
77    ev.notify(5, SC_NS);
78    t.disable();
79    wait(10, SC_NS);
80
81    count = 3;
82    ev.notify(5, SC_NS);
83    t.disable();
84    t.disable(); // Dummy
85    t.resume();
86    t.resume();
87    t.sync_reset_off(); // Dummy
88    t.sync_reset_off(); // Dummy
89    wait(10, SC_NS);
90
91    count = 4;
92    ev.notify(5, SC_NS);
93    t.enable();
94    wait(10, SC_NS);
95
96    count = 5;
97    ev.notify(5, SC_NS);
98    t.enable(); // Dummy
99    t.enable(); // Dummy
100    t.sync_reset_off(); // Dummy
101    t.sync_reset_off(); // Dummy
102    wait(10, SC_NS);
103
104    count = 6;
105    ev.notify(5, SC_NS);
106    t.reset();
107    wait(SC_ZERO_TIME);
108
109    count = 7;
110    wait(sc_time(100, SC_NS) - sc_time_stamp());
111
112    count = 8;
113    ev.notify(5, SC_NS);
114    t.disable();
115    wait(10, SC_NS);
116
117    count = 9;
118    ev.notify(5, SC_NS);
119    t.reset();
120    wait(10, SC_NS);
121
122    count = 10;
123    ev.notify(5, SC_NS);
124    t.reset();
125    wait(10, SC_NS);
126
127    count = 11;
128    ev.notify(5, SC_NS);
129    t.enable();
130    wait(sc_time(200, SC_NS) - sc_time_stamp());
131
132    count = 12;
133    ev.notify(5, SC_NS);
134    t.suspend();
135    wait(10, SC_NS);
136
137    count = 13;
138    t.suspend(); // Dummy
139    t.suspend(); // Dummy
140    t.enable(); // Dummy
141    t.enable(); // Dummy
142    t.sync_reset_off(); // Dummy
143    t.sync_reset_off(); // Dummy
144    wait(10, SC_NS);
145
146    count = 14;
147    t.resume();
148    wait(10, SC_NS);
149
150    count = 15;
151    ev.notify(5, SC_NS);
152    t.resume(); // Dummy
153    t.resume(); // Dummy
154    t.enable(); // Dummy
155    t.enable(); // Dummy
156    t.sync_reset_off(); // Dummy
157    t.sync_reset_off(); // Dummy
158    wait(10, SC_NS);
159
160    count = 16;
161    ev.notify();
162    t.resume(); // Dummy
163    t.resume(); // Dummy
164    t.disable(); // Dummy
165    t.disable(); // Dummy
166    t.enable(); // Dummy
167    t.enable(); // Dummy
168    t.suspend();
169    wait(10, SC_NS);
170
171    count = 17;
172    t.suspend(); // Dummy
173    t.suspend(); // Dummy
174    t.enable(); // Dummy
175    t.enable(); // Dummy
176    t.sync_reset_off(); // Dummy
177    t.sync_reset_off(); // Dummy
178    wait(10, SC_NS);
179
180    count = 18;
181    t.resume();
182    wait(sc_time(300, SC_NS) - sc_time_stamp());
183
184    count = 19;
185    ev.notify();
186    ev.notify(5, SC_NS);
187    t.disable();
188    t.disable(); // Dummy
189    wait(5, SC_NS);
190    t.disable(); // Dummy
191    t.resume();
192    t.resume();
193    wait(5, SC_NS);
194
195    count = 20;
196    ev.notify(5, SC_NS);
197    t.enable();
198    t.enable(); // Dummy
199    wait(SC_ZERO_TIME);
200
201    count = 21;
202    wait(10, SC_NS);
203
204    count = 22;
205    ev.notify(5, SC_NS);
206    t.suspend();
207    wait(10, SC_NS);
208
209    count = 23;
210    t.reset();
211    ev.notify(5, SC_NS);
212    wait(10, SC_NS);
213
214    count = 24;
215    t.reset();
216    ev.notify(5, SC_NS);
217    wait(10, SC_NS);
218
219    count = 25;
220    t.resume();
221    wait(sc_time(400, SC_NS) - sc_time_stamp());
222
223    count = 26;
224    ev.notify();
225    t.reset();
226    wait(10, SC_NS);
227
228    count = 27;
229    ev.notify();
230    t.suspend();
231    wait(10, SC_NS);
232
233    count = 28;
234    t.reset();
235    wait(10, SC_NS);
236    t.resume();
237
238    wait(sc_time(500, SC_NS) - sc_time_stamp());
239
240    count = 29;
241    t.sync_reset_on();
242    t.sync_reset_on(); // Dummy
243    wait(10, SC_NS);
244
245    count = 30;
246    ev.notify();
247    wait(10, SC_NS);
248
249    count = 31;
250    t.resume(); // Dummy
251    t.resume(); // Dummy
252    t.enable(); // Dummy
253    t.enable(); // Dummy
254    t.sync_reset_on(); // Dummy
255    t.sync_reset_on(); // Dummy
256    wait(10, SC_NS);
257
258    count = 32;
259    ev.notify();
260    wait(10, SC_NS);
261
262    count = 33;
263    ev.notify();
264    t.disable();
265    wait(10, SC_NS);
266
267    count = 34;
268    ev.notify();
269    wait(10, SC_NS);
270
271    count = 35;
272    t.enable();
273    ev.notify();
274    wait(10, SC_NS);
275
276    count = 36;
277    t.disable();
278    t.disable(); // Dummy
279    ev.notify();
280    ev.notify(); // Dummy
281    wait(10, SC_NS);
282
283    count = 37;
284    t.sync_reset_off();
285    t.sync_reset_off(); // Dummy
286    wait(10, SC_NS);
287
288    count = 38;
289    t.enable();
290    wait(10, SC_NS);
291
292    count = 39;
293    ev.notify();
294    wait(sc_time(700, SC_NS) - sc_time_stamp());
295
296    sc_stop();
297  }
298
299  void target()
300  {
301    switch (count)
302    {
303        case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f1=1; break;
304        case 6: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); f5=1; break;
305        case 9: sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); f7=1; break;
306        case 10: sc_assert( sc_time_stamp() == sc_time(120, SC_NS) ); f8=1; break;
307        case 23: sc_assert( sc_time_stamp() == sc_time(330, SC_NS) ); f15=1; break;
308        case 24: sc_assert( sc_time_stamp() == sc_time(340, SC_NS) ); f16=1; break;
309        case 26: sc_assert( sc_time_stamp() == sc_time(400, SC_NS) ); f18=1; break;
310        case 28: sc_assert( sc_time_stamp() == sc_time(420, SC_NS) ); f19=1; break;
311        case 30: sc_assert( sc_time_stamp() == sc_time(510, SC_NS) ); f20=1; break;
312        case 32: sc_assert( sc_time_stamp() == sc_time(530, SC_NS) ); f21=1; break;
313        case 33: sc_assert( sc_time_stamp() == sc_time(540, SC_NS) ); f22=1; break;
314        case 35: sc_assert( sc_time_stamp() == sc_time(560, SC_NS) ); f23=1; break;
315        default: sc_assert( false ); break;
316    }
317
318    for (;;)
319    {
320      wait(ev);
321      switch (count)
322      {
323        case 1: sc_assert( sc_time_stamp() == sc_time(5, SC_NS) ); f2=1; break;
324        case 4: sc_assert( sc_time_stamp() == sc_time(35, SC_NS) ); f3=1; break;
325        case 5: sc_assert( sc_time_stamp() == sc_time(45, SC_NS) ); f4=1; break;
326        case 7: sc_assert( sc_time_stamp() == sc_time(55, SC_NS) ); f6=1; break;
327        case 11: sc_assert( sc_time_stamp() == sc_time(135, SC_NS) ); f9=1; break;
328        case 14: sc_assert( sc_time_stamp() == sc_time(220, SC_NS) ); f10=1; break;
329        case 15: sc_assert( sc_time_stamp() == sc_time(235, SC_NS) ); f11=1; break;
330        case 18: sc_assert( sc_time_stamp() == sc_time(260, SC_NS) ); f12=1; break;
331        case 19: sc_assert( sc_time_stamp() == sc_time(300, SC_NS) ); f13=1; break;
332        case 21: sc_assert( sc_time_stamp() == sc_time(315, SC_NS) ); f14=1; break;
333        case 25: sc_assert( sc_time_stamp() == sc_time(350, SC_NS) ); f17=1; break;
334        case 39: sc_assert( sc_time_stamp() == sc_time(600, SC_NS) ); f24=1; break;
335        default: sc_assert( false ); break;
336      }
337    }
338  }
339
340  SC_HAS_PROCESS(Top);
341};
342
343int sc_main(int argc, char* argv[])
344{
345  Top top("top");
346
347  sc_start();
348
349  sc_assert( top.f1 );
350  sc_assert( top.f2 );
351  sc_assert( top.f3 );
352  sc_assert( top.f4 );
353  sc_assert( top.f5 );
354  sc_assert( top.f6 );
355  sc_assert( top.f7 );
356  sc_assert( top.f8 );
357  sc_assert( top.f9 );
358  sc_assert( top.f10 );
359  sc_assert( top.f11 );
360  sc_assert( top.f12 );
361  sc_assert( top.f13 );
362  sc_assert( top.f14 );
363  sc_assert( top.f15 );
364  sc_assert( top.f16 );
365  sc_assert( top.f17 );
366  sc_assert( top.f18 );
367  sc_assert( top.f19 );
368  sc_assert( top.f20 );
369  sc_assert( top.f21 );
370  sc_assert( top.f22 );
371  sc_assert( top.f23 );
372  sc_assert( top.f24 );
373
374  cout << endl << "Success" << endl;
375  return 0;
376}
377
378