disable_enable.cpp revision 12855
112169Sgabeblack@google.com/***************************************************************************** 212169Sgabeblack@google.com 312169Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412169Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512169Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612169Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712169Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812169Sgabeblack@google.com License. You may obtain a copy of the License at 912169Sgabeblack@google.com 1012169Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112169Sgabeblack@google.com 1212169Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312169Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412169Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512169Sgabeblack@google.com implied. See the License for the specific language governing 1612169Sgabeblack@google.com permissions and limitations under the License. 1712169Sgabeblack@google.com 1812169Sgabeblack@google.com *****************************************************************************/ 1912169Sgabeblack@google.com 2012169Sgabeblack@google.com// disable_enable.cpp -- test for 2112169Sgabeblack@google.com// 2212169Sgabeblack@google.com// Original Author: John Aynsley, Doulos Inc. 2312169Sgabeblack@google.com// 2412169Sgabeblack@google.com// MODIFICATION LOG - modifiers, enter your name, affiliation, date and 2512169Sgabeblack@google.com// 2612169Sgabeblack@google.com// $Log: disable_enable.cpp,v $ 2712169Sgabeblack@google.com// Revision 1.2 2011/05/08 19:18:46 acg 2812169Sgabeblack@google.com// Andy Goodrich: remove extraneous + prefixes from git diff. 2912169Sgabeblack@google.com// 3012169Sgabeblack@google.com 3112169Sgabeblack@google.com// disable() should take effect only the next evaluation phase 3212169Sgabeblack@google.com 3312169Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES 3412169Sgabeblack@google.com 3512169Sgabeblack@google.com#include <systemc> 3612169Sgabeblack@google.com 3712169Sgabeblack@google.comusing namespace sc_core; 3812169Sgabeblack@google.comusing namespace std; 3912169Sgabeblack@google.com 4012169Sgabeblack@google.comstruct Top: sc_module 4112169Sgabeblack@google.com{ 4212169Sgabeblack@google.com Top(sc_module_name _name) 4312169Sgabeblack@google.com : count(0) 4412169Sgabeblack@google.com { 4512169Sgabeblack@google.com SC_THREAD(control); 4612169Sgabeblack@google.com SC_THREAD(target); 4712169Sgabeblack@google.com t = sc_get_current_process_handle(); 4812169Sgabeblack@google.com 4912169Sgabeblack@google.com f0 = f1 = f2 = f3 = f4 = f5 = 0; 5012169Sgabeblack@google.com } 5112169Sgabeblack@google.com 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