| 200 | | #include "tlmt_transactions.h" // VCI headers |
| 201 | | #include "tlmt_simple_initiator_socket.h" // VCI socket |
| 202 | | #include "mapping_table.h" |
| 203 | | |
| 204 | | class my_initiator // my_initiator |
| 205 | | : public sc_core::sc_module // inherit from SC module base class |
| | 197 | #include "tlmt_transactions.h" // TLM-T headers |
| | 198 | #include "tlmt_simple_initiator_socket.h" // TLM-T initiator socket |
| | 199 | #include "mapping_table.h" // mapping Table |
| | 200 | |
| | 201 | class my_initiator // my_initiator |
| | 202 | : public sc_core::sc_module // inherit from SC module base clase |
| 210 | | sc_core::sc_event m_rspEvent; |
| 211 | | sc_core::sc_time m_localTime; |
| 212 | | bool m_activity; |
| 213 | | uint32_t m_initid; |
| 214 | | uint32_t m_counter; |
| 215 | | uint32_t m_lookahead; |
| 216 | | |
| 217 | | ///////////////////////////////////////////////////////////////////////////////////// |
| 218 | | // Functions |
| 219 | | ///////////////////////////////////////////////////////////////////////////////////// |
| | 207 | |
| | 208 | ////////////////////// |
| | 209 | // Member Variables |
| | 210 | ////////////////////// |
| | 211 | uint32_t m_srcid; |
| | 212 | soclib::common::MappingTable m_mt; |
| | 213 | uint32_t m_counter; |
| | 214 | uint32_t m_lookahead; |
| | 215 | sc_core::sc_time m_local_time; |
| | 216 | bool m_activity_status; |
| | 217 | sc_core::sc_event m_rsp_event; |
| | 218 | |
| | 219 | soclib_vci_types::tlm_payload_type m_payload; |
| | 220 | soclib_vci_types::tlm_phase_type m_phase; |
| | 221 | |
| | 222 | /////////////////////// |
| | 223 | // Member Functions |
| | 224 | /////////////////////// |
| 222 | | void setLocalTime(sc_core::sc_time& t); // set the local time |
| 223 | | sc_core::sc_time getLocalTime(void); // get the local time |
| 224 | | void setActivity(bool t); // set the activity status (true if the component is active) |
| 225 | | bool getActivity(void); // get the activity state |
| 226 | | |
| 227 | | ///////////////////////////////////////////////////////////////////////////////////// |
| 228 | | // Virtual Fuctions tlm::tlm_bw_transport_if (VCI INITIATOR SOCKET) |
| 229 | | ///////////////////////////////////////////////////////////////////////////////////// |
| 230 | | |
| 231 | | /// Receive rsp from target |
| 232 | | tlm::tlm_sync_enum vci_rsp_received // for resp messages |
| 233 | | ( soclib_vci_types::tlm_payload_type &payload, // payload |
| 234 | | soclib_vci_types::tlm_phase_type &phase, // transaction phase |
| 235 | | sc_core::sc_time &time); // resp time |
| | 231 | tlm::tlm_sync_enum vci_rsp_received // interface function to receive VCI response |
| | 232 | ( soclib_vci_types::tlm_payload_type &payload, // payload |
| | 233 | soclib_vci_types::tlm_phase_type &phase, // phase |
| | 234 | sc_core::sc_time &time); // time |
| 245 | | sc_core::sc_module_name name, // module name |
| 246 | | const soclib::common::IntTab &index, // VCI initiator index |
| 247 | | const soclib::common::MappingTable &mt, // mapping table |
| 248 | | uint32_t lookahead // lookahead |
| 249 | | ); |
| 250 | | |
| 251 | | }; |
| 252 | | #endif /* __MY_INITIATOR_H__ */ |
| | 249 | sc_core::sc_module_name name, // module name |
| | 250 | const soclib::common::IntTab &index, // index of mapping table |
| | 251 | const soclib::common::MappingTable &mt, // mapping table |
| | 252 | uint32_t lookahead); // lookahead |
| | 253 | }; |
| 255 | | #include "my_initiator.h" // Our header |
| 256 | | |
| 257 | | #ifndef MY_INITIATOR_DEBUG |
| 258 | | #define MY_INITIATOR_DEBUG 1 |
| 259 | | #endif |
| 260 | | |
| 261 | | #define tmpl(x) x my_initiator |
| 262 | | |
| 263 | | ///Constructor |
| 264 | | tmpl (/**/)::my_initiator |
| 265 | | ( sc_core::sc_module_name name, // module name |
| 266 | | const soclib::common::IntTab &index, // index of mapping table |
| 267 | | const soclib::common::MappingTable &mt, // mapping table |
| 268 | | uint32_t lookahead // lookahead |
| 269 | | ) |
| 270 | | : sc_module(name) // init module name |
| 271 | | , p_vci_init("p_vci_init") // vci initiator socket name |
| 272 | | { |
| 273 | | //register callback function |
| | 256 | |
| | 257 | ///////////////// |
| | 258 | // Constructor |
| | 259 | ///////////////// |
| | 260 | my_initiator::my_initiator |
| | 261 | ( sc_core::sc_module_name name, // module name |
| | 262 | const soclib::common::IntTab &index, // index of mapping table |
| | 263 | const soclib::common::MappingTable &mt, // mapping table |
| | 264 | uint32_t lookahead) // lookahead |
| | 265 | : sc_module(name), // init module name |
| | 266 | m_mt(mt), // mapping table |
| | 267 | p_vci_init("socket") // vci initiator socket name |
| | 268 | { |
| | 269 | // link the interface function the TLM-T INITIATOR SOCKET |
| 293 | | ///////////////////////////////////////////////////////////////////////////////////// |
| 294 | | // Functions |
| 295 | | ///////////////////////////////////////////////////////////////////////////////////// |
| 296 | | tmpl (sc_core::sc_time)::getLocalTime() |
| 297 | | { |
| 298 | | return m_localTime; |
| 299 | | } |
| 300 | | |
| 301 | | tmpl (bool)::getActivity() |
| 302 | | { |
| 303 | | return m_activity; |
| 304 | | } |
| 305 | | |
| 306 | | tmpl (void)::setLocalTime(sc_core::sc_time &t) |
| 307 | | { |
| 308 | | m_localTime=t; |
| 309 | | } |
| 310 | | |
| 311 | | tmpl (void)::addLocalTime(sc_core::sc_time t) |
| 312 | | { |
| 313 | | m_localTime= m_localTime + t; |
| 314 | | } |
| 315 | | |
| 316 | | tmpl (void)::setActivity(bool t) |
| 317 | | { |
| 318 | | m_activity =t; |
| 319 | | } |
| 320 | | |
| 321 | | tmpl (void)::execLoop(void) // initiator thread |
| 322 | | { |
| 323 | | soclib_vci_types::tlm_payload_type payload; |
| 324 | | soclib_vci_types::tlm_phase_type phase; |
| 325 | | sc_core::sc_time sendTime; |
| 326 | | unsigned char data[32]; |
| 327 | | unsigned char byte_enable[32]; |
| 328 | | int pktid = 0; |
| 329 | | int nbytes = 4; // 1 word of 32 bits |
| 330 | | |
| 331 | | uint32_t int_data = 12345678; |
| 332 | | std::ostringstream name; |
| 333 | | name << "" << int_data; |
| 334 | | std::cout << "NAME = " << std::dec << name << std::endl; |
| 335 | | |
| 336 | | for(int i=0; i<nbytes; i++) |
| 337 | | byte_enable[i] = TLMT_BYTE_ENABLED; |
| 338 | | |
| 339 | | for(int i=0; i<32; i++) |
| 340 | | data[i] = 0x0; |
| 341 | | |
| 342 | | data[0]='a'; |
| 343 | | data[1]='b'; |
| 344 | | data[2]='c'; |
| 345 | | data[3]='d'; |
| 346 | | data[4]='\0'; |
| 347 | | |
| 348 | | std ::cout<< "DATA = " << data << std::endl; |
| 349 | | |
| 350 | | while ( 1 ){ |
| | 289 | ////////////////////// |
| | 290 | // Access Functions |
| | 291 | ////////////////////// |
| | 292 | bool my_initiator::getActivity() { return m_activity; } |
| | 293 | my_initiator::setActivity(bool t) { m_activity = t; } |
| | 294 | sc_core::sc_time my_initiator::getLocalTime() { return m_local_time; } |
| | 295 | my_initiator::setLocalTime(sc_core::sc_time t) { m_local_time = t; } |
| | 296 | my_initiator::addLocalTime(sc_core::sc_time t) { m_local_time += t; } |
| | 297 | |
| | 298 | /////////////////////// |
| | 299 | // thread |
| | 300 | /////////////////////// |
| | 301 | my_initiator::execLoop(void) |
| | 302 | { |
| | 303 | uint32_t address = 0x10000000; |
| | 304 | uint32_t data_int = 0xAABBCCDD; |
| | 305 | unsigned char data[4]; |
| | 306 | unsigned char byte_enable[4]; |
| | 307 | int nbytes = 4; |
| | 308 | |
| | 309 | for(int i=0; i<nbytes; i++) byte_enable[i] = TLM_BYTE_ENABLED; |
| | 310 | |
| | 311 | while ( true ) { |
| | 312 | // increase local time |
| 352 | | |
| 353 | | payload.set_address(0x10000000);//ram 0 |
| 354 | | payload.set_byte_enable_ptr(byte_enable); |
| 355 | | payload.set_byte_enable_length(nbytes); |
| 356 | | payload.set_data_ptr(data); |
| 357 | | payload.set_data_length(nbytes); // 5 words of 32 bits |
| 358 | | |
| 359 | | payload.set_write(); |
| 360 | | payload.set_src_id(m_initid); |
| 361 | | payload.set_trd_id(0); |
| 362 | | payload.set_pkt_id(pktid); |
| 363 | | |
| 364 | | phase= soclib::tlmt::TLMT_CMD; |
| 365 | | sendTime = getLocalTime(); |
| 366 | | |
| 367 | | #if MY_INITIATOR_DEBUG |
| 368 | | std::cout << "[INITIATOR " << m_initid << "] send cmd packet id = " << payload.get_pkt_id() << " time = " << getLocalTime().value() << std::endl; |
| 369 | | #endif |
| 370 | | |
| 371 | | p_vci_init->nb_transport_fw(payload, phase, sendTime); |
| 372 | | wait(m_rspEvent); |
| 373 | | |
| 374 | | #if MY_INITIATOR_DEBUG |
| 375 | | std::cout << "[INITIATOR " << m_initid << "] receive rsp packet id = " << payload.get_pkt_id() << " time = " << getLocalTime().value() << std::endl; |
| 376 | | #endif |
| 377 | | |
| 378 | | pktid++; |
| 379 | | |
| 380 | | addLocalTime(10 * UNIT_TIME); |
| 381 | | |
| 382 | | payload.set_address(0x10000000);//ram 0 |
| 383 | | payload.set_byte_enable_ptr(byte_enable); |
| 384 | | payload.set_byte_enable_length(nbytes); |
| 385 | | payload.set_data_ptr(data); |
| 386 | | payload.set_data_length(nbytes); // 5 words of 32 bits |
| 387 | | payload.set_read(); |
| 388 | | payload.set_src_id(m_initid); |
| 389 | | payload.set_trd_id(0); |
| 390 | | payload.set_pkt_id(pktid); |
| 391 | | |
| 392 | | phase= soclib::tlmt::TLMT_CMD; |
| 393 | | sendTime = getLocalTime(); |
| 394 | | |
| 395 | | #if MY_INITIATOR_DEBUG |
| 396 | | std::cout << "[INITIATOR " << m_initid << "] send cmd packet id = " << payload.get_pkt_id() << " time = " << getLocalTime().value() << std::endl; |
| 397 | | #endif |
| 398 | | |
| 399 | | p_vci_init->nb_transport_fw(payload, phase, sendTime); |
| 400 | | wait(m_rspEvent); |
| 401 | | |
| 402 | | #if MY_INITIATOR_DEBUG |
| 403 | | std::cout << "[INITIATOR " << m_initid << "] receive rsp packet id = " << payload.get_pkt_id() << " time = " << getLocalTime().value() << std::endl; |
| 404 | | |
| 405 | | #endif |
| 406 | | |
| 407 | | pktid++; |
| 408 | | |
| | 314 | // prepare payload (including int to char translation) |
| | 315 | m_payload.itoa(data_int, data, 0); |
| | 316 | m_payload.set_write(); |
| | 317 | m_payload.set_address(address); |
| | 318 | m_payload.set_byte_enable_ptr(byte_enable); |
| | 319 | m_payload.set_data_ptr(data); |
| | 320 | m_payload.set_data_length(nbytes); |
| | 321 | m_payload.set_srcid(m_srcid); |
| | 322 | m_payload.set_trdid(0); |
| | 323 | m_payload.set_pktid(0); |
| | 324 | // set the phase |
| | 325 | m_phase= soclib::tlmt::TLMT_CMD; |
| | 326 | // send the VCI command packet... |
| | 327 | p_vci_initiator->nb_transport_fw(m_payload, m_phase, m_local_time); |
| | 328 | // thread is descheduled, waiting for the response |
| | 329 | wait(m_rsp_event); |
| 415 | | |
| 416 | | } // end while true |
| 417 | | setActivity(false); |
| 418 | | } // end initiator_thread |
| 419 | | |
| 420 | | |
| 421 | | ///////////////////////////////////////////////////////////////////////////////////// |
| 422 | | // Virtual Functions tlm::tlm_bw_transport_if (VCI SOCKET) |
| 423 | | ///////////////////////////////////////////////////////////////////////////////////// |
| 424 | | /// receive the response packet from target socket |
| 425 | | |
| 426 | | tmpl (tlm::tlm_sync_enum)::vci_rsp_received // |
| 427 | | ( soclib_vci_types::tlm_payload_type &payload, // VCI payload |
| 428 | | soclib_vci_types::tlm_phase_type &phase, // tlm phase |
| 429 | | sc_core::sc_time &rspTime // time |
| | 336 | } // end while |
| | 337 | |
| | 338 | } // end execLoop() |
| | 339 | |
| | 340 | /////////////////////////////////////////////////////////////// |
| | 341 | // Interface Function to receive the response packet |
| | 342 | /////////////////////////////////////////////////////////////// |
| | 343 | tlm::tlm_sync_enum my_initiator::vci_rsp_received |
| | 344 | ( soclib_vci_types::tlm_payload_type &payload, // payload |
| | 345 | soclib_vci_types::tlm_phase_type &phase, // phase |
| | 346 | sc_core::sc_time &time // time |