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// suspend_resume.cpp -- test for 21// 22// Original Author: John Aynsley, Doulos, Inc. 23// 24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and 25// 26// $Log: suspend_resume.cpp,v $ 27// Revision 1.2 2011/05/08 19:18:46 acg 28// Andy Goodrich: remove extraneous + prefixes from git diff. 29// 30 31#define SC_INCLUDE_DYNAMIC_PROCESSES 32 33#include <systemc> 34 35using namespace sc_core; 36using std::cout; 37using std::endl; 38 39struct M1: sc_module 40{ 41 M1(sc_module_name _name) 42 { 43 SC_THREAD(ticker); 44 SC_THREAD(calling); 45 SC_THREAD(target); 46 t = sc_get_current_process_handle(); 47 } 48 49 sc_process_handle t; 50 sc_event ev; 51 52 void ticker() 53 { 54 for (;;) 55 { 56 wait(10, SC_NS); 57 ev.notify(); 58 } 59 } 60 61 void calling() 62 { 63 wait(15, SC_NS); 64 // Target runs at time 10 NS due to notification 65 66 t.suspend(); 67 wait(10, SC_NS); 68 // Target does not run at time 20 NS while suspended 69 70 t.resume(); 71 // Target runs at time 25 NS when resume is called 72 73 wait(10, SC_NS); 74 // Target runs at time 30 NS due to notification 75 76 t.disable(); 77 wait(10, SC_NS); 78 // Target does not run at time 40 NS while disabled 79 80 t.enable(); 81 // Target does not run at time 45 NS when enable is called 82 83 wait(10, SC_NS); 84 // Target runs at time 50 NS due to notification 85 86 sc_stop(); 87 } 88 89 void target() 90 { 91 for (;;) 92 { 93 wait(ev); 94 cout << "Target awoke at " << sc_time_stamp() << endl; 95 } 96 } 97 98 SC_HAS_PROCESS(M1); 99}; 100 101int sc_main(int argc, char* argv[]) 102{ 103 M1 m("m"); 104 105 sc_start(); 106 107 cout << endl << "Success" << endl; 108 return 0; 109} 110 111