test2.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// test02.cpp -- test that disabled processes with static sensitivity 23// wake up when enabled. 24// 25// Original Author: Andy Goodrich, Forte Design Systems, Inc. 26// 27// CVS MODIFICATION LOG - modifiers, enter your name, affiliation, date and 28// changes you are making here. 29// 30// $Log: test2.cpp,v $ 31// Revision 1.2 2009/07/28 01:10:19 acg 32// Andy Goodrich: replacement test using standardized test bench. 33// 34//***************************************************************************** 35 36#define SC_INCLUDE_DYNAMIC_PROCESSES 37#include "systemc.h" 38 39enum my_process_states { 40 ST_DISABLED, 41 ST_NORMAL, 42 ST_SUSPENDED 43}; 44 45inline ostream& time_stamp( ostream& os ) 46{ 47 os << dec << sc_time_stamp() << "[" << sc_delta_count() << "]: "; 48 return os; 49} 50 51SC_MODULE(top) { 52 // constructor: 53 54 SC_CTOR(top) 55 { 56 m_state_cthread0 = ST_NORMAL; 57 m_state_method0 = ST_NORMAL; 58 m_state_thread0 = ST_NORMAL; 59 60 SC_THREAD(stimulator0); 61 62 SC_CTHREAD( target_cthread0, m_clk.pos() ); 63 m_target_cthread0 = sc_get_current_process_handle(); 64 65 SC_METHOD(target_method0); 66 sensitive << m_clk.pos(); 67 m_target_method0 = sc_get_current_process_handle(); 68 69 SC_THREAD(target_thread0); 70 sensitive << m_clk.neg(); 71 m_target_thread0 = sc_get_current_process_handle(); 72 } 73 74 // processes: 75 76 void stimulator0(); 77 void target_cthread0(); 78 void target_method0(); 79 void target_thread0(); 80 81 // Storage: 82 83 sc_in<bool> m_clk; 84 sc_signal<int> m_state_cthread0; 85 sc_signal<int> m_state_method0; 86 sc_signal<int> m_state_thread0; 87 sc_process_handle m_target_cthread0; 88 sc_process_handle m_target_method0; 89 sc_process_handle m_target_thread0; 90}; 91 92#define DISABLE(TARGET) \ 93 cout << endl; \ 94 time_stamp(cout) << name << ": disabling target_" << #TARGET << endl; \ 95 m_state_##TARGET = ST_DISABLED; \ 96 m_target_##TARGET.disable(); \ 97 cout << endl; 98 99#define ENABLE(TARGET) \ 100 cout << endl; \ 101 time_stamp(cout) << name << ": enabling target_" << #TARGET << endl; \ 102 m_state_##TARGET = ST_NORMAL; \ 103 m_target_##TARGET.enable(); \ 104 cout << endl; 105 106void top::stimulator0() 107{ 108 const char* name = "stimulator"; 109 110 wait(2, SC_NS); 111 112 DISABLE(cthread0) 113 wait(3, SC_NS); 114 DISABLE(method0) 115 wait(3, SC_NS); 116 DISABLE(thread0) 117 wait(3, SC_NS); 118 119 ENABLE(cthread0) 120 wait(3, SC_NS); 121 ENABLE(method0) 122 wait(3, SC_NS); 123 ENABLE(thread0) 124 wait(3, SC_NS); 125 126 DISABLE(cthread0) 127 wait(3, SC_NS); 128 DISABLE(method0) 129 wait(3, SC_NS); 130 DISABLE(thread0) 131 wait(3, SC_NS); 132 133 ENABLE(cthread0) 134 wait(3, SC_NS); 135 ENABLE(method0) 136 wait(3, SC_NS); 137 ENABLE(thread0) 138 wait(3, SC_NS); 139 140 ::sc_core::wait(1000, SC_NS); 141 cout << endl; 142 time_stamp(cout) << name << ": terminating" << endl; 143 sc_stop(); 144} 145 146void top::target_cthread0() 147{ 148 const char* name = "target_cthread0"; 149 150 time_stamp(cout) << name << ": starting" << endl; 151 for (int i = 0; i < 10; i++) 152 { 153 wait(); 154 if ( m_state_cthread0 == ST_DISABLED ) 155 { 156 time_stamp(cout) << name << ": ERROR should not see this" << endl; 157 } 158 else 159 { 160 time_stamp(cout) << name << ": active" << endl; 161 } 162 } 163 time_stamp(cout) << name << ": terminating" << endl; 164} 165 166void top::target_method0() 167{ 168 const char* name = "target_method0"; 169 static int state = 0; 170 switch( state ) 171 { 172 case 0: 173 time_stamp(cout) << name << ": starting" << endl; 174 break; 175 default: 176 if ( m_state_method0 == ST_DISABLED ) 177 { 178 time_stamp(cout) << name << ": ERROR should not see this" << endl; 179 } 180 else if ( state < 18 ) 181 { 182 time_stamp(cout) << name << ": active" << endl; 183 } 184 break; 185 case 19: 186 time_stamp(cout) << name << ": terminating" << endl; 187 break; 188 } 189 state++; 190} 191 192void top::target_thread0() 193{ 194 const char* name = "target_thread0"; 195 196 time_stamp(cout) << name << ": starting" << endl; 197 for (int i = 0; i < 10; i++) 198 { 199 wait(); 200 if ( m_state_thread0 == ST_DISABLED ) 201 { 202 time_stamp(cout) << name << ": ERROR should not see this" << endl; 203 } 204 else 205 { 206 time_stamp(cout) << name << ": active" << endl; 207 } 208 } 209 time_stamp(cout) << name << ": terminating" << endl; 210} 211 212int sc_main (int argc, char *argv[]) 213{ 214 sc_clock clock( "clock", 2.0, SC_NS ); 215 216 top* top_p = new top("top"); 217 top_p->m_clk(clock); 218 219 sc_start(); 220 return 0; 221} 222 223