test01.cpp revision 12855:588919e0e4aa
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 test01.cpp -- Demo "new" dynamic method support. 23 24 25 See the README file for a description of these capabilities. This demo 26 excercises all of the major capabilities. 27 28 Original Author: Stuart Swan, Cadence Design Systems, Inc., 2002-10-22 29 30 *****************************************************************************/ 31 32/***************************************************************************** 33 34 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 35 changes you are making here. 36 37 Name, Affiliation, Date: Andy Goodrich, Forte Design Systems, 30 July 03 38 Description of Modification: Converted thread demo to method demo. 39 40 *****************************************************************************/ 41 42 43#define SC_INCLUDE_DYNAMIC_PROCESSES 44#include <systemc.h> 45 46 47int test_function(double d) 48{ 49 cout << endl << "Test_function sees " << d << endl; 50 return int(d); 51} 52 53void void_function(double d) 54{ 55 cout << endl << "void_function sees " << d << endl; 56} 57 58int ref_function(const double& d) 59{ 60 cout << endl << "ref_function sees " << d << endl; 61 return int(d); 62} 63 64 65class top : public sc_module 66{ 67public: 68 SC_HAS_PROCESS(top); 69 70 top(sc_module_name name) : sc_module(name) 71 { 72 SC_THREAD(main); 73 } 74 75 void main() 76 { 77 sc_event e1, e2, e3, e4; 78 sc_spawn_options options1, options2, options3, options4; 79 int r; 80 81 cout << endl; 82 83 e1.notify(100, SC_NS); 84 85 // Spawn several methods that co-operatively execute in round robin order 86 87 options1.spawn_method(); 88 options1.dont_initialize(); 89 options1.set_sensitivity(&e1); 90 sc_spawn(&r, 91 sc_bind(&top::round_robin, this, "1", sc_ref(e1), sc_ref(e2), 3), 92 "1", &options1 93 ); 94 95 options2.spawn_method(); 96 options2.dont_initialize(); 97 options2.set_sensitivity(&e2); 98 sc_spawn(&r, 99 sc_bind(&top::round_robin, this, "2", sc_ref(e2), sc_ref(e3), 3), 100 "2", &options2 101 ); 102 103 options3.spawn_method(); 104 options3.dont_initialize(); 105 options3.set_sensitivity(&e3); 106 sc_spawn(&r, 107 sc_bind(&top::round_robin, this, "3", sc_ref(e3), sc_ref(e4), 3), 108 "3", &options3 109 ); 110 111 options4.spawn_method(); 112 options4.dont_initialize(); 113 options4.set_sensitivity(&e4); 114 sc_spawn(&r, 115 sc_bind(&top::round_robin, this, "4", sc_ref(e4), sc_ref(e1), 3), 116 "4", &options4 117 ); 118 wait(295, SC_NS); 119 cout << endl << "Done." << endl; 120 sc_stop(); 121 } 122 123 int round_robin(const char *str, sc_event& receive, sc_event& send, int cnt) 124 { 125 cout << "Round robin method " << str << 126 " at time " << sc_time_stamp() << endl; 127 next_trigger(receive); 128 send.notify(10, SC_NS); 129 return 0; 130 } 131}; 132 133int sc_main (int argc , char *argv[]) 134{ 135 top top1("Top1"); 136 sc_start(); 137 138 return 0; 139} 140