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// async_reset.cpp
2112855Sgabeblack@google.com//
2212855Sgabeblack@google.com//  Original Author: John Aynsley, Doulos, Inc.
2312855Sgabeblack@google.com//
2412855Sgabeblack@google.com// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
2512855Sgabeblack@google.com//
2612855Sgabeblack@google.com// $Log: async_reset.cpp,v $
2712855Sgabeblack@google.com// Revision 1.3  2011/05/08 19:18:45  acg
2812855Sgabeblack@google.com//  Andy Goodrich: remove extraneous + prefixes from git diff.
2912855Sgabeblack@google.com//
3012855Sgabeblack@google.com
3112855Sgabeblack@google.com// async_reset_signal_is
3212855Sgabeblack@google.com
3312855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES
3412855Sgabeblack@google.com
3512855Sgabeblack@google.com#include <systemc>
3612855Sgabeblack@google.comusing namespace sc_core;
3712855Sgabeblack@google.comusing std::cout;
3812855Sgabeblack@google.comusing std::endl;
3912855Sgabeblack@google.com
4012855Sgabeblack@google.comstruct Top: sc_module
4112855Sgabeblack@google.com{
4212855Sgabeblack@google.com  Top(sc_module_name _name)
4312855Sgabeblack@google.com  : count(0)
4412855Sgabeblack@google.com  {
4512855Sgabeblack@google.com    clk_port.bind(clk);
4612855Sgabeblack@google.com
4712855Sgabeblack@google.com    SC_THREAD(ctrl);
4812855Sgabeblack@google.com
4912855Sgabeblack@google.com    SC_CTHREAD(CT, clk_port.value_changed());
5012855Sgabeblack@google.com      async_reset_signal_is(areset, true);
5112855Sgabeblack@google.com      ct = sc_get_current_process_handle();
5212855Sgabeblack@google.com
5312855Sgabeblack@google.com    sc_spawn_options opt;
5412855Sgabeblack@google.com    opt.async_reset_signal_is(areset, true);
5512855Sgabeblack@google.com    t = sc_spawn(sc_bind(&Top::T, this), "T", &opt);
5612855Sgabeblack@google.com
5712855Sgabeblack@google.com    opt.spawn_method();
5812855Sgabeblack@google.com    opt.dont_initialize();
5912855Sgabeblack@google.com    opt.set_sensitivity( &clk );
6012855Sgabeblack@google.com    m = sc_spawn(sc_bind(&Top::M, this), "M", &opt);
6112855Sgabeblack@google.com
6212855Sgabeblack@google.com    SC_CTHREAD(CT2, clk_port.pos())
6312855Sgabeblack@google.com      async_reset_signal_is(areset1, true);
6412855Sgabeblack@google.com      async_reset_signal_is(areset2, true);
6512855Sgabeblack@google.com      async_reset_signal_is(areset3, true);
6612855Sgabeblack@google.com      reset_signal_is(sreset1, true);
6712855Sgabeblack@google.com      reset_signal_is(sreset2, true);
6812855Sgabeblack@google.com      reset_signal_is(sreset3, true);
6912855Sgabeblack@google.com      ct2 = sc_get_current_process_handle();
7012855Sgabeblack@google.com      ct2.disable();
7112855Sgabeblack@google.com
7212855Sgabeblack@google.com    SC_THREAD(T2)
7312855Sgabeblack@google.com      sensitive << clk_port.pos();
7412855Sgabeblack@google.com      async_reset_signal_is(areset1, true);
7512855Sgabeblack@google.com      async_reset_signal_is(areset2, true);
7612855Sgabeblack@google.com      async_reset_signal_is(areset3, true);
7712855Sgabeblack@google.com      reset_signal_is(sreset1, true);
7812855Sgabeblack@google.com      reset_signal_is(sreset2, true);
7912855Sgabeblack@google.com      reset_signal_is(sreset3, true);
8012855Sgabeblack@google.com      t2 = sc_get_current_process_handle();
8112855Sgabeblack@google.com      t2.disable();
8212855Sgabeblack@google.com
8312855Sgabeblack@google.com    clk.write(false);
8412855Sgabeblack@google.com    areset.write(false);
8512855Sgabeblack@google.com
8612855Sgabeblack@google.com    f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0;
8712855Sgabeblack@google.com    f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0;
8812855Sgabeblack@google.com    f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0;
8912855Sgabeblack@google.com    f30 = f31 = f32 = f33 = f34 = f35 = f36 = f37 = f38 = f39 = 0;
9012855Sgabeblack@google.com    f40 = f41 = f42 = f43 = f44 = f45 = f46 = f47 = f48 = f49 = 0;
9112855Sgabeblack@google.com    f50 = f51 = f52 = f53 = f54 = f55 = f56 = f57 = f58 = f59 = 0;
9212855Sgabeblack@google.com    f60 = f61 = f62 = f63 = f64 = f65 = f66 = f67 = f68 = f69 = 0;
9312855Sgabeblack@google.com    f70 = f71 = f72 = f73 = f74 = f75 = f76 = f77 = f78 = f79 = 0;
9412855Sgabeblack@google.com    f80 = f81 = f82 = f83 = f84 = f85 = f86 = f87 = f88 = f89 = 0;
9512855Sgabeblack@google.com  }
9612855Sgabeblack@google.com
9712855Sgabeblack@google.com  sc_signal<bool> clk;
9812855Sgabeblack@google.com  sc_in<bool> clk_port;
9912855Sgabeblack@google.com  sc_signal<bool> areset;
10012855Sgabeblack@google.com  sc_signal<bool> areset1, areset2, areset3, sreset1, sreset2, sreset3;
10112855Sgabeblack@google.com
10212855Sgabeblack@google.com  sc_process_handle ct, t, m, ct2, t2;
10312855Sgabeblack@google.com  int count;
10412855Sgabeblack@google.com
10512855Sgabeblack@google.com  int f1, f2, f3, f4, f5, f6, f7, f8, f9;
10612855Sgabeblack@google.com  int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19;
10712855Sgabeblack@google.com  int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29;
10812855Sgabeblack@google.com  int f30, f31, f32, f33, f34, f35, f36, f37, f38, f39;
10912855Sgabeblack@google.com  int f40, f41, f42, f43, f44, f45, f46, f47, f48, f49;
11012855Sgabeblack@google.com  int f50, f51, f52, f53, f54, f55, f56, f57, f58, f59;
11112855Sgabeblack@google.com  int f60, f61, f62, f63, f64, f65, f66, f67, f68, f69;
11212855Sgabeblack@google.com  int f70, f71, f72, f73, f74, f75, f76, f77, f78, f79;
11312855Sgabeblack@google.com  int f80, f81, f82, f83, f84, f85, f86, f87, f88, f89;
11412855Sgabeblack@google.com
11512855Sgabeblack@google.com  void ctrl()
11612855Sgabeblack@google.com  {
11712855Sgabeblack@google.com    sc_assert( sc_delta_count() == 0 );
11812855Sgabeblack@google.com    clock();
11912855Sgabeblack@google.com    wait(SC_ZERO_TIME);
12012855Sgabeblack@google.com    wait(SC_ZERO_TIME);
12112855Sgabeblack@google.com
12212855Sgabeblack@google.com    count = 1;
12312855Sgabeblack@google.com    clock();
12412855Sgabeblack@google.com    wait(1, SC_NS);
12512855Sgabeblack@google.com
12612855Sgabeblack@google.com    count = 2;
12712855Sgabeblack@google.com    clock();
12812855Sgabeblack@google.com    wait(10, SC_NS);
12912855Sgabeblack@google.com
13012855Sgabeblack@google.com    count = 3;
13112855Sgabeblack@google.com    clock();
13212855Sgabeblack@google.com    wait(sc_time(20, SC_NS) - sc_time_stamp());
13312855Sgabeblack@google.com
13412855Sgabeblack@google.com    count = 4;
13512855Sgabeblack@google.com    areset.write(true);
13612855Sgabeblack@google.com    wait(1, SC_NS);
13712855Sgabeblack@google.com
13812855Sgabeblack@google.com    count = 5;
13912855Sgabeblack@google.com    areset.write(false);
14012855Sgabeblack@google.com    wait(1, SC_NS);
14112855Sgabeblack@google.com
14212855Sgabeblack@google.com    count = 6;
14312855Sgabeblack@google.com    clock();
14412855Sgabeblack@google.com    wait(sc_time(30, SC_NS) - sc_time_stamp());
14512855Sgabeblack@google.com
14612855Sgabeblack@google.com    count = 7;
14712855Sgabeblack@google.com    areset.write(true);
14812855Sgabeblack@google.com    wait(1, SC_NS);
14912855Sgabeblack@google.com
15012855Sgabeblack@google.com    count = 8;
15112855Sgabeblack@google.com    clock();      // Clocked while asynch reset is active
15212855Sgabeblack@google.com    wait(1, SC_NS);
15312855Sgabeblack@google.com
15412855Sgabeblack@google.com    count = 9;
15512855Sgabeblack@google.com    clock();
15612855Sgabeblack@google.com    wait(1, SC_NS);
15712855Sgabeblack@google.com
15812855Sgabeblack@google.com    count = 10;
15912855Sgabeblack@google.com    areset.write(false);
16012855Sgabeblack@google.com    wait(1, SC_NS);
16112855Sgabeblack@google.com
16212855Sgabeblack@google.com    count = 11;
16312855Sgabeblack@google.com    areset.write(true);
16412855Sgabeblack@google.com    wait(1, SC_NS);
16512855Sgabeblack@google.com
16612855Sgabeblack@google.com    count = 12;
16712855Sgabeblack@google.com    areset.write(false);
16812855Sgabeblack@google.com    wait(sc_time(40, SC_NS) - sc_time_stamp());
16912855Sgabeblack@google.com
17012855Sgabeblack@google.com    count = 13;
17112855Sgabeblack@google.com    sync_reset_on();
17212855Sgabeblack@google.com    wait(1, SC_NS);
17312855Sgabeblack@google.com
17412855Sgabeblack@google.com    count = 14;
17512855Sgabeblack@google.com    clock();
17612855Sgabeblack@google.com    wait(1, SC_NS);
17712855Sgabeblack@google.com
17812855Sgabeblack@google.com    count = 15;
17912855Sgabeblack@google.com    sync_reset_off();
18012855Sgabeblack@google.com    wait(sc_time(50, SC_NS) - sc_time_stamp());
18112855Sgabeblack@google.com
18212855Sgabeblack@google.com    count = 16;
18312855Sgabeblack@google.com    disable();
18412855Sgabeblack@google.com    wait(1, SC_NS);
18512855Sgabeblack@google.com
18612855Sgabeblack@google.com    count = 17;
18712855Sgabeblack@google.com    clock();
18812855Sgabeblack@google.com    wait(1, SC_NS);
18912855Sgabeblack@google.com
19012855Sgabeblack@google.com    count = 18;
19112855Sgabeblack@google.com    sync_reset_on();
19212855Sgabeblack@google.com    clock();
19312855Sgabeblack@google.com    wait(1, SC_NS);
19412855Sgabeblack@google.com
19512855Sgabeblack@google.com    count = 19;
19612855Sgabeblack@google.com    enable();
19712855Sgabeblack@google.com    clock();
19812855Sgabeblack@google.com    wait(1, SC_NS);
19912855Sgabeblack@google.com
20012855Sgabeblack@google.com    count = 20;
20112855Sgabeblack@google.com    sync_reset_off();
20212855Sgabeblack@google.com    clock();
20312855Sgabeblack@google.com    wait(sc_time(60, SC_NS) - sc_time_stamp());
20412855Sgabeblack@google.com
20512855Sgabeblack@google.com    count = 21;
20612855Sgabeblack@google.com    disable();
20712855Sgabeblack@google.com    wait(1, SC_NS);
20812855Sgabeblack@google.com
20912855Sgabeblack@google.com    count = 22;
21012855Sgabeblack@google.com    areset.write(true);
21112855Sgabeblack@google.com    wait(1, SC_NS);
21212855Sgabeblack@google.com
21312855Sgabeblack@google.com    count = 23;
21412855Sgabeblack@google.com    clock();
21512855Sgabeblack@google.com    wait(1, SC_NS);
21612855Sgabeblack@google.com
21712855Sgabeblack@google.com    count = 24;
21812855Sgabeblack@google.com    areset.write(false);
21912855Sgabeblack@google.com    wait(1, SC_NS);
22012855Sgabeblack@google.com
22112855Sgabeblack@google.com    count = 25;
22212855Sgabeblack@google.com    clock();
22312855Sgabeblack@google.com    wait(1, SC_NS);
22412855Sgabeblack@google.com
22512855Sgabeblack@google.com    count = 26;
22612855Sgabeblack@google.com    areset.write(true);
22712855Sgabeblack@google.com    wait(1, SC_NS);
22812855Sgabeblack@google.com
22912855Sgabeblack@google.com    count = 27;
23012855Sgabeblack@google.com    enable();
23112855Sgabeblack@google.com    wait(1, SC_NS);
23212855Sgabeblack@google.com
23312855Sgabeblack@google.com    count = 28;
23412855Sgabeblack@google.com    clock();
23512855Sgabeblack@google.com    wait(1, SC_NS);
23612855Sgabeblack@google.com
23712855Sgabeblack@google.com    count = 29;
23812855Sgabeblack@google.com    areset.write(false);
23912855Sgabeblack@google.com    wait(sc_time(100, SC_NS) - sc_time_stamp());
24012855Sgabeblack@google.com
24112855Sgabeblack@google.com    count = 30;
24212855Sgabeblack@google.com    ct.disable();
24312855Sgabeblack@google.com    t.disable();
24412855Sgabeblack@google.com    m.disable();
24512855Sgabeblack@google.com
24612855Sgabeblack@google.com    // Test multiple resets
24712855Sgabeblack@google.com    ct2.enable();
24812855Sgabeblack@google.com    t2.enable();
24912855Sgabeblack@google.com    clock2();
25012855Sgabeblack@google.com
25112855Sgabeblack@google.com    count = 31;
25212855Sgabeblack@google.com    clock2();
25312855Sgabeblack@google.com
25412855Sgabeblack@google.com    count = 32;
25512855Sgabeblack@google.com    sreset1.write(1);
25612855Sgabeblack@google.com    clock2();
25712855Sgabeblack@google.com
25812855Sgabeblack@google.com    count = 33;
25912855Sgabeblack@google.com    sreset2.write(1);
26012855Sgabeblack@google.com    sreset3.write(1);
26112855Sgabeblack@google.com    clock2();
26212855Sgabeblack@google.com
26312855Sgabeblack@google.com    count = 34;
26412855Sgabeblack@google.com    sreset1.write(0);
26512855Sgabeblack@google.com    sreset2.write(0);
26612855Sgabeblack@google.com    clock2();
26712855Sgabeblack@google.com
26812855Sgabeblack@google.com    count = 35;
26912855Sgabeblack@google.com    sreset3.write(0);
27012855Sgabeblack@google.com    clock2();
27112855Sgabeblack@google.com
27212855Sgabeblack@google.com    count = 36;
27312855Sgabeblack@google.com    areset1.write(1);
27412855Sgabeblack@google.com    areset2.write(1);
27512855Sgabeblack@google.com    areset3.write(1);
27612855Sgabeblack@google.com    wait(SC_ZERO_TIME);
27712855Sgabeblack@google.com
27812855Sgabeblack@google.com    count = 37;
27912855Sgabeblack@google.com    clock2();
28012855Sgabeblack@google.com
28112855Sgabeblack@google.com    count = 38;
28212855Sgabeblack@google.com    sreset1.write(1);
28312855Sgabeblack@google.com    sreset2.write(1);
28412855Sgabeblack@google.com    sreset3.write(1);
28512855Sgabeblack@google.com    ct2.sync_reset_on();
28612855Sgabeblack@google.com    t2.sync_reset_on();
28712855Sgabeblack@google.com    clock2();
28812855Sgabeblack@google.com
28912855Sgabeblack@google.com    count = 39;
29012855Sgabeblack@google.com    areset1.write(0);
29112855Sgabeblack@google.com    areset2.write(0);
29212855Sgabeblack@google.com    areset3.write(0);
29312855Sgabeblack@google.com    sreset1.write(0);
29412855Sgabeblack@google.com    sreset2.write(0);
29512855Sgabeblack@google.com    sreset3.write(0);
29612855Sgabeblack@google.com    clock2();
29712855Sgabeblack@google.com
29812855Sgabeblack@google.com    count = 40;
29912855Sgabeblack@google.com    ct2.sync_reset_off();
30012855Sgabeblack@google.com    t2.sync_reset_off();
30112855Sgabeblack@google.com    clock2();
30212855Sgabeblack@google.com
30312855Sgabeblack@google.com    count = 41;
30412855Sgabeblack@google.com    sreset2.write(1);
30512855Sgabeblack@google.com    ct2.sync_reset_on();
30612855Sgabeblack@google.com    t2.sync_reset_on();
30712855Sgabeblack@google.com    clock2();
30812855Sgabeblack@google.com
30912855Sgabeblack@google.com    count = 42;
31012855Sgabeblack@google.com    areset2.write(1);
31112855Sgabeblack@google.com    wait(SC_ZERO_TIME);
31212855Sgabeblack@google.com
31312855Sgabeblack@google.com    count = 43;
31412855Sgabeblack@google.com    clock2();
31512855Sgabeblack@google.com
31612855Sgabeblack@google.com    count = 44;
31712855Sgabeblack@google.com    sreset2.write(0);
31812855Sgabeblack@google.com    ct2.sync_reset_off();
31912855Sgabeblack@google.com    t2.sync_reset_off();
32012855Sgabeblack@google.com    clock2();
32112855Sgabeblack@google.com
32212855Sgabeblack@google.com    count = 45;
32312855Sgabeblack@google.com    areset1.write(0);
32412855Sgabeblack@google.com    areset2.write(0);
32512855Sgabeblack@google.com    areset3.write(0);
32612855Sgabeblack@google.com    sreset1.write(0);
32712855Sgabeblack@google.com    sreset2.write(0);
32812855Sgabeblack@google.com    sreset3.write(0);
32912855Sgabeblack@google.com    clock2();
33012855Sgabeblack@google.com
33112855Sgabeblack@google.com    count = 46;
33212855Sgabeblack@google.com    ct2.reset();
33312855Sgabeblack@google.com    t2.reset();
33412855Sgabeblack@google.com    wait(SC_ZERO_TIME);
33512855Sgabeblack@google.com
33612855Sgabeblack@google.com    count = 47;
33712855Sgabeblack@google.com    clock2();
33812855Sgabeblack@google.com  }
33912855Sgabeblack@google.com
34012855Sgabeblack@google.com  void CT()
34112855Sgabeblack@google.com  {
34212855Sgabeblack@google.com    //cout << "CT() called at " << sc_time_stamp() << endl;
34312855Sgabeblack@google.com    switch (count)
34412855Sgabeblack@google.com    {
34512855Sgabeblack@google.com      case  0: sc_assert( sc_delta_count() == 1 ); f1=1; break;
34612855Sgabeblack@google.com      case  4: sc_assert( sc_time_stamp() == sc_time(20, SC_NS) ); f2=1; break;
34712855Sgabeblack@google.com      case  7: sc_assert( sc_time_stamp() == sc_time(30, SC_NS) ); f3=1; break;
34812855Sgabeblack@google.com      case  8: sc_assert( sc_time_stamp() == sc_time(31, SC_NS) ); f4=1; break;
34912855Sgabeblack@google.com      case  9: sc_assert( sc_time_stamp() == sc_time(32, SC_NS) ); f5=1; break;
35012855Sgabeblack@google.com      case 11: sc_assert( sc_time_stamp() == sc_time(34, SC_NS) ); f6=1; break;
35112855Sgabeblack@google.com      case 14: sc_assert( sc_time_stamp() == sc_time(41, SC_NS) ); f7=1; break;
35212855Sgabeblack@google.com      case 19: sc_assert( sc_time_stamp() == sc_time(53, SC_NS) ); f8=1; break;
35312855Sgabeblack@google.com      case 22: sc_assert( sc_time_stamp() == sc_time(61, SC_NS) ); f9=1; break;
35412855Sgabeblack@google.com      case 26: sc_assert( sc_time_stamp() == sc_time(65, SC_NS) ); f11=1; break;
35512855Sgabeblack@google.com      case 28: sc_assert( sc_time_stamp() == sc_time(67, SC_NS) ); f12=1; break;
35612855Sgabeblack@google.com      default: sc_assert( false ); break;
35712855Sgabeblack@google.com    }
35812855Sgabeblack@google.com    while (true)
35912855Sgabeblack@google.com    {
36012855Sgabeblack@google.com      wait();
36112855Sgabeblack@google.com      //cout << "CT() awoke at " << sc_time_stamp() << endl;
36212855Sgabeblack@google.com
36312855Sgabeblack@google.com    switch (count)
36412855Sgabeblack@google.com    {
36512855Sgabeblack@google.com      case  1: sc_assert( sc_delta_count() == 3 ); f13=1; break;
36612855Sgabeblack@google.com      case  2: sc_assert( sc_time_stamp() == sc_time(1, SC_NS) ); f14=1; break;
36712855Sgabeblack@google.com      case  3: sc_assert( sc_time_stamp() == sc_time(11, SC_NS) ); f15=1; break;
36812855Sgabeblack@google.com      case  6: sc_assert( sc_time_stamp() == sc_time(22, SC_NS) ); f16=1; break;
36912855Sgabeblack@google.com      case 20: sc_assert( sc_time_stamp() == sc_time(54, SC_NS) ); f17=1; break;
37012855Sgabeblack@google.com      default: sc_assert( false ); break;
37112855Sgabeblack@google.com    }
37212855Sgabeblack@google.com
37312855Sgabeblack@google.com    }
37412855Sgabeblack@google.com  }
37512855Sgabeblack@google.com
37612855Sgabeblack@google.com  void T()
37712855Sgabeblack@google.com  {
37812855Sgabeblack@google.com    //cout << "T() called at " << sc_time_stamp() << endl;
37912855Sgabeblack@google.com    switch (count)
38012855Sgabeblack@google.com    {
38112855Sgabeblack@google.com      case  0: sc_assert( sc_delta_count() == 0 ); f18=1; break;
38212855Sgabeblack@google.com      case  4: sc_assert( sc_time_stamp() == sc_time(20, SC_NS) ); f19=1; break;
38312855Sgabeblack@google.com      case  7: sc_assert( sc_time_stamp() == sc_time(30, SC_NS) ); f20=1; break;
38412855Sgabeblack@google.com      case  8: sc_assert( sc_time_stamp() == sc_time(31, SC_NS) ); f21=1; break;
38512855Sgabeblack@google.com      case  9: sc_assert( sc_time_stamp() == sc_time(32, SC_NS) ); f22=1; break;
38612855Sgabeblack@google.com      case 11: sc_assert( sc_time_stamp() == sc_time(34, SC_NS) ); f23=1; break;
38712855Sgabeblack@google.com      case 14: sc_assert( sc_time_stamp() == sc_time(41, SC_NS) ); f24=1; break;
38812855Sgabeblack@google.com      case 19: sc_assert( sc_time_stamp() == sc_time(53, SC_NS) ); f25=1; break;
38912855Sgabeblack@google.com      case 22: sc_assert( sc_time_stamp() == sc_time(61, SC_NS) ); f26=1; break;
39012855Sgabeblack@google.com      case 26: sc_assert( sc_time_stamp() == sc_time(65, SC_NS) ); f28=1; break;
39112855Sgabeblack@google.com      case 28: sc_assert( sc_time_stamp() == sc_time(67, SC_NS) ); f29=1; break;
39212855Sgabeblack@google.com      default: sc_assert( false ); break;
39312855Sgabeblack@google.com    }
39412855Sgabeblack@google.com    while (true)
39512855Sgabeblack@google.com    {
39612855Sgabeblack@google.com      wait(clk.default_event());
39712855Sgabeblack@google.com      //cout << "T() awoke at " << sc_time_stamp() << endl;
39812855Sgabeblack@google.com
39912855Sgabeblack@google.com    switch (count)
40012855Sgabeblack@google.com    {
40112855Sgabeblack@google.com      case  0: sc_assert( sc_delta_count() == 1 ); f30=1; break;
40212855Sgabeblack@google.com      case  1: sc_assert( sc_delta_count() == 3 ); f31=1; break;
40312855Sgabeblack@google.com      case  2: sc_assert( sc_time_stamp() == sc_time(1, SC_NS) ); f32=1; break;
40412855Sgabeblack@google.com      case  3: sc_assert( sc_time_stamp() == sc_time(11, SC_NS) ); f33=1; break;
40512855Sgabeblack@google.com      case  6: sc_assert( sc_time_stamp() == sc_time(22, SC_NS) ); f34=1; break;
40612855Sgabeblack@google.com      case 20: sc_assert( sc_time_stamp() == sc_time(54, SC_NS) ); f35=1; break;
40712855Sgabeblack@google.com      default: sc_assert( false ); break;
40812855Sgabeblack@google.com    }
40912855Sgabeblack@google.com
41012855Sgabeblack@google.com    }
41112855Sgabeblack@google.com  }
41212855Sgabeblack@google.com
41312855Sgabeblack@google.com  void M()
41412855Sgabeblack@google.com  {
41512855Sgabeblack@google.com    //cout << "M() called at " << sc_time_stamp() << endl;
41612855Sgabeblack@google.com    switch (count)
41712855Sgabeblack@google.com    {
41812855Sgabeblack@google.com      case  0: sc_assert( sc_delta_count() == 1 ); f36=1; break;
41912855Sgabeblack@google.com      case  1: sc_assert( sc_delta_count() == 3 ); f37=1; break;
42012855Sgabeblack@google.com      case  2: sc_assert( sc_time_stamp() == sc_time(1, SC_NS) ); f38=1; break;
42112855Sgabeblack@google.com      case  3: sc_assert( sc_time_stamp() == sc_time(11, SC_NS) ); f39=1; break;
42212855Sgabeblack@google.com      case  4: sc_assert( sc_time_stamp() == sc_time(20, SC_NS) ); f83=1; break;
42312855Sgabeblack@google.com      case  6: sc_assert( sc_time_stamp() == sc_time(22, SC_NS) ); f40=1; break;
42412855Sgabeblack@google.com      case  7: sc_assert( sc_time_stamp() == sc_time(30, SC_NS) ); f84=1; break;
42512855Sgabeblack@google.com      case  8: sc_assert( sc_time_stamp() == sc_time(31, SC_NS) ); f41=1; break;
42612855Sgabeblack@google.com      case  9: sc_assert( sc_time_stamp() == sc_time(32, SC_NS) ); f42=1; break;
42712855Sgabeblack@google.com      case 11: sc_assert( sc_time_stamp() == sc_time(34, SC_NS) ); f85=1; break;
42812855Sgabeblack@google.com      case 14: sc_assert( sc_time_stamp() == sc_time(41, SC_NS) ); f43=1; break;
42912855Sgabeblack@google.com      case 19: sc_assert( sc_time_stamp() == sc_time(53, SC_NS) ); f44=1; break;
43012855Sgabeblack@google.com      case 20: sc_assert( sc_time_stamp() == sc_time(54, SC_NS) ); f45=1; break;
43112855Sgabeblack@google.com      case 22: sc_assert( sc_time_stamp() == sc_time(61, SC_NS) ); f26=1; break;
43212855Sgabeblack@google.com      case 26: sc_assert( sc_time_stamp() == sc_time(65, SC_NS) ); f86=1; break;
43312855Sgabeblack@google.com      case 28: sc_assert( sc_time_stamp() == sc_time(67, SC_NS) ); f46=1; break;
43412855Sgabeblack@google.com      default: sc_assert( false ); break;
43512855Sgabeblack@google.com    }
43612855Sgabeblack@google.com  }
43712855Sgabeblack@google.com
43812855Sgabeblack@google.com  void CT2()
43912855Sgabeblack@google.com  {
44012855Sgabeblack@google.com    //cout << "CT2() called at " << sc_time_stamp() << endl;
44112855Sgabeblack@google.com    switch (count)
44212855Sgabeblack@google.com    {
44312855Sgabeblack@google.com        case 30: sc_assert( sc_time_stamp() == sc_time(105, SC_NS) ); f47=1; break;
44412855Sgabeblack@google.com        case 32: sc_assert( sc_time_stamp() == sc_time(125, SC_NS) ); f51=1; break;
44512855Sgabeblack@google.com        case 33: sc_assert( sc_time_stamp() == sc_time(135, SC_NS) ); f53=1; break;
44612855Sgabeblack@google.com        case 34: sc_assert( sc_time_stamp() == sc_time(145, SC_NS) ); f55=1; break;
44712855Sgabeblack@google.com        case 36: sc_assert( sc_time_stamp() == sc_time(160, SC_NS) ); f59=1; break;
44812855Sgabeblack@google.com        case 37: sc_assert( sc_time_stamp() == sc_time(165, SC_NS) ); f61=1; break;
44912855Sgabeblack@google.com        case 38: sc_assert( sc_time_stamp() == sc_time(175, SC_NS) ); f63=1; break;
45012855Sgabeblack@google.com        case 39: sc_assert( sc_time_stamp() == sc_time(185, SC_NS) ); f65=1; break;
45112855Sgabeblack@google.com        case 41: sc_assert( sc_time_stamp() == sc_time(205, SC_NS) ); f69=1; break;
45212855Sgabeblack@google.com        case 42: sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); f71=1; break;
45312855Sgabeblack@google.com        case 43: sc_assert( sc_time_stamp() == sc_time(215, SC_NS) ); f73=1; break;
45412855Sgabeblack@google.com        case 44: sc_assert( sc_time_stamp() == sc_time(225, SC_NS) ); f75=1; break;
45512855Sgabeblack@google.com        case 46: sc_assert( sc_time_stamp() == sc_time(240, SC_NS) ); f79=1; break;
45612855Sgabeblack@google.com        default: sc_assert( false ); break;
45712855Sgabeblack@google.com    }
45812855Sgabeblack@google.com    while (true)
45912855Sgabeblack@google.com    {
46012855Sgabeblack@google.com      wait();
46112855Sgabeblack@google.com      //cout << "CT2() awoke at " << sc_time_stamp() << endl;
46212855Sgabeblack@google.com      switch (count)
46312855Sgabeblack@google.com      {
46412855Sgabeblack@google.com        case 31: sc_assert( sc_time_stamp() == sc_time(115, SC_NS) ); f49=1; break;
46512855Sgabeblack@google.com        case 35: sc_assert( sc_time_stamp() == sc_time(155, SC_NS) ); f57=1; break;
46612855Sgabeblack@google.com        case 40: sc_assert( sc_time_stamp() == sc_time(195, SC_NS) ); f67=1; break;
46712855Sgabeblack@google.com        case 45: sc_assert( sc_time_stamp() == sc_time(235, SC_NS) ); f77=1; break;
46812855Sgabeblack@google.com        case 47: sc_assert( sc_time_stamp() == sc_time(245, SC_NS) ); f81=1; break;
46912855Sgabeblack@google.com        default: sc_assert( false ); break;
47012855Sgabeblack@google.com      }
47112855Sgabeblack@google.com    }
47212855Sgabeblack@google.com  }
47312855Sgabeblack@google.com
47412855Sgabeblack@google.com  void T2()
47512855Sgabeblack@google.com  {
47612855Sgabeblack@google.com    //cout << "T2() called at " << sc_time_stamp() << endl;
47712855Sgabeblack@google.com    switch (count)
47812855Sgabeblack@google.com    {
47912855Sgabeblack@google.com        case 30: sc_assert( sc_time_stamp() == sc_time(105, SC_NS) ); f48=1; break;
48012855Sgabeblack@google.com        case 32: sc_assert( sc_time_stamp() == sc_time(125, SC_NS) ); f52=1; break;
48112855Sgabeblack@google.com        case 33: sc_assert( sc_time_stamp() == sc_time(135, SC_NS) ); f54=1; break;
48212855Sgabeblack@google.com        case 34: sc_assert( sc_time_stamp() == sc_time(145, SC_NS) ); f56=1; break;
48312855Sgabeblack@google.com        case 36: sc_assert( sc_time_stamp() == sc_time(160, SC_NS) ); f60=1; break;
48412855Sgabeblack@google.com        case 37: sc_assert( sc_time_stamp() == sc_time(165, SC_NS) ); f62=1; break;
48512855Sgabeblack@google.com        case 38: sc_assert( sc_time_stamp() == sc_time(175, SC_NS) ); f64=1; break;
48612855Sgabeblack@google.com        case 39: sc_assert( sc_time_stamp() == sc_time(185, SC_NS) ); f66=1; break;
48712855Sgabeblack@google.com        case 41: sc_assert( sc_time_stamp() == sc_time(205, SC_NS) ); f70=1; break;
48812855Sgabeblack@google.com        case 42: sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); f72=1; break;
48912855Sgabeblack@google.com        case 43: sc_assert( sc_time_stamp() == sc_time(215, SC_NS) ); f74=1; break;
49012855Sgabeblack@google.com        case 44: sc_assert( sc_time_stamp() == sc_time(225, SC_NS) ); f76=1; break;
49112855Sgabeblack@google.com        case 46: sc_assert( sc_time_stamp() == sc_time(240, SC_NS) ); f80=1; break;
49212855Sgabeblack@google.com        default: sc_assert( false ); break;
49312855Sgabeblack@google.com    }
49412855Sgabeblack@google.com    while (true)
49512855Sgabeblack@google.com    {
49612855Sgabeblack@google.com      wait();
49712855Sgabeblack@google.com      //cout << "T2() awoke at " << sc_time_stamp() << endl;
49812855Sgabeblack@google.com      switch (count)
49912855Sgabeblack@google.com      {
50012855Sgabeblack@google.com        case 31: sc_assert( sc_time_stamp() == sc_time(115, SC_NS) ); f50=1; break;
50112855Sgabeblack@google.com        case 35: sc_assert( sc_time_stamp() == sc_time(155, SC_NS) ); f58=1; break;
50212855Sgabeblack@google.com        case 40: sc_assert( sc_time_stamp() == sc_time(195, SC_NS) ); f68=1; break;
50312855Sgabeblack@google.com        case 45: sc_assert( sc_time_stamp() == sc_time(235, SC_NS) ); f78=1; break;
50412855Sgabeblack@google.com        case 47: sc_assert( sc_time_stamp() == sc_time(245, SC_NS) ); f82=1; break;
50512855Sgabeblack@google.com        default: sc_assert( false ); break;
50612855Sgabeblack@google.com      }
50712855Sgabeblack@google.com    }
50812855Sgabeblack@google.com  }
50912855Sgabeblack@google.com
51012855Sgabeblack@google.com  void clock()
51112855Sgabeblack@google.com  {
51212855Sgabeblack@google.com    clk.write( !clk.read() );
51312855Sgabeblack@google.com  }
51412855Sgabeblack@google.com
51512855Sgabeblack@google.com  void clock2()
51612855Sgabeblack@google.com  {
51712855Sgabeblack@google.com    clk.write(0);
51812855Sgabeblack@google.com    wait(5, SC_NS);
51912855Sgabeblack@google.com    clk.write(1);
52012855Sgabeblack@google.com    wait(5, SC_NS);
52112855Sgabeblack@google.com  }
52212855Sgabeblack@google.com
52312855Sgabeblack@google.com  void suspend()
52412855Sgabeblack@google.com  {
52512855Sgabeblack@google.com    ct.suspend();
52612855Sgabeblack@google.com    t.suspend();
52712855Sgabeblack@google.com    m.suspend();
52812855Sgabeblack@google.com  }
52912855Sgabeblack@google.com
53012855Sgabeblack@google.com  void resume()
53112855Sgabeblack@google.com  {
53212855Sgabeblack@google.com    ct.resume();
53312855Sgabeblack@google.com    t.resume();
53412855Sgabeblack@google.com    m.resume();
53512855Sgabeblack@google.com  }
53612855Sgabeblack@google.com
53712855Sgabeblack@google.com  void disable()
53812855Sgabeblack@google.com  {
53912855Sgabeblack@google.com    ct.disable();
54012855Sgabeblack@google.com    t.disable();
54112855Sgabeblack@google.com    m.disable();
54212855Sgabeblack@google.com  }
54312855Sgabeblack@google.com
54412855Sgabeblack@google.com  void enable()
54512855Sgabeblack@google.com  {
54612855Sgabeblack@google.com    ct.enable();
54712855Sgabeblack@google.com    t.enable();
54812855Sgabeblack@google.com    m.enable();
54912855Sgabeblack@google.com  }
55012855Sgabeblack@google.com
55112855Sgabeblack@google.com  void sync_reset_on()
55212855Sgabeblack@google.com  {
55312855Sgabeblack@google.com    ct.sync_reset_on();
55412855Sgabeblack@google.com    t.sync_reset_on();
55512855Sgabeblack@google.com    m.sync_reset_on();
55612855Sgabeblack@google.com  }
55712855Sgabeblack@google.com
55812855Sgabeblack@google.com  void sync_reset_off()
55912855Sgabeblack@google.com  {
56012855Sgabeblack@google.com    ct.sync_reset_off();
56112855Sgabeblack@google.com    t.sync_reset_off();
56212855Sgabeblack@google.com    m.sync_reset_off();
56312855Sgabeblack@google.com  }
56412855Sgabeblack@google.com
56512855Sgabeblack@google.com  SC_HAS_PROCESS(Top);
56612855Sgabeblack@google.com};
56712855Sgabeblack@google.com
56812855Sgabeblack@google.comint sc_main(int argc, char* argv[])
56912855Sgabeblack@google.com{
57012855Sgabeblack@google.com  Top top("top");
57112855Sgabeblack@google.com
57212855Sgabeblack@google.com  sc_start();
57312855Sgabeblack@google.com
57412855Sgabeblack@google.com  sc_assert(top.f1);
57512855Sgabeblack@google.com  sc_assert(top.f2);
57612855Sgabeblack@google.com  sc_assert(top.f3);
57712855Sgabeblack@google.com  sc_assert(top.f4);
57812855Sgabeblack@google.com  sc_assert(top.f5);
57912855Sgabeblack@google.com  sc_assert(top.f6);
58012855Sgabeblack@google.com  sc_assert(top.f7);
58112855Sgabeblack@google.com  sc_assert(top.f8);
58212855Sgabeblack@google.com  sc_assert(top.f9);
58312855Sgabeblack@google.com  sc_assert(top.f11);
58412855Sgabeblack@google.com  sc_assert(top.f12);
58512855Sgabeblack@google.com  sc_assert(top.f13);
58612855Sgabeblack@google.com  sc_assert(top.f14);
58712855Sgabeblack@google.com  sc_assert(top.f15);
58812855Sgabeblack@google.com  sc_assert(top.f16);
58912855Sgabeblack@google.com  sc_assert(top.f17);
59012855Sgabeblack@google.com  sc_assert(top.f18);
59112855Sgabeblack@google.com  sc_assert(top.f19);
59212855Sgabeblack@google.com  sc_assert(top.f20);
59312855Sgabeblack@google.com  sc_assert(top.f21);
59412855Sgabeblack@google.com  sc_assert(top.f22);
59512855Sgabeblack@google.com  sc_assert(top.f23);
59612855Sgabeblack@google.com  sc_assert(top.f24);
59712855Sgabeblack@google.com  sc_assert(top.f25);
59812855Sgabeblack@google.com  sc_assert(top.f26);
59912855Sgabeblack@google.com  sc_assert(top.f28);
60012855Sgabeblack@google.com  sc_assert(top.f29);
60112855Sgabeblack@google.com  sc_assert(top.f30);
60212855Sgabeblack@google.com  sc_assert(top.f31);
60312855Sgabeblack@google.com  sc_assert(top.f32);
60412855Sgabeblack@google.com  sc_assert(top.f33);
60512855Sgabeblack@google.com  sc_assert(top.f34);
60612855Sgabeblack@google.com  sc_assert(top.f35);
60712855Sgabeblack@google.com  sc_assert(top.f36);
60812855Sgabeblack@google.com  sc_assert(top.f37);
60912855Sgabeblack@google.com  sc_assert(top.f38);
61012855Sgabeblack@google.com  sc_assert(top.f39);
61112855Sgabeblack@google.com  sc_assert(top.f40);
61212855Sgabeblack@google.com  sc_assert(top.f41);
61312855Sgabeblack@google.com  sc_assert(top.f42);
61412855Sgabeblack@google.com  sc_assert(top.f43);
61512855Sgabeblack@google.com  sc_assert(top.f44);
61612855Sgabeblack@google.com  sc_assert(top.f45);
61712855Sgabeblack@google.com  sc_assert(top.f46);
61812855Sgabeblack@google.com  sc_assert(top.f47);
61912855Sgabeblack@google.com  sc_assert(top.f48);
62012855Sgabeblack@google.com  sc_assert(top.f49);
62112855Sgabeblack@google.com  sc_assert(top.f50);
62212855Sgabeblack@google.com  sc_assert(top.f51);
62312855Sgabeblack@google.com  sc_assert(top.f52);
62412855Sgabeblack@google.com  sc_assert(top.f53);
62512855Sgabeblack@google.com  sc_assert(top.f54);
62612855Sgabeblack@google.com  sc_assert(top.f55);
62712855Sgabeblack@google.com  sc_assert(top.f56);
62812855Sgabeblack@google.com  sc_assert(top.f57);
62912855Sgabeblack@google.com  sc_assert(top.f58);
63012855Sgabeblack@google.com  sc_assert(top.f59);
63112855Sgabeblack@google.com  sc_assert(top.f60);
63212855Sgabeblack@google.com  sc_assert(top.f61);
63312855Sgabeblack@google.com  sc_assert(top.f62);
63412855Sgabeblack@google.com  sc_assert(top.f63);
63512855Sgabeblack@google.com  sc_assert(top.f64);
63612855Sgabeblack@google.com  sc_assert(top.f65);
63712855Sgabeblack@google.com  sc_assert(top.f66);
63812855Sgabeblack@google.com  sc_assert(top.f67);
63912855Sgabeblack@google.com  sc_assert(top.f68);
64012855Sgabeblack@google.com  sc_assert(top.f69);
64112855Sgabeblack@google.com  sc_assert(top.f70);
64212855Sgabeblack@google.com  sc_assert(top.f71);
64312855Sgabeblack@google.com  sc_assert(top.f72);
64412855Sgabeblack@google.com  sc_assert(top.f73);
64512855Sgabeblack@google.com  sc_assert(top.f74);
64612855Sgabeblack@google.com  sc_assert(top.f75);
64712855Sgabeblack@google.com  sc_assert(top.f76);
64812855Sgabeblack@google.com  sc_assert(top.f77);
64912855Sgabeblack@google.com  sc_assert(top.f78);
65012855Sgabeblack@google.com  sc_assert(top.f79);
65112855Sgabeblack@google.com  sc_assert(top.f80);
65212855Sgabeblack@google.com  sc_assert(top.f81);
65312855Sgabeblack@google.com  sc_assert(top.f82);
65412855Sgabeblack@google.com  sc_assert(top.f83);
65512855Sgabeblack@google.com  sc_assert(top.f84);
65612855Sgabeblack@google.com  sc_assert(top.f85);
65712855Sgabeblack@google.com  sc_assert(top.f86);
65812855Sgabeblack@google.com
65912855Sgabeblack@google.com  cout << endl << "Success" << endl;
66012855Sgabeblack@google.com  return 0;
66112855Sgabeblack@google.com}
662