Changes between Version 123 and Version 124 of Writing Rules/Tlmt
- Timestamp:
- Mar 3, 2009, 11:02:21 AM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Writing Rules/Tlmt
v123 v124 240 240 241 241 {{{ 242 #include "my_initiator.h" // Ourheader243 244 my_initiator::my_initiator (245 246 247 248 uint32_t time_quantum)// time quantum249 250 m_mt(mt),// mapping table251 p_vci_init("socket")// vci initiator socket name242 #include "my_initiator.h" // header 243 244 my_initiator::my_initiator 245 ( sc_core::sc_module_name name, // module name 246 const soclib::common::IntTab &index, // index of mapping table 247 const soclib::common::MappingTable &mt, // mapping table 248 sc_core::sc_time time_quantum) // time quantum 249 : sc_module(name), // init module name 250 m_mt(mt), // mapping table 251 p_vci_init("socket") // vci initiator socket name 252 252 { 253 253 //register callback function VCI INITIATOR SOCKET 254 254 p_vci_init.register_nb_transport_bw(this, &my_initiator::my_nb_transport_bw); 255 256 //initiator identification 255 //initiator identification 257 256 m_srcid = mt.indexForId(index); 258 259 //Quantum keeper 260 tlm_utils::tlm_quantumkeeper::set_global_quantum(time_quantum * UNIT_TIME); 261 m_QuantumKeeper.reset(); 262 263 //initialize the local time 264 m_local_time = sc_core::SC_ZERO_TIME; 265 266 //initialize the activity variable 267 setActivity(true); 268 257 //PDES local time 258 m_pdes_local_time = new pdes_local_time(time_quantum); 259 //PDES activity status 260 m_pdes_activity_status = new pdes_activity_status(true); 269 261 // register thread process 270 SC_THREAD(behavior); 271 } 272 273 ///////////////////////////////////////////////////////////////////////////////////// 274 // Fuctions 275 ///////////////////////////////////////////////////////////////////////////////////// 276 bool my_initiator::getActivity() 277 { 278 return m_activity_status; 279 } 280 281 void my_initiator::setActivity(bool t) 282 { 283 m_activity_status =t; 284 } 285 286 //send a message to network to inform the current activity status 262 SC_THREAD(execLoop); 263 } 264 265 // send to interconnect the initiator activity status 287 266 void my_initiator::sendActivity() 288 267 { 289 268 tlm::tlm_generic_payload *payload_ptr = new tlm::tlm_generic_payload(); 269 soclib_payload_extension *extension_ptr = new soclib_payload_extension(); 290 270 tlm::tlm_phase phase; 291 sc_core::sc_time send_time; 292 soclib_payload_extension *extension_ptr = new soclib_payload_extension(); 293 271 sc_core::sc_time time; 272 294 273 // set the active or inactive command 295 if(m_ activity_status) extension_ptr->set_active();274 if(m_pdes_activity_status->get()) extension_ptr->set_active(); 296 275 else extension_ptr->set_inactive(); 297 276 // set the extension to tlm payload … … 300 279 phase = tlm::BEGIN_REQ; 301 280 //set the local time to transaction time 302 send_time = m_local_time;303 //send the message304 p_vci_init ->nb_transport_fw(*payload_ptr, phase, send_time);281 time = m_pdes_local_time->get(); 282 //send a message with command equals to PDES_ACTIVE or PDES_INACTIVE 283 p_vci_initiator->nb_transport_fw(*payload_ptr, phase, time); 305 284 //wait a response 306 285 wait(m_rspEvent); 307 286 } 308 287 309 sc_core::sc_time my_initiator::getLocalTime() 310 { 311 return m_local_time; 312 } 313 314 void my_initiator::setLocalTime(sc_core::sc_time &t) 315 { 316 m_local_time=t; 317 } 318 319 void my_initiator::addTime(sc_core::sc_time t) 320 { 321 m_local_time= m_local_time + t; 322 } 323 324 //send a null message to network to inform the current local time 288 // send to interconnect a null message with the initiator local time 325 289 void my_initiator::sendNullMessage() 326 290 { 327 291 tlm::tlm_generic_payload *payload_ptr = new tlm::tlm_generic_payload(); 292 soclib_payload_extension *extension_ptr = new soclib_payload_extension(); 328 293 tlm::tlm_phase phase; 329 sc_core::sc_time send_time; 330 soclib_payload_extension *extension_ptr = new soclib_payload_extension(); 331 294 sc_core::sc_time time; 295 332 296 // set the null message command 333 297 extension_ptr->set_null_message(); … … 337 301 phase = tlm::BEGIN_REQ; 338 302 //set the local time to transaction time 339 send_time = m_local_time;340 //send the null message341 p_vci_init ->nb_transport_fw(*payload_ptr, phase, send_time);342 //deschedule 303 time = m_pdes_local_time->get(); 304 //send a null message 305 p_vci_initiator->nb_transport_fw(*payload_ptr, phase, time); 306 //deschedule the initiator thread 343 307 wait(sc_core::SC_ZERO_TIME); 344 308 } 345 // initiator thread 346 void my_initiator::behavior(void) 309 310 // initiator thread 311 void my_initiator::execLoop(void) 347 312 { 348 313 tlm::tlm_generic_payload *payload_ptr = new tlm::tlm_generic_payload(); 349 tlm::tlm_phase phase;350 sc_core::sc_time send_time;351 314 soclib_payload_extension *extension_ptr = new soclib_payload_extension(); 352 353 uint32_t nwords = 1;354 uint32_t nbytes = nwords * vci_param::nbytes;315 tlm::tlm_phase phase; 316 sc_core::sc_time time; 317 uint32_t nbytes = 4; 355 318 unsigned char data[nbytes]; 356 319 unsigned char byte_enable[nbytes]; 357 320 358 for(unsigned int i=0; i<nbytes; i++){359 byte_enable[i]=0xFF;360 data[i]=0xAA;361 }362 363 321 while (true){ 364 //increment the local time 365 addTime(100 * UNIT_TIME); 366 m_QuantumKeeper.inc(100 * UNIT_TIME); 367 368 // set the values in tlm payload 322 //fill the byte_enable and data 323 for(unsigned int i=0; i<nbytes; i++){ 324 byte_enable[i]=0xFF; 325 data[i]=0xAA; 326 } 327 328 // set the values in tlm payload 369 329 payload_ptr->set_command(tlm::TLM_IGNORE_COMMAND); 370 330 payload_ptr->set_address(0x10000000); … … 379 339 extension_ptr->set_pkt_id(0); 380 340 // set the extension to tlm payload 381 payload_ptr->set_extension (extension_ptr);341 payload_ptr->set_extension (extension_ptr ); 382 342 // set the tlm phase 383 343 phase = tlm::BEGIN_REQ; 384 344 // set the local time to transaction time 385 send_time = m_local_time; 386 387 // send the transaction 388 p_vci_init->nb_transport_fw(*payload_ptr, phase, send_time); 389 // wait the response 345 time = m_pdes_local_time->get(); 346 // send the transaction and wait a response 347 p_vci_initiator->nb_transport_fw(*payload_ptr, phase, time); 390 348 wait(m_rspEvent); 391 392 // if the initiator needs synchronize then it sends a null message and resets the quantum keeper 393 if (m_QuantumKeeper.need_sync()) { 349 350 // increment the local time 351 m_pdes_local_time->add(10 * UNIT_TIME); 352 // if a synchronization is nexcessary then the initiator sends a null message 353 if (m_pdes_local_time->need_sync()) { 394 354 sendNullMessage(); 395 m_QuantumKeeper.reset();396 355 } 397 356 } // end while true 398 setActivity(false); 357 358 //desactive the initiator and inform to interconnect 359 m_pdes_activity_status->set(false); 399 360 sendActivity(); 400 } // end initiator_thread 401 402 ///////////////////////////////////////////////////////////////////////////////////// 403 // Virtual Fuctions tlm::tlm_bw_transport_if (VCI INITIATOR SOCKET) 404 ///////////////////////////////////////////////////////////////////////////////////// 405 tlm::tlm_sync_enum my_initiator::my_nb_transport_bw // inbound nb_transport_bw 406 ( tlm::tlm_generic_payload &payload, // payload 407 tlm::tlm_phase &phase, // phase 408 sc_core::sc_time &time) // time 361 } 362 363 // inbound nb_transport_bw (VCI INITIATOR SOCKET) 364 tlm::tlm_sync_enum my_initiator::my_nb_transport_bw 365 ( tlm::tlm_base_protocol_types::tlm_payload_type &payload, // payload 366 tlm::tlm_base_protocol_types::tlm_phase_type &phase, // phase 367 sc_core::sc_time &time) // time 409 368 { 410 //update the local time 411 setLocalTime(time); 412 //increment the quatum keeper using the difference between the sending time and response time 413 m_QuantumKeeper.inc(time - send_time); 414 //notify the initiator thread 369 // update the local time 370 m_pdes_local_time->set(time); 371 // wake up the initiator thread 415 372 m_rspEvent.notify(sc_core::SC_ZERO_TIME); 416 373 return tlm::TLM_COMPLETED; 417 } // end backward nb transport374 } 418 375 419 376 }}}