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_timeout.cpp -- test for 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: proc_ctrl_timeout.cpp,v $ 2712855Sgabeblack@google.com// Revision 1.2 2011/05/08 19:18:46 acg 2812855Sgabeblack@google.com// Andy Goodrich: remove extraneous + prefixes from git diff. 2912855Sgabeblack@google.com// 3012855Sgabeblack@google.com 3112855Sgabeblack@google.com// Process control methods interacting with time-out and event lists 3212855Sgabeblack@google.com 3312855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES 3412855Sgabeblack@google.com 3512855Sgabeblack@google.com#include <systemc> 3612855Sgabeblack@google.com 3712855Sgabeblack@google.comusing namespace sc_core; 3812855Sgabeblack@google.comusing std::cout; 3912855Sgabeblack@google.comusing std::endl; 4012855Sgabeblack@google.com 4112855Sgabeblack@google.comstruct Top: sc_module 4212855Sgabeblack@google.com{ 4312855Sgabeblack@google.com Top(sc_module_name _name) 4412855Sgabeblack@google.com { 4512855Sgabeblack@google.com SC_THREAD(calling); 4612855Sgabeblack@google.com 4712855Sgabeblack@google.com SC_THREAD(target1); 4812855Sgabeblack@google.com t1 = sc_get_current_process_handle(); 4912855Sgabeblack@google.com 5012855Sgabeblack@google.com SC_METHOD(target2); 5112855Sgabeblack@google.com t2 = sc_get_current_process_handle(); 5212855Sgabeblack@google.com 5312855Sgabeblack@google.com SC_THREAD(target3); 5412855Sgabeblack@google.com t3 = sc_get_current_process_handle(); 5512855Sgabeblack@google.com 5612855Sgabeblack@google.com SC_METHOD(target4); 5712855Sgabeblack@google.com t4 = sc_get_current_process_handle(); 5812855Sgabeblack@google.com 5912855Sgabeblack@google.com SC_METHOD(target5); 6012855Sgabeblack@google.com t5 = sc_get_current_process_handle(); 6112855Sgabeblack@google.com t5.disable(); 6212855Sgabeblack@google.com sensitive << ev4; 6312855Sgabeblack@google.com 6412855Sgabeblack@google.com count = 0; 6512855Sgabeblack@google.com f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = f10 = 0; 6612855Sgabeblack@google.com f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0; 6712855Sgabeblack@google.com f20 = f21 = f22 = 0; 6812855Sgabeblack@google.com } 6912855Sgabeblack@google.com 7012855Sgabeblack@google.com sc_process_handle t1, t2, t3, t4, t5; 7112855Sgabeblack@google.com sc_event ev1, ev2, ev3, ev4; 7212855Sgabeblack@google.com int count; 7312855Sgabeblack@google.com int f1, f2, f3, f4, f5, f6, f7, f8, f9, f10; 7412855Sgabeblack@google.com int f11, f12, f13, f14, f15, f16, f17, f18, f19; 7512855Sgabeblack@google.com int f20, f21, f22; 7612855Sgabeblack@google.com 7712855Sgabeblack@google.com void calling() 7812855Sgabeblack@google.com { 7912855Sgabeblack@google.com wait(SC_ZERO_TIME); 8012855Sgabeblack@google.com count = 1; 8112855Sgabeblack@google.com wait(15, SC_NS); 8212855Sgabeblack@google.com 8312855Sgabeblack@google.com count = 2; 8412855Sgabeblack@google.com try { 8512855Sgabeblack@google.com t1.disable(); 8612855Sgabeblack@google.com sc_assert(false); 8712855Sgabeblack@google.com } 8812855Sgabeblack@google.com catch (sc_exception ex) { 8912855Sgabeblack@google.com //cout << "Exception caught at " << sc_time_stamp() << endl; 9012855Sgabeblack@google.com f7 = 1; 9112855Sgabeblack@google.com } 9212855Sgabeblack@google.com 9312855Sgabeblack@google.com try { 9412855Sgabeblack@google.com t2.disable(); 9512855Sgabeblack@google.com sc_assert(false); 9612855Sgabeblack@google.com } 9712855Sgabeblack@google.com catch (sc_exception ex) { 9812855Sgabeblack@google.com //cout << "Exception caught at " << sc_time_stamp() << endl; 9912855Sgabeblack@google.com f8 = 1; 10012855Sgabeblack@google.com } 10112855Sgabeblack@google.com wait(SC_ZERO_TIME); 10212855Sgabeblack@google.com t1.kill(); 10312855Sgabeblack@google.com t2.kill(); 10412855Sgabeblack@google.com ev1.notify(); 10512855Sgabeblack@google.com wait(sc_time(100, SC_NS) - sc_time_stamp()); 10612855Sgabeblack@google.com 10712855Sgabeblack@google.com count = 6; 10812855Sgabeblack@google.com t3.disable(); 10912855Sgabeblack@google.com t4.disable(); 11012855Sgabeblack@google.com wait(10, SC_NS); 11112855Sgabeblack@google.com 11212855Sgabeblack@google.com ev2.notify(); 11312855Sgabeblack@google.com wait(10, SC_NS); 11412855Sgabeblack@google.com 11512855Sgabeblack@google.com t3.enable(); 11612855Sgabeblack@google.com t4.enable(); 11712855Sgabeblack@google.com wait(10, SC_NS); 11812855Sgabeblack@google.com 11912855Sgabeblack@google.com ev3.notify(); 12012855Sgabeblack@google.com wait(10, SC_NS); 12112855Sgabeblack@google.com 12212855Sgabeblack@google.com ev2.notify(); 12312855Sgabeblack@google.com wait(sc_time(200, SC_NS) - sc_time_stamp()); 12412855Sgabeblack@google.com 12512855Sgabeblack@google.com count = 7; 12612855Sgabeblack@google.com ev1.notify(); 12712855Sgabeblack@google.com wait(10, SC_NS); 12812855Sgabeblack@google.com 12912855Sgabeblack@google.com t3.suspend(); 13012855Sgabeblack@google.com t4.suspend(); 13112855Sgabeblack@google.com wait(10, SC_NS); 13212855Sgabeblack@google.com 13312855Sgabeblack@google.com ev2.notify(); 13412855Sgabeblack@google.com wait(10, SC_NS); 13512855Sgabeblack@google.com 13612855Sgabeblack@google.com t3.resume(); 13712855Sgabeblack@google.com t4.resume(); 13812855Sgabeblack@google.com wait(10, SC_NS); 13912855Sgabeblack@google.com 14012855Sgabeblack@google.com ev3.notify(); 14112855Sgabeblack@google.com wait(sc_time(300, SC_NS) - sc_time_stamp()); 14212855Sgabeblack@google.com 14312855Sgabeblack@google.com count = 8; 14412855Sgabeblack@google.com ev1.notify(); 14512855Sgabeblack@google.com wait(10, SC_NS); 14612855Sgabeblack@google.com 14712855Sgabeblack@google.com ev2.notify(); 14812855Sgabeblack@google.com wait(10, SC_NS); 14912855Sgabeblack@google.com 15012855Sgabeblack@google.com t3.reset(); 15112855Sgabeblack@google.com count = 9; 15212855Sgabeblack@google.com wait(10, SC_NS); 15312855Sgabeblack@google.com 15412855Sgabeblack@google.com ev3.notify(); 15512855Sgabeblack@google.com wait(10, SC_NS); 15612855Sgabeblack@google.com 15712855Sgabeblack@google.com ev1.notify(); 15812855Sgabeblack@google.com wait(10, SC_NS); 15912855Sgabeblack@google.com 16012855Sgabeblack@google.com ev2.notify(); 16112855Sgabeblack@google.com wait(sc_time(400, SC_NS) - sc_time_stamp()); 16212855Sgabeblack@google.com t3.disable(); 16312855Sgabeblack@google.com t4.disable(); 16412855Sgabeblack@google.com 16512855Sgabeblack@google.com // Now target5 16612855Sgabeblack@google.com count = 9; 16712855Sgabeblack@google.com t5.enable(); 16812855Sgabeblack@google.com ev4.notify(); 16912855Sgabeblack@google.com wait(SC_ZERO_TIME); 17012855Sgabeblack@google.com 17112855Sgabeblack@google.com count = 10; 17212855Sgabeblack@google.com ev3.notify(3, SC_NS); 17312855Sgabeblack@google.com ev2.notify(2, SC_NS); 17412855Sgabeblack@google.com ev1.notify(1, SC_NS); 17512855Sgabeblack@google.com wait(10, SC_NS); 17612855Sgabeblack@google.com 17712855Sgabeblack@google.com count = 11; 17812855Sgabeblack@google.com t5.reset(); // On reset, dynamic sensit is cleared, then target is called again 17912855Sgabeblack@google.com wait(SC_ZERO_TIME); 18012855Sgabeblack@google.com 18112855Sgabeblack@google.com count = 12; 18212855Sgabeblack@google.com ev3.notify(3, SC_NS); 18312855Sgabeblack@google.com ev2.notify(2, SC_NS); 18412855Sgabeblack@google.com ev1.notify(1, SC_NS); 18512855Sgabeblack@google.com wait(10, SC_NS); 18612855Sgabeblack@google.com 18712855Sgabeblack@google.com count = 13; 18812855Sgabeblack@google.com ev4.notify(); 18912855Sgabeblack@google.com wait(SC_ZERO_TIME); 19012855Sgabeblack@google.com 19112855Sgabeblack@google.com count = 14; 19212855Sgabeblack@google.com try { 19312855Sgabeblack@google.com t5.disable(); // Disabling a process waiting on a time-out 19412855Sgabeblack@google.com } 19512855Sgabeblack@google.com catch (sc_exception ex) { 19612855Sgabeblack@google.com //cout << "Exception caught at " << sc_time_stamp() << endl; 19712855Sgabeblack@google.com f21 = 1; 19812855Sgabeblack@google.com } 19912855Sgabeblack@google.com wait(sc_time(500, SC_NS) - sc_time_stamp()); 20012855Sgabeblack@google.com 20112855Sgabeblack@google.com count = 15; 20212855Sgabeblack@google.com t5.reset(); 20312855Sgabeblack@google.com wait(10, SC_NS); 20412855Sgabeblack@google.com 20512855Sgabeblack@google.com count = 16; 20612855Sgabeblack@google.com ev4.notify(); 20712855Sgabeblack@google.com wait(10, SC_NS); 20812855Sgabeblack@google.com 20912855Sgabeblack@google.com sc_stop(); 21012855Sgabeblack@google.com } 21112855Sgabeblack@google.com 21212855Sgabeblack@google.com void target1() 21312855Sgabeblack@google.com { 21412855Sgabeblack@google.com //cout << "target1() called at " << sc_time_stamp() << " count = " << count << endl; 21512855Sgabeblack@google.com switch (count) 21612855Sgabeblack@google.com { 21712855Sgabeblack@google.com case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f1=1; break; 21812855Sgabeblack@google.com default: sc_assert( false ); break; 21912855Sgabeblack@google.com } 22012855Sgabeblack@google.com 22112855Sgabeblack@google.com for (;;) 22212855Sgabeblack@google.com { 22312855Sgabeblack@google.com wait(10, SC_NS); 22412855Sgabeblack@google.com //cout << "target1() awoke at " << sc_time_stamp() << " count = " << count << endl; 22512855Sgabeblack@google.com switch (count) 22612855Sgabeblack@google.com { 22712855Sgabeblack@google.com case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); f5=1; break; 22812855Sgabeblack@google.com default: sc_assert( false ); break; 22912855Sgabeblack@google.com } 23012855Sgabeblack@google.com } 23112855Sgabeblack@google.com } 23212855Sgabeblack@google.com 23312855Sgabeblack@google.com void target2() 23412855Sgabeblack@google.com { 23512855Sgabeblack@google.com //cout << "target2() called at " << sc_time_stamp() << " count = " << count << endl; 23612855Sgabeblack@google.com switch (count) 23712855Sgabeblack@google.com { 23812855Sgabeblack@google.com case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f2=1; break; 23912855Sgabeblack@google.com case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); f6=1; break; 24012855Sgabeblack@google.com default: sc_assert( false ); break; 24112855Sgabeblack@google.com } 24212855Sgabeblack@google.com next_trigger(10, SC_NS); 24312855Sgabeblack@google.com } 24412855Sgabeblack@google.com 24512855Sgabeblack@google.com void target3() 24612855Sgabeblack@google.com { 24712855Sgabeblack@google.com //cout << "target3() called at " << sc_time_stamp() << " count = " << count << endl; 24812855Sgabeblack@google.com switch (count) 24912855Sgabeblack@google.com { 25012855Sgabeblack@google.com case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f3=1; break; 25112855Sgabeblack@google.com case 8: sc_assert( sc_time_stamp() == sc_time(320, SC_NS) ); f13=1; break; 25212855Sgabeblack@google.com default: sc_assert( false ); break; 25312855Sgabeblack@google.com } 25412855Sgabeblack@google.com 25512855Sgabeblack@google.com for (;;) 25612855Sgabeblack@google.com { 25712855Sgabeblack@google.com wait(ev1 & ev2 & ev3); 25812855Sgabeblack@google.com //cout << "target3() awoke at " << sc_time_stamp() << " count = " << count << endl; 25912855Sgabeblack@google.com switch (count) 26012855Sgabeblack@google.com { 26112855Sgabeblack@google.com case 6: sc_assert( sc_time_stamp() == sc_time(140, SC_NS) ); f9=1; break; 26212855Sgabeblack@google.com case 7: sc_assert( sc_time_stamp() == sc_time(240, SC_NS) ); f11=1; break; 26312855Sgabeblack@google.com case 9: sc_assert( sc_time_stamp() == sc_time(350, SC_NS) ); f15=1; break; 26412855Sgabeblack@google.com default: sc_assert( false ); break; 26512855Sgabeblack@google.com } 26612855Sgabeblack@google.com } 26712855Sgabeblack@google.com } 26812855Sgabeblack@google.com 26912855Sgabeblack@google.com void target4() 27012855Sgabeblack@google.com { 27112855Sgabeblack@google.com //cout << "target4() called at " << sc_time_stamp() << " count = " << count << endl; 27212855Sgabeblack@google.com switch (count) 27312855Sgabeblack@google.com { 27412855Sgabeblack@google.com case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f4=1; break; 27512855Sgabeblack@google.com case 6: sc_assert( sc_time_stamp() == sc_time(140, SC_NS) ); f10=1; break; 27612855Sgabeblack@google.com case 7: sc_assert( sc_time_stamp() == sc_time(240, SC_NS) ); f12=1; break; 27712855Sgabeblack@google.com case 9: sc_assert( sc_time_stamp() == sc_time(330, SC_NS) ); f14=1; break; 27812855Sgabeblack@google.com default: sc_assert( false ); break; 27912855Sgabeblack@google.com } 28012855Sgabeblack@google.com next_trigger(ev1 & ev2 & ev3); 28112855Sgabeblack@google.com } 28212855Sgabeblack@google.com 28312855Sgabeblack@google.com void target5() 28412855Sgabeblack@google.com { 28512855Sgabeblack@google.com //cout << "target5() called at " << sc_time_stamp() << " count = " << count << endl; 28612855Sgabeblack@google.com switch (count) 28712855Sgabeblack@google.com { 28812855Sgabeblack@google.com case 9: sc_assert( sc_time_stamp() == sc_time(400, SC_NS) ); f16=1; break; 28912855Sgabeblack@google.com case 10: sc_assert( sc_time_stamp() == sc_time(403, SC_NS) ); f17=1; break; 29012855Sgabeblack@google.com case 11: sc_assert( sc_time_stamp() == sc_time(410, SC_NS) ); f18=1; break; 29112855Sgabeblack@google.com case 12: sc_assert( sc_time_stamp() == sc_time(413, SC_NS) ); f19=1; break; 29212855Sgabeblack@google.com case 14: sc_assert( sc_time_stamp() == sc_time(424, SC_NS) ); break; 29312855Sgabeblack@google.com case 15: sc_assert( sc_time_stamp() == sc_time(500, SC_NS) ); f20=1; break; 29412855Sgabeblack@google.com case 16: sc_assert( sc_time_stamp() == sc_time(510, SC_NS) ); f22=1; break; 29512855Sgabeblack@google.com default: sc_assert( false ); break; 29612855Sgabeblack@google.com } 29712855Sgabeblack@google.com if (count < 12) 29812855Sgabeblack@google.com next_trigger(ev1 & ev2 & ev3); 29912855Sgabeblack@google.com else if (count == 12) 30012855Sgabeblack@google.com next_trigger(11, SC_NS, ev3); 30112855Sgabeblack@google.com else if (count > 12) 30212855Sgabeblack@google.com next_trigger(); 30312855Sgabeblack@google.com } 30412855Sgabeblack@google.com 30512855Sgabeblack@google.com SC_HAS_PROCESS(Top); 30612855Sgabeblack@google.com}; 30712855Sgabeblack@google.com 30812855Sgabeblack@google.comint sc_main(int argc, char* argv[]) 30912855Sgabeblack@google.com{ 31012855Sgabeblack@google.com Top top("top"); 31112855Sgabeblack@google.com 31212855Sgabeblack@google.com sc_start(); 31312855Sgabeblack@google.com 31412855Sgabeblack@google.com sc_assert( top.f1 ); 31512855Sgabeblack@google.com sc_assert( top.f2 ); 31612855Sgabeblack@google.com sc_assert( top.f3 ); 31712855Sgabeblack@google.com sc_assert( top.f4 ); 31812855Sgabeblack@google.com sc_assert( top.f5 ); 31912855Sgabeblack@google.com sc_assert( top.f6 ); 32012855Sgabeblack@google.com sc_assert( top.f7 ); 32112855Sgabeblack@google.com sc_assert( top.f8 ); 32212855Sgabeblack@google.com sc_assert( top.f9 ); 32312855Sgabeblack@google.com sc_assert( top.f10 ); 32412855Sgabeblack@google.com sc_assert( top.f11 ); 32512855Sgabeblack@google.com sc_assert( top.f12 ); 32612855Sgabeblack@google.com sc_assert( top.f13 ); 32712855Sgabeblack@google.com sc_assert( top.f14 ); 32812855Sgabeblack@google.com sc_assert( top.f15 ); 32912855Sgabeblack@google.com sc_assert( top.f16 ); 33012855Sgabeblack@google.com sc_assert( top.f17 ); 33112855Sgabeblack@google.com sc_assert( top.f18 ); 33212855Sgabeblack@google.com sc_assert( top.f19 ); 33312855Sgabeblack@google.com sc_assert( top.f20 ); 33412855Sgabeblack@google.com sc_assert( top.f21 ); 33512855Sgabeblack@google.com sc_assert( top.f22 ); 33612855Sgabeblack@google.com 33712855Sgabeblack@google.com cout << endl << "Success" << endl; 33812855Sgabeblack@google.com return 0; 33912855Sgabeblack@google.com} 34012855Sgabeblack@google.com 341