proc_ctrl.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// proc_ctrl.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: proc_ctrl.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// Basic functionality of process control methods 32 33#define SC_INCLUDE_DYNAMIC_PROCESSES 34 35#include <systemc> 36using sc_core::sc_process_handle; 37using sc_core::sc_event; 38using sc_core::sc_get_current_process_handle; 39using sc_core::SC_NS; 40using sc_core::sc_time; 41using sc_core::sc_time_stamp; 42using sc_core::sc_stop; 43using sc_core::sc_unwind_exception; 44using sc_core::sc_is_unwinding; 45using sc_core::sc_start; 46using sc_core::SC_ZERO_TIME; 47using std::cout; 48using std::endl; 49 50SC_MODULE(Top) 51{ 52 SC_CTOR(Top) 53 : count(0) 54 { 55 SC_METHOD(gen); 56 sensitive << ev; 57 58 SC_THREAD(ctrl); 59 60 SC_THREAD(target); 61 t1 = sc_get_current_process_handle(); 62 63 f0 = f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0; 64 f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0; 65 f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0; 66 } 67 68 sc_process_handle t1, t2; 69 sc_event ev; 70 int count; 71 int f0, f1, f2, f3, f4, f5, f6, f7, f8, f9; 72 int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19; 73 int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29; 74 75 void gen() 76 { 77 ev.notify(10, SC_NS); 78 } 79 80 void ctrl() 81 { 82 wait(SC_ZERO_TIME); 83 84 count = 1; 85 wait(15, SC_NS); 86 87 count = 2; 88 t1.suspend(); 89 wait(20, SC_NS); 90 91 count = 3; 92 t1.reset(); // Reset takes priority over suspend 93 wait(20, SC_NS); 94 95 count = 4; 96 t1.reset(); // Reset takes priority over suspend 97 wait(20, SC_NS); 98 99 count = 5; 100 t1.resume(); 101 wait(SC_ZERO_TIME); 102 103 count = 6; 104 wait(10, SC_NS); 105 106 count = 7; 107 wait(10, SC_NS); 108 109 count = 8; 110 t1.reset(); 111 112 count = 9; 113 wait(10, SC_NS); 114 115 count = 10; 116 wait(10, SC_NS); 117 118 count = 11; 119 t1.disable(); 120 wait(20, SC_NS); 121 122 count = 12; 123 t1.reset(); // Reset takes priority over enable 124 125 count = 13; 126 wait(20, SC_NS); 127 128 count = 14; 129 t1.reset(); // Reset takes priority over enable 130 131 count = 15; 132 wait(20, SC_NS); 133 134 count = 16; 135 t1.enable(); 136 wait(SC_ZERO_TIME); 137 138 count = 17; 139 wait(10, SC_NS); 140 141 count = 18; 142 wait(10, SC_NS); 143 144 count = 19; 145 t1.disable(); 146 wait(SC_ZERO_TIME); 147 148 count = 20; 149 wait(20, SC_NS); 150 151 count = 21; 152 t1.suspend(); 153 wait(20, SC_NS); 154 155 count = 22; 156 t1.enable(); 157 wait(SC_ZERO_TIME); 158 159 count = 23; 160 wait(20, SC_NS); 161 162 count = 24; 163 t1.resume(); 164 wait(SC_ZERO_TIME); 165 166 count = 25; 167 wait(10, SC_NS); 168 169 count = 26; 170 wait(10, SC_NS); 171 172 count = 27; 173 t1.suspend(); 174 175 count = 28; 176 wait(20, SC_NS); 177 178 count = 29; 179 t1.kill(); // kill takes priority over suspend 180 wait(20, SC_NS); 181 182 count = 30; 183 t1.resume(); 184 wait(20, SC_NS); 185 186 count = 31; 187 sc_assert( !sc_is_unwinding() ); 188 if (t1.valid()) 189 sc_assert( !t1.is_unwinding() ); 190 191 sc_stop(); 192 } 193 194 void target() 195 { 196 sc_assert( !sc_is_unwinding() ); 197 198 switch(count) 199 { 200 case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f1=1; break; 201 case 3: sc_assert( sc_time_stamp() == sc_time(35, SC_NS) ); f3=1; break; 202 case 4: sc_assert( sc_time_stamp() == sc_time(55, SC_NS) ); f4=1; break; 203 case 8: sc_assert( sc_time_stamp() == sc_time(95, SC_NS) ); f8=1; break; 204 case 12: sc_assert( sc_time_stamp() == sc_time(135, SC_NS) ); f11=1; break; 205 case 14: sc_assert( sc_time_stamp() == sc_time(155, SC_NS) ); f12=1; break; 206 default: sc_assert( false ); break; 207 } 208 209 for(;;) 210 { 211 try { 212 wait(ev); 213 214 switch(count) 215 { 216 case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); f2=1; break; 217 case 5: sc_assert( sc_time_stamp() == sc_time(75, SC_NS) ); f5=1; break; 218 case 6: sc_assert( sc_time_stamp() == sc_time(80, SC_NS) ); f6=1; break; 219 case 7: sc_assert( sc_time_stamp() == sc_time(90, SC_NS) ); f7=1; break; 220 case 9: sc_assert( sc_time_stamp() == sc_time(100, SC_NS) ); f9=1; break; 221 case 10: sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); f10=1; break; 222 case 17: sc_assert( sc_time_stamp() == sc_time(180, SC_NS) ); f13=1; break; 223 case 18: sc_assert( sc_time_stamp() == sc_time(190, SC_NS) ); f14=1; break; 224 case 24: sc_assert( sc_time_stamp() == sc_time(255, SC_NS) ); f15=1; break; 225 case 25: sc_assert( sc_time_stamp() == sc_time(260, SC_NS) ); f16=1; break; 226 case 26: sc_assert( sc_time_stamp() == sc_time(270, SC_NS) ); f17=1; break; 227 default: sc_assert( false ); break; 228 } 229 230 } 231 catch (const sc_unwind_exception& e) 232 { 233 sc_assert( sc_is_unwinding() ); 234 235 if (count == 29) 236 { 237 sc_assert( e.is_reset() == false ); f24=1; 238 } 239 switch(count) 240 { 241 case 3: sc_assert( sc_time_stamp() == sc_time(35, SC_NS) ); f18=1; break; 242 case 4: sc_assert( sc_time_stamp() == sc_time(55, SC_NS) ); f19=1; break; 243 case 8: sc_assert( sc_time_stamp() == sc_time(95, SC_NS) ); f20=1; break; 244 case 12: sc_assert( sc_time_stamp() == sc_time(135, SC_NS) ); f21=1; break; 245 case 14: sc_assert( sc_time_stamp() == sc_time(155, SC_NS) ); f22=1; break; 246 case 29: sc_assert( sc_time_stamp() == sc_time(295, SC_NS) ); f23=1; break; 247 default: sc_assert( false ); break; 248 } 249 250 throw e; 251 } 252 } 253 } 254}; 255 256int sc_main(int argc, char* argv[]) 257{ 258 Top top("top"); 259 sc_start(); 260 261 sc_assert(top.f1); 262 sc_assert(top.f2); 263 sc_assert(top.f3); 264 sc_assert(top.f4); 265 sc_assert(top.f5); 266 sc_assert(top.f6); 267 sc_assert(top.f7); 268 sc_assert(top.f8); 269 sc_assert(top.f9); 270 sc_assert(top.f10); 271 sc_assert(top.f11); 272 sc_assert(top.f12); 273 sc_assert(top.f13); 274 sc_assert(top.f14); 275 sc_assert(top.f15); 276 sc_assert(top.f16); 277 sc_assert(top.f17); 278 sc_assert(top.f18); 279 sc_assert(top.f19); 280 sc_assert(top.f20); 281 sc_assert(top.f21); 282 sc_assert(top.f22); 283 sc_assert(top.f23); 284 sc_assert(top.f24); 285 /* 286 sc_assert(top.f25); 287 sc_assert(top.f26); 288 sc_assert(top.f27); 289 sc_assert(top.f28); 290 sc_assert(top.f29); 291 */ 292 293 cout << endl << "Success" << endl; 294 return 0; 295} 296