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/***************************************************************************** 21 22 Original Author: Bishnupriya Bhattacharya, Cadence Design Systems, 23 September 5, 2003 24 25 *****************************************************************************/ 26 27// test dynamic method processes and hierarchical dynamic process naming 28 29/***************************************************************************** 30 31 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 32 changes you are making here. 33 34 Name, Affiliation, Date: 35 Description of Modification: 36 37 *****************************************************************************/ 38// $Log: test02.cpp,v $ 39// Revision 1.3 2011/03/06 06:55:19 acg 40// Andy Goodrich: removed carriage returns. 41// 42// Revision 1.2 2011/02/01 17:17:40 acg 43// Andy Goodrich: update of copyright notice, added visible CVS logging. 44// 45 46#define SC_INCLUDE_DYNAMIC_PROCESSES 47#include <systemc.h> 48 49int function_method(double d) 50{ 51 cout << endl << sc_time_stamp() << ", " 52 << sc_get_current_process_handle().name() 53 << ": function_method sees " << d << endl; 54 return int(d); 55} 56 57void function_thread(double d) 58{ 59 cout << endl << sc_time_stamp() << ", " 60 << sc_get_current_process_handle().name() 61 << ": function_thread sees " << d << endl; 62 sc_core::wait(10, SC_NS); 63 cout << sc_time_stamp() << ", " 64 << sc_get_current_process_handle().name() 65 << ": ending thread" << endl; 66} 67 68class module1 : public sc_module 69{ 70private: 71 sc_event& ev; 72 int method_count; 73 int r; 74public: 75 76 SC_HAS_PROCESS(module1); 77 78 module1(sc_module_name name, sc_event& event) : sc_module(name), 79 ev(event), method_count(0), r(0) 80 { 81 SC_THREAD(main); 82 cout << endl << sc_time_stamp() << ": CTOR, Before spawning function_method " << endl; 83 sc_spawn_options o1; 84 o1.spawn_method(); 85 o1.dont_initialize(); 86 o1.set_sensitivity(&ev); 87 sc_process_handle h4 = sc_spawn(&r, sc_bind(&function_method, 1.2345), "event_sensitive_method", &o1); 88 89 } 90 91 void main() 92 { 93 int r; 94 sc_event e1, e2, e3, e4; 95 sc_spawn_options o1, o2, o3, o4; 96 97 cout << endl << sc_time_stamp() << ", " 98 << sc_get_current_process_handle().name() 99 << ": main thread, Before spawning round robin methods " 100 << endl << endl; 101 102 e1.notify(15, SC_NS); 103 o1.spawn_method(); 104 o2.spawn_method(); 105 o3.spawn_method(); 106 o4.spawn_method(); 107 108 // Spawn several methods that co-operatively execute in round robin order 109 110 sc_spawn( 111 sc_bind(&module1::round_robin, this, "1", sc_ref(e1), sc_ref(e2), 1), "method1", &o1); 112 sc_spawn( 113 sc_bind(&module1::round_robin, this, "2", sc_ref(e2), sc_ref(e3), 1), "method2", &o2); 114 sc_spawn( 115 sc_bind(&module1::round_robin, this, "3", sc_ref(e3), sc_ref(e4), 1), "method3", &o3); 116 sc_spawn( 117 sc_bind(&module1::round_robin, this, "4", sc_ref(e4), sc_ref(e1), 1), "method4", &o4); 118 119 120 cout << endl << sc_time_stamp() << ", " 121 << sc_get_current_process_handle().name() 122 << ": main thread, Issuing wait(60, SC_NS)" << endl; 123 124 sc_core::wait(60, SC_NS); 125 126 cout << endl << sc_time_stamp() << ", " 127 << sc_get_current_process_handle().name() 128 << ": Done main thread." << endl; 129 } 130 131 void round_robin(const char *str, sc_event& receive, sc_event& send, int cnt) 132 { 133 cout << sc_time_stamp() << ", " 134 << sc_get_current_process_handle().name() 135 << ": In Round robin method " << str; 136 137 if (method_count < 4) { 138 method_count++; 139 next_trigger(receive); 140 cout << ". Issued next_trigger. " << endl; 141 } else { 142 send.notify(10, SC_NS); 143 cout << ". Notified. Ending Round robin method " << str << endl; 144 } 145 146 } 147 148}; 149 150int sc_main (int argc , char *argv[]) 151{ 152 sc_event event1; 153 event1.notify(55, SC_NS); 154 155 module1 mod1("mod1", event1); 156 sc_start(100, SC_NS); 157 cout << endl << sc_time_stamp() << ": sc_main, Before spawning function_thread " << endl; 158 sc_process_handle h4 = sc_spawn(sc_bind(&function_thread, 6.789)); 159 sc_start(100, SC_NS); 160 return 0; 161} 162