112855Sgabeblack@google.com/*****************************************************************************
212855Sgabeblack@google.com
312855Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412855Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512855Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612855Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712855Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812855Sgabeblack@google.com  License.  You may obtain a copy of the License at
912855Sgabeblack@google.com
1012855Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112855Sgabeblack@google.com
1212855Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312855Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412855Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512855Sgabeblack@google.com  implied.  See the License for the specific language governing
1612855Sgabeblack@google.com  permissions and limitations under the License.
1712855Sgabeblack@google.com
1812855Sgabeblack@google.com *****************************************************************************/
1912855Sgabeblack@google.com
2012855Sgabeblack@google.com// proc_ctrl_priority.cpp -- test for
2112855Sgabeblack@google.com//
2212855Sgabeblack@google.com//  Original Author: John Aynsley, Doulus
2312855Sgabeblack@google.com//
2412855Sgabeblack@google.com// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
2512855Sgabeblack@google.com//
2612855Sgabeblack@google.com// $Log: proc_ctrl_priority.cpp,v $
2712855Sgabeblack@google.com// Revision 1.3  2011/09/05 21:23:35  acg
2812855Sgabeblack@google.com//  Philipp A. Hartmann: eliminate compiler warnings.
2912855Sgabeblack@google.com//
3012855Sgabeblack@google.com// Revision 1.2  2011/05/08 19:18:46  acg
3112855Sgabeblack@google.com//  Andy Goodrich: remove extraneous + prefixes from git diff.
3212855Sgabeblack@google.com//
3312855Sgabeblack@google.com
3412855Sgabeblack@google.com// Priority of process control methods suspend, disable, sync_reset_on, reset
3512855Sgabeblack@google.com
3612855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES
3712855Sgabeblack@google.com
3812855Sgabeblack@google.com#include <systemc>
3912855Sgabeblack@google.com
4012855Sgabeblack@google.comusing namespace sc_core;
4112855Sgabeblack@google.comusing std::cout;
4212855Sgabeblack@google.comusing std::endl;
4312855Sgabeblack@google.com
4412855Sgabeblack@google.comstruct Top: sc_module
4512855Sgabeblack@google.com{
4612855Sgabeblack@google.com  Top(sc_module_name _name)
4712855Sgabeblack@google.com  {
4812855Sgabeblack@google.com    SC_THREAD(calling);
4912855Sgabeblack@google.com
5012855Sgabeblack@google.com    SC_THREAD(target);
5112855Sgabeblack@google.com      t = sc_get_current_process_handle();
5212855Sgabeblack@google.com
5312855Sgabeblack@google.com    count = 0;
5412855Sgabeblack@google.com    f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0;
5512855Sgabeblack@google.com    f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0;
5612855Sgabeblack@google.com    f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0;
5712855Sgabeblack@google.com  }
5812855Sgabeblack@google.com
5912855Sgabeblack@google.com  sc_process_handle t;
6012855Sgabeblack@google.com  sc_event ev;
6112855Sgabeblack@google.com  int count;
6212855Sgabeblack@google.com  bool target_awoke;
6312855Sgabeblack@google.com  int f1, f2, f3, f4, f5, f6, f7, f8, f9;
6412855Sgabeblack@google.com  int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19;
6512855Sgabeblack@google.com  int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29;
6612855Sgabeblack@google.com
6712855Sgabeblack@google.com  void calling()
6812855Sgabeblack@google.com  {
6912855Sgabeblack@google.com    count = 0;
7012855Sgabeblack@google.com    wait(SC_ZERO_TIME);
7112855Sgabeblack@google.com
7212855Sgabeblack@google.com    count = 1;
7312855Sgabeblack@google.com    ev.notify(5, SC_NS);
7412855Sgabeblack@google.com    wait(10, SC_NS);
7512855Sgabeblack@google.com
7612855Sgabeblack@google.com    count = 2;
7712855Sgabeblack@google.com    ev.notify(5, SC_NS);
7812855Sgabeblack@google.com    t.disable();
7912855Sgabeblack@google.com    wait(10, SC_NS);
8012855Sgabeblack@google.com
8112855Sgabeblack@google.com    count = 3;
8212855Sgabeblack@google.com    ev.notify(5, SC_NS);
8312855Sgabeblack@google.com    t.disable();
8412855Sgabeblack@google.com    t.disable(); // Dummy
8512855Sgabeblack@google.com    t.resume();
8612855Sgabeblack@google.com    t.resume();
8712855Sgabeblack@google.com    t.sync_reset_off(); // Dummy
8812855Sgabeblack@google.com    t.sync_reset_off(); // Dummy
8912855Sgabeblack@google.com    wait(10, SC_NS);
9012855Sgabeblack@google.com
9112855Sgabeblack@google.com    count = 4;
9212855Sgabeblack@google.com    ev.notify(5, SC_NS);
9312855Sgabeblack@google.com    t.enable();
9412855Sgabeblack@google.com    wait(10, SC_NS);
9512855Sgabeblack@google.com
9612855Sgabeblack@google.com    count = 5;
9712855Sgabeblack@google.com    ev.notify(5, SC_NS);
9812855Sgabeblack@google.com    t.enable(); // Dummy
9912855Sgabeblack@google.com    t.enable(); // Dummy
10012855Sgabeblack@google.com    t.sync_reset_off(); // Dummy
10112855Sgabeblack@google.com    t.sync_reset_off(); // Dummy
10212855Sgabeblack@google.com    wait(10, SC_NS);
10312855Sgabeblack@google.com
10412855Sgabeblack@google.com    count = 6;
10512855Sgabeblack@google.com    ev.notify(5, SC_NS);
10612855Sgabeblack@google.com    t.reset();
10712855Sgabeblack@google.com    wait(SC_ZERO_TIME);
10812855Sgabeblack@google.com
10912855Sgabeblack@google.com    count = 7;
11012855Sgabeblack@google.com    wait(sc_time(100, SC_NS) - sc_time_stamp());
11112855Sgabeblack@google.com
11212855Sgabeblack@google.com    count = 8;
11312855Sgabeblack@google.com    ev.notify(5, SC_NS);
11412855Sgabeblack@google.com    t.disable();
11512855Sgabeblack@google.com    wait(10, SC_NS);
11612855Sgabeblack@google.com
11712855Sgabeblack@google.com    count = 9;
11812855Sgabeblack@google.com    ev.notify(5, SC_NS);
11912855Sgabeblack@google.com    t.reset();
12012855Sgabeblack@google.com    wait(10, SC_NS);
12112855Sgabeblack@google.com
12212855Sgabeblack@google.com    count = 10;
12312855Sgabeblack@google.com    ev.notify(5, SC_NS);
12412855Sgabeblack@google.com    t.reset();
12512855Sgabeblack@google.com    wait(10, SC_NS);
12612855Sgabeblack@google.com
12712855Sgabeblack@google.com    count = 11;
12812855Sgabeblack@google.com    ev.notify(5, SC_NS);
12912855Sgabeblack@google.com    t.enable();
13012855Sgabeblack@google.com    wait(sc_time(200, SC_NS) - sc_time_stamp());
13112855Sgabeblack@google.com
13212855Sgabeblack@google.com    count = 12;
13312855Sgabeblack@google.com    ev.notify(5, SC_NS);
13412855Sgabeblack@google.com    t.suspend();
13512855Sgabeblack@google.com    wait(10, SC_NS);
13612855Sgabeblack@google.com
13712855Sgabeblack@google.com    count = 13;
13812855Sgabeblack@google.com    t.suspend(); // Dummy
13912855Sgabeblack@google.com    t.suspend(); // Dummy
14012855Sgabeblack@google.com    t.enable(); // Dummy
14112855Sgabeblack@google.com    t.enable(); // Dummy
14212855Sgabeblack@google.com    t.sync_reset_off(); // Dummy
14312855Sgabeblack@google.com    t.sync_reset_off(); // Dummy
14412855Sgabeblack@google.com    wait(10, SC_NS);
14512855Sgabeblack@google.com
14612855Sgabeblack@google.com    count = 14;
14712855Sgabeblack@google.com    t.resume();
14812855Sgabeblack@google.com    wait(10, SC_NS);
14912855Sgabeblack@google.com
15012855Sgabeblack@google.com    count = 15;
15112855Sgabeblack@google.com    ev.notify(5, SC_NS);
15212855Sgabeblack@google.com    t.resume(); // Dummy
15312855Sgabeblack@google.com    t.resume(); // Dummy
15412855Sgabeblack@google.com    t.enable(); // Dummy
15512855Sgabeblack@google.com    t.enable(); // Dummy
15612855Sgabeblack@google.com    t.sync_reset_off(); // Dummy
15712855Sgabeblack@google.com    t.sync_reset_off(); // Dummy
15812855Sgabeblack@google.com    wait(10, SC_NS);
15912855Sgabeblack@google.com
16012855Sgabeblack@google.com    count = 16;
16112855Sgabeblack@google.com    ev.notify();
16212855Sgabeblack@google.com    t.resume(); // Dummy
16312855Sgabeblack@google.com    t.resume(); // Dummy
16412855Sgabeblack@google.com    t.disable(); // Dummy
16512855Sgabeblack@google.com    t.disable(); // Dummy
16612855Sgabeblack@google.com    t.enable(); // Dummy
16712855Sgabeblack@google.com    t.enable(); // Dummy
16812855Sgabeblack@google.com    t.suspend();
16912855Sgabeblack@google.com    wait(10, SC_NS);
17012855Sgabeblack@google.com
17112855Sgabeblack@google.com    count = 17;
17212855Sgabeblack@google.com    t.suspend(); // Dummy
17312855Sgabeblack@google.com    t.suspend(); // Dummy
17412855Sgabeblack@google.com    t.enable(); // Dummy
17512855Sgabeblack@google.com    t.enable(); // Dummy
17612855Sgabeblack@google.com    t.sync_reset_off(); // Dummy
17712855Sgabeblack@google.com    t.sync_reset_off(); // Dummy
17812855Sgabeblack@google.com    wait(10, SC_NS);
17912855Sgabeblack@google.com
18012855Sgabeblack@google.com    count = 18;
18112855Sgabeblack@google.com    t.resume();
18212855Sgabeblack@google.com    wait(sc_time(300, SC_NS) - sc_time_stamp());
18312855Sgabeblack@google.com
18412855Sgabeblack@google.com    count = 19;
18512855Sgabeblack@google.com    ev.notify();
18612855Sgabeblack@google.com    ev.notify(5, SC_NS);
18712855Sgabeblack@google.com    t.disable();
18812855Sgabeblack@google.com    t.disable(); // Dummy
18912855Sgabeblack@google.com    wait(5, SC_NS);
19012855Sgabeblack@google.com    t.disable(); // Dummy
19112855Sgabeblack@google.com    t.resume();
19212855Sgabeblack@google.com    t.resume();
19312855Sgabeblack@google.com    wait(5, SC_NS);
19412855Sgabeblack@google.com
19512855Sgabeblack@google.com    count = 20;
19612855Sgabeblack@google.com    ev.notify(5, SC_NS);
19712855Sgabeblack@google.com    t.enable();
19812855Sgabeblack@google.com    t.enable(); // Dummy
19912855Sgabeblack@google.com    wait(SC_ZERO_TIME);
20012855Sgabeblack@google.com
20112855Sgabeblack@google.com    count = 21;
20212855Sgabeblack@google.com    wait(10, SC_NS);
20312855Sgabeblack@google.com
20412855Sgabeblack@google.com    count = 22;
20512855Sgabeblack@google.com    ev.notify(5, SC_NS);
20612855Sgabeblack@google.com    t.suspend();
20712855Sgabeblack@google.com    wait(10, SC_NS);
20812855Sgabeblack@google.com
20912855Sgabeblack@google.com    count = 23;
21012855Sgabeblack@google.com    t.reset();
21112855Sgabeblack@google.com    ev.notify(5, SC_NS);
21212855Sgabeblack@google.com    wait(10, SC_NS);
21312855Sgabeblack@google.com
21412855Sgabeblack@google.com    count = 24;
21512855Sgabeblack@google.com    t.reset();
21612855Sgabeblack@google.com    ev.notify(5, SC_NS);
21712855Sgabeblack@google.com    wait(10, SC_NS);
21812855Sgabeblack@google.com
21912855Sgabeblack@google.com    count = 25;
22012855Sgabeblack@google.com    t.resume();
22112855Sgabeblack@google.com    wait(sc_time(400, SC_NS) - sc_time_stamp());
22212855Sgabeblack@google.com
22312855Sgabeblack@google.com    count = 26;
22412855Sgabeblack@google.com    ev.notify();
22512855Sgabeblack@google.com    t.reset();
22612855Sgabeblack@google.com    wait(10, SC_NS);
22712855Sgabeblack@google.com
22812855Sgabeblack@google.com    count = 27;
22912855Sgabeblack@google.com    ev.notify();
23012855Sgabeblack@google.com    t.suspend();
23112855Sgabeblack@google.com    wait(10, SC_NS);
23212855Sgabeblack@google.com
23312855Sgabeblack@google.com    count = 28;
23412855Sgabeblack@google.com    t.reset();
23512855Sgabeblack@google.com    wait(10, SC_NS);
23612855Sgabeblack@google.com    t.resume();
23712855Sgabeblack@google.com
23812855Sgabeblack@google.com    wait(sc_time(500, SC_NS) - sc_time_stamp());
23912855Sgabeblack@google.com
24012855Sgabeblack@google.com    count = 29;
24112855Sgabeblack@google.com    t.sync_reset_on();
24212855Sgabeblack@google.com    t.sync_reset_on(); // Dummy
24312855Sgabeblack@google.com    wait(10, SC_NS);
24412855Sgabeblack@google.com
24512855Sgabeblack@google.com    count = 30;
24612855Sgabeblack@google.com    ev.notify();
24712855Sgabeblack@google.com    wait(10, SC_NS);
24812855Sgabeblack@google.com
24912855Sgabeblack@google.com    count = 31;
25012855Sgabeblack@google.com    t.resume(); // Dummy
25112855Sgabeblack@google.com    t.resume(); // Dummy
25212855Sgabeblack@google.com    t.enable(); // Dummy
25312855Sgabeblack@google.com    t.enable(); // Dummy
25412855Sgabeblack@google.com    t.sync_reset_on(); // Dummy
25512855Sgabeblack@google.com    t.sync_reset_on(); // Dummy
25612855Sgabeblack@google.com    wait(10, SC_NS);
25712855Sgabeblack@google.com
25812855Sgabeblack@google.com    count = 32;
25912855Sgabeblack@google.com    ev.notify();
26012855Sgabeblack@google.com    wait(10, SC_NS);
26112855Sgabeblack@google.com
26212855Sgabeblack@google.com    count = 33;
26312855Sgabeblack@google.com    ev.notify();
26412855Sgabeblack@google.com    t.disable();
26512855Sgabeblack@google.com    wait(10, SC_NS);
26612855Sgabeblack@google.com
26712855Sgabeblack@google.com    count = 34;
26812855Sgabeblack@google.com    ev.notify();
26912855Sgabeblack@google.com    wait(10, SC_NS);
27012855Sgabeblack@google.com
27112855Sgabeblack@google.com    count = 35;
27212855Sgabeblack@google.com    t.enable();
27312855Sgabeblack@google.com    ev.notify();
27412855Sgabeblack@google.com    wait(10, SC_NS);
27512855Sgabeblack@google.com
27612855Sgabeblack@google.com    count = 36;
27712855Sgabeblack@google.com    t.disable();
27812855Sgabeblack@google.com    t.disable(); // Dummy
27912855Sgabeblack@google.com    ev.notify();
28012855Sgabeblack@google.com    ev.notify(); // Dummy
28112855Sgabeblack@google.com    wait(10, SC_NS);
28212855Sgabeblack@google.com
28312855Sgabeblack@google.com    count = 37;
28412855Sgabeblack@google.com    t.sync_reset_off();
28512855Sgabeblack@google.com    t.sync_reset_off(); // Dummy
28612855Sgabeblack@google.com    wait(10, SC_NS);
28712855Sgabeblack@google.com
28812855Sgabeblack@google.com    count = 38;
28912855Sgabeblack@google.com    t.enable();
29012855Sgabeblack@google.com    wait(10, SC_NS);
29112855Sgabeblack@google.com
29212855Sgabeblack@google.com    count = 39;
29312855Sgabeblack@google.com    ev.notify();
29412855Sgabeblack@google.com    wait(sc_time(700, SC_NS) - sc_time_stamp());
29512855Sgabeblack@google.com
29612855Sgabeblack@google.com    sc_stop();
29712855Sgabeblack@google.com  }
29812855Sgabeblack@google.com
29912855Sgabeblack@google.com  void target()
30012855Sgabeblack@google.com  {
30112855Sgabeblack@google.com    switch (count)
30212855Sgabeblack@google.com    {
30312855Sgabeblack@google.com        case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f1=1; break;
30412855Sgabeblack@google.com        case 6: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); f5=1; break;
30512855Sgabeblack@google.com        case 9: sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); f7=1; break;
30612855Sgabeblack@google.com        case 10: sc_assert( sc_time_stamp() == sc_time(120, SC_NS) ); f8=1; break;
30712855Sgabeblack@google.com        case 23: sc_assert( sc_time_stamp() == sc_time(330, SC_NS) ); f15=1; break;
30812855Sgabeblack@google.com        case 24: sc_assert( sc_time_stamp() == sc_time(340, SC_NS) ); f16=1; break;
30912855Sgabeblack@google.com        case 26: sc_assert( sc_time_stamp() == sc_time(400, SC_NS) ); f18=1; break;
31012855Sgabeblack@google.com        case 28: sc_assert( sc_time_stamp() == sc_time(420, SC_NS) ); f19=1; break;
31112855Sgabeblack@google.com        case 30: sc_assert( sc_time_stamp() == sc_time(510, SC_NS) ); f20=1; break;
31212855Sgabeblack@google.com        case 32: sc_assert( sc_time_stamp() == sc_time(530, SC_NS) ); f21=1; break;
31312855Sgabeblack@google.com        case 33: sc_assert( sc_time_stamp() == sc_time(540, SC_NS) ); f22=1; break;
31412855Sgabeblack@google.com        case 35: sc_assert( sc_time_stamp() == sc_time(560, SC_NS) ); f23=1; break;
31512855Sgabeblack@google.com        default: sc_assert( false ); break;
31612855Sgabeblack@google.com    }
31712855Sgabeblack@google.com
31812855Sgabeblack@google.com    for (;;)
31912855Sgabeblack@google.com    {
32012855Sgabeblack@google.com      wait(ev);
32112855Sgabeblack@google.com      switch (count)
32212855Sgabeblack@google.com      {
32312855Sgabeblack@google.com        case 1: sc_assert( sc_time_stamp() == sc_time(5, SC_NS) ); f2=1; break;
32412855Sgabeblack@google.com        case 4: sc_assert( sc_time_stamp() == sc_time(35, SC_NS) ); f3=1; break;
32512855Sgabeblack@google.com        case 5: sc_assert( sc_time_stamp() == sc_time(45, SC_NS) ); f4=1; break;
32612855Sgabeblack@google.com        case 7: sc_assert( sc_time_stamp() == sc_time(55, SC_NS) ); f6=1; break;
32712855Sgabeblack@google.com        case 11: sc_assert( sc_time_stamp() == sc_time(135, SC_NS) ); f9=1; break;
32812855Sgabeblack@google.com        case 14: sc_assert( sc_time_stamp() == sc_time(220, SC_NS) ); f10=1; break;
32912855Sgabeblack@google.com        case 15: sc_assert( sc_time_stamp() == sc_time(235, SC_NS) ); f11=1; break;
33012855Sgabeblack@google.com        case 18: sc_assert( sc_time_stamp() == sc_time(260, SC_NS) ); f12=1; break;
33112855Sgabeblack@google.com        case 19: sc_assert( sc_time_stamp() == sc_time(300, SC_NS) ); f13=1; break;
33212855Sgabeblack@google.com        case 21: sc_assert( sc_time_stamp() == sc_time(315, SC_NS) ); f14=1; break;
33312855Sgabeblack@google.com        case 25: sc_assert( sc_time_stamp() == sc_time(350, SC_NS) ); f17=1; break;
33412855Sgabeblack@google.com        case 39: sc_assert( sc_time_stamp() == sc_time(600, SC_NS) ); f24=1; break;
33512855Sgabeblack@google.com        default: sc_assert( false ); break;
33612855Sgabeblack@google.com      }
33712855Sgabeblack@google.com    }
33812855Sgabeblack@google.com  }
33912855Sgabeblack@google.com
34012855Sgabeblack@google.com  SC_HAS_PROCESS(Top);
34112855Sgabeblack@google.com};
34212855Sgabeblack@google.com
34312855Sgabeblack@google.comint sc_main(int argc, char* argv[])
34412855Sgabeblack@google.com{
34512855Sgabeblack@google.com  Top top("top");
34612855Sgabeblack@google.com
34712855Sgabeblack@google.com  sc_start();
34812855Sgabeblack@google.com
34912855Sgabeblack@google.com  sc_assert( top.f1 );
35012855Sgabeblack@google.com  sc_assert( top.f2 );
35112855Sgabeblack@google.com  sc_assert( top.f3 );
35212855Sgabeblack@google.com  sc_assert( top.f4 );
35312855Sgabeblack@google.com  sc_assert( top.f5 );
35412855Sgabeblack@google.com  sc_assert( top.f6 );
35512855Sgabeblack@google.com  sc_assert( top.f7 );
35612855Sgabeblack@google.com  sc_assert( top.f8 );
35712855Sgabeblack@google.com  sc_assert( top.f9 );
35812855Sgabeblack@google.com  sc_assert( top.f10 );
35912855Sgabeblack@google.com  sc_assert( top.f11 );
36012855Sgabeblack@google.com  sc_assert( top.f12 );
36112855Sgabeblack@google.com  sc_assert( top.f13 );
36212855Sgabeblack@google.com  sc_assert( top.f14 );
36312855Sgabeblack@google.com  sc_assert( top.f15 );
36412855Sgabeblack@google.com  sc_assert( top.f16 );
36512855Sgabeblack@google.com  sc_assert( top.f17 );
36612855Sgabeblack@google.com  sc_assert( top.f18 );
36712855Sgabeblack@google.com  sc_assert( top.f19 );
36812855Sgabeblack@google.com  sc_assert( top.f20 );
36912855Sgabeblack@google.com  sc_assert( top.f21 );
37012855Sgabeblack@google.com  sc_assert( top.f22 );
37112855Sgabeblack@google.com  sc_assert( top.f23 );
37212855Sgabeblack@google.com  sc_assert( top.f24 );
37312855Sgabeblack@google.com
37412855Sgabeblack@google.com  cout << endl << "Success" << endl;
37512855Sgabeblack@google.com  return 0;
37612855Sgabeblack@google.com}
37712855Sgabeblack@google.com
378