112922Sgabeblack@google.com/***************************************************************************** 212922Sgabeblack@google.com 312922Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412922Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512922Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612922Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712922Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812922Sgabeblack@google.com License. You may obtain a copy of the License at 912922Sgabeblack@google.com 1012922Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112922Sgabeblack@google.com 1212922Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312922Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412922Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512922Sgabeblack@google.com implied. See the License for the specific language governing 1612922Sgabeblack@google.com permissions and limitations under the License. 1712922Sgabeblack@google.com 1812922Sgabeblack@google.com *****************************************************************************/ 1912922Sgabeblack@google.com 2012922Sgabeblack@google.com#ifndef __SIMPLE_AT_TARGET1_H__ 2112922Sgabeblack@google.com#define __SIMPLE_AT_TARGET1_H__ 2212922Sgabeblack@google.com 2312922Sgabeblack@google.com#include "tlm.h" 2412922Sgabeblack@google.com#include "tlm_utils/simple_target_socket.h" 2512922Sgabeblack@google.com//#include <systemc> 2612922Sgabeblack@google.com#include <cassert> 2712922Sgabeblack@google.com#include <vector> 2812922Sgabeblack@google.com#include <queue> 2912922Sgabeblack@google.com//#include <iostream> 3012922Sgabeblack@google.com 3112922Sgabeblack@google.comclass SimpleATTarget1 : public sc_core::sc_module 3212922Sgabeblack@google.com{ 3312922Sgabeblack@google.compublic: 3412922Sgabeblack@google.com typedef tlm::tlm_generic_payload transaction_type; 3512922Sgabeblack@google.com typedef tlm::tlm_phase phase_type; 3612922Sgabeblack@google.com typedef tlm::tlm_sync_enum sync_enum_type; 3712922Sgabeblack@google.com typedef tlm_utils::simple_target_socket<SimpleATTarget1> target_socket_type; 3812922Sgabeblack@google.com 3912922Sgabeblack@google.compublic: 4012922Sgabeblack@google.com target_socket_type socket; 4112922Sgabeblack@google.com 4212922Sgabeblack@google.compublic: 4312922Sgabeblack@google.com SC_HAS_PROCESS(SimpleATTarget1); 4412922Sgabeblack@google.com SimpleATTarget1(sc_core::sc_module_name name) : 4512922Sgabeblack@google.com sc_core::sc_module(name), 4612922Sgabeblack@google.com socket("socket"), 4712922Sgabeblack@google.com ACCEPT_DELAY(25, sc_core::SC_NS), 4812922Sgabeblack@google.com RESPONSE_DELAY(100, sc_core::SC_NS) 4912922Sgabeblack@google.com { 5012922Sgabeblack@google.com // register nb_transport method 5112922Sgabeblack@google.com socket.register_nb_transport_fw(this, &SimpleATTarget1::myNBTransport); 5212922Sgabeblack@google.com 5312922Sgabeblack@google.com SC_METHOD(endRequest) 5412922Sgabeblack@google.com sensitive << mEndRequestEvent; 5512922Sgabeblack@google.com dont_initialize(); 5612922Sgabeblack@google.com 5712922Sgabeblack@google.com SC_METHOD(beginResponse) 5812922Sgabeblack@google.com sensitive << mBeginResponseEvent; 5912922Sgabeblack@google.com dont_initialize(); 6012922Sgabeblack@google.com 6112922Sgabeblack@google.com SC_METHOD(endResponse) 6212922Sgabeblack@google.com sensitive << mEndResponseEvent; 6312922Sgabeblack@google.com dont_initialize(); 6412922Sgabeblack@google.com } 6512922Sgabeblack@google.com 6612922Sgabeblack@google.com // 6712922Sgabeblack@google.com // Simple AT target 6812922Sgabeblack@google.com // - Request is accepted after ACCEPT delay (relative to end of prev request 6912922Sgabeblack@google.com // phase) 7012922Sgabeblack@google.com // - Response is started after RESPONSE delay (relative to end of prev resp 7112922Sgabeblack@google.com // phase) 7212922Sgabeblack@google.com // 7312922Sgabeblack@google.com sync_enum_type myNBTransport(transaction_type& trans, phase_type& phase, sc_core::sc_time& t) 7412922Sgabeblack@google.com { 7512922Sgabeblack@google.com if (phase == tlm::BEGIN_REQ) { 7612922Sgabeblack@google.com // transactions may be kept in queue after the initiator has send END_REQ 7712922Sgabeblack@google.com trans.acquire(); 7812922Sgabeblack@google.com 7912922Sgabeblack@google.com sc_dt::uint64 address = trans.get_address(); 8012922Sgabeblack@google.com assert(address < 400); 8112922Sgabeblack@google.com 8212922Sgabeblack@google.com unsigned int& data = *reinterpret_cast<unsigned int*>(trans.get_data_ptr()); 8312922Sgabeblack@google.com if (trans.get_command() == tlm::TLM_WRITE_COMMAND) { 8412922Sgabeblack@google.com std::cout << name() << ": Received write request: A = 0x" 8512922Sgabeblack@google.com << std::hex << (unsigned int)address << ", D = 0x" 8612922Sgabeblack@google.com << data << std::dec 8712922Sgabeblack@google.com << " @ " << sc_core::sc_time_stamp() << std::endl; 8812922Sgabeblack@google.com 8912922Sgabeblack@google.com *reinterpret_cast<unsigned int*>(&mMem[address]) = data; 9012922Sgabeblack@google.com 9112922Sgabeblack@google.com } else { 9212922Sgabeblack@google.com std::cout << name() << ": Received read request: A = 0x" 9312922Sgabeblack@google.com << std::hex << (unsigned int)address << std::dec 9412922Sgabeblack@google.com << " @ " << sc_core::sc_time_stamp() << std::endl; 9512922Sgabeblack@google.com 9612922Sgabeblack@google.com data = *reinterpret_cast<unsigned int*>(&mMem[address]); 9712922Sgabeblack@google.com } 9812922Sgabeblack@google.com 9912922Sgabeblack@google.com // Notify end of request phase after ACCEPT delay 10012922Sgabeblack@google.com if (mEndRequestQueue.empty()) { 10112922Sgabeblack@google.com mEndRequestEvent.notify(t + ACCEPT_DELAY); 10212922Sgabeblack@google.com } 10312922Sgabeblack@google.com mEndRequestQueue.push(&trans); 10412922Sgabeblack@google.com 10512922Sgabeblack@google.com // AT-noTA target 10612922Sgabeblack@google.com // - always return false 10712922Sgabeblack@google.com // - seperate call to indicate end of phase (do not update phase or t) 10812922Sgabeblack@google.com return tlm::TLM_ACCEPTED; 10912922Sgabeblack@google.com 11012922Sgabeblack@google.com } else if (phase == tlm::END_RESP) { 11112922Sgabeblack@google.com 11212922Sgabeblack@google.com // response phase ends after t 11312922Sgabeblack@google.com mEndResponseEvent.notify(t); 11412922Sgabeblack@google.com 11512922Sgabeblack@google.com return tlm::TLM_COMPLETED; 11612922Sgabeblack@google.com } 11712922Sgabeblack@google.com 11812922Sgabeblack@google.com // Not possible 11912922Sgabeblack@google.com assert(0); exit(1); 12012922Sgabeblack@google.com// return tlm::TLM_COMPLETED; //unreachable code 12112922Sgabeblack@google.com } 12212922Sgabeblack@google.com 12312922Sgabeblack@google.com void endRequest() 12412922Sgabeblack@google.com { 12512922Sgabeblack@google.com assert(!mEndRequestQueue.empty()); 12612922Sgabeblack@google.com // end request phase of oldest transaction 12712922Sgabeblack@google.com phase_type phase = tlm::END_REQ; 12812922Sgabeblack@google.com sc_core::sc_time t = sc_core::SC_ZERO_TIME; 12912922Sgabeblack@google.com transaction_type* trans = mEndRequestQueue.front(); 13012922Sgabeblack@google.com assert(trans); 13112922Sgabeblack@google.com mEndRequestQueue.pop(); 13212922Sgabeblack@google.com #if ( ! NDEBUG ) 13312922Sgabeblack@google.com sync_enum_type r = socket->nb_transport_bw(*trans, phase, t); 13412922Sgabeblack@google.com #endif /* ! NDEBUG */ 13512922Sgabeblack@google.com assert(r == tlm::TLM_ACCEPTED); // FIXME: initiator should return TLM_ACCEPTED? 13612922Sgabeblack@google.com assert(t == sc_core::SC_ZERO_TIME); // t must be SC_ZERO_TIME 13712922Sgabeblack@google.com 13812922Sgabeblack@google.com // Notify end of request phase for next transaction after ACCEPT delay 13912922Sgabeblack@google.com if (!mEndRequestQueue.empty()) { 14012922Sgabeblack@google.com mEndRequestEvent.notify(ACCEPT_DELAY); 14112922Sgabeblack@google.com } 14212922Sgabeblack@google.com 14312922Sgabeblack@google.com if (mResponseQueue.empty()) { 14412922Sgabeblack@google.com // Start processing transaction 14512922Sgabeblack@google.com // Notify begin of response phase after RESPONSE delay 14612922Sgabeblack@google.com mBeginResponseEvent.notify(RESPONSE_DELAY); 14712922Sgabeblack@google.com } 14812922Sgabeblack@google.com mResponseQueue.push(trans); 14912922Sgabeblack@google.com } 15012922Sgabeblack@google.com 15112922Sgabeblack@google.com void beginResponse() 15212922Sgabeblack@google.com { 15312922Sgabeblack@google.com assert(!mResponseQueue.empty()); 15412922Sgabeblack@google.com // start response phase of oldest transaction 15512922Sgabeblack@google.com phase_type phase = tlm::BEGIN_RESP; 15612922Sgabeblack@google.com sc_core::sc_time t = sc_core::SC_ZERO_TIME; 15712922Sgabeblack@google.com transaction_type* trans = mResponseQueue.front(); 15812922Sgabeblack@google.com assert(trans); 15912922Sgabeblack@google.com 16012922Sgabeblack@google.com // Set response data 16112922Sgabeblack@google.com trans->set_response_status(tlm::TLM_OK_RESPONSE); 16212922Sgabeblack@google.com if (trans->get_command() == tlm::TLM_READ_COMMAND) { 16312922Sgabeblack@google.com sc_dt::uint64 address = trans->get_address(); 16412922Sgabeblack@google.com assert(address < 400); 16512922Sgabeblack@google.com *reinterpret_cast<unsigned int*>(trans->get_data_ptr()) = 16612922Sgabeblack@google.com *reinterpret_cast<unsigned int*>(&mMem[address]); 16712922Sgabeblack@google.com } 16812922Sgabeblack@google.com 16912922Sgabeblack@google.com switch (socket->nb_transport_bw(*trans, phase, t)) { 17012922Sgabeblack@google.com case tlm::TLM_COMPLETED: 17112922Sgabeblack@google.com // response phase ends after t 17212922Sgabeblack@google.com mEndResponseEvent.notify(t); 17312922Sgabeblack@google.com break; 17412922Sgabeblack@google.com 17512922Sgabeblack@google.com case tlm::TLM_ACCEPTED: 17612922Sgabeblack@google.com case tlm::TLM_UPDATED: 17712922Sgabeblack@google.com // initiator will call nb_transport to indicate end of response phase 17812922Sgabeblack@google.com break; 17912922Sgabeblack@google.com 18012922Sgabeblack@google.com default: 18112922Sgabeblack@google.com assert(0); exit(1); 18212922Sgabeblack@google.com }; 18312922Sgabeblack@google.com } 18412922Sgabeblack@google.com 18512922Sgabeblack@google.com void endResponse() 18612922Sgabeblack@google.com { 18712922Sgabeblack@google.com assert(!mResponseQueue.empty()); 18812922Sgabeblack@google.com mResponseQueue.front()->release(); 18912922Sgabeblack@google.com mResponseQueue.pop(); 19012922Sgabeblack@google.com 19112922Sgabeblack@google.com if (!mResponseQueue.empty()) { 19212922Sgabeblack@google.com // Start processing next transaction 19312922Sgabeblack@google.com // Notify begin of response phase after RESPONSE delay 19412922Sgabeblack@google.com mBeginResponseEvent.notify(RESPONSE_DELAY); 19512922Sgabeblack@google.com } 19612922Sgabeblack@google.com } 19712922Sgabeblack@google.com 19812922Sgabeblack@google.comprivate: 19912922Sgabeblack@google.com const sc_core::sc_time ACCEPT_DELAY; 20012922Sgabeblack@google.com const sc_core::sc_time RESPONSE_DELAY; 20112922Sgabeblack@google.com 20212922Sgabeblack@google.comprivate: 20312922Sgabeblack@google.com unsigned char mMem[400]; 20412922Sgabeblack@google.com std::queue<transaction_type*> mEndRequestQueue; 20512922Sgabeblack@google.com sc_core::sc_event mEndRequestEvent; 20612922Sgabeblack@google.com std::queue<transaction_type*> mResponseQueue; 20712922Sgabeblack@google.com sc_core::sc_event mBeginResponseEvent; 20812922Sgabeblack@google.com sc_core::sc_event mEndResponseEvent; 20912922Sgabeblack@google.com}; 21012922Sgabeblack@google.com 21112922Sgabeblack@google.com#endif 212