diff options
author | Gabe Black <gabeblack@google.com> | 2018-06-15 20:02:54 -0700 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-08-28 21:16:31 +0000 |
commit | eba0ab506bfa33e7810163bc255d0af4a14ac8db (patch) | |
tree | c269137367fb7a66d1377909be06f6c883f368d9 /src/systemc/tests/include/SimpleLTInitiator2.h | |
parent | dc0b98dcdcc8f3665eac4d924060a51493862f2e (diff) | |
download | gem5-eba0ab506bfa33e7810163bc255d0af4a14ac8db.tar.xz |
systemc: Add some common test include files.
These are "common" in the sense that they're not in a particular test
directory, but I think they're only used by one test.
Change-Id: I4ffd209d04ed0e5253085810913827b87412b302
Reviewed-on: https://gem5-review.googlesource.com/11272
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/tests/include/SimpleLTInitiator2.h')
-rw-r--r-- | src/systemc/tests/include/SimpleLTInitiator2.h | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/src/systemc/tests/include/SimpleLTInitiator2.h b/src/systemc/tests/include/SimpleLTInitiator2.h new file mode 100644 index 000000000..ee0118a21 --- /dev/null +++ b/src/systemc/tests/include/SimpleLTInitiator2.h @@ -0,0 +1,151 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with the + License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing + permissions and limitations under the License. + + *****************************************************************************/ + +//==================================================================== +// Nov 06, 2008 +// +// Updated by: +// Xiaopeng Qiu, JEDA Technologies, Inc +// Email: qiuxp@jedatechnologies.net +// +// To fix violations of TLM2.0 rules, which are detected by JEDA +// TLM2.0 checker. +// +//==================================================================== + +#ifndef __SIMPLE_LT_INITIATOR2_H__ +#define __SIMPLE_LT_INITIATOR2_H__ + +#include "tlm.h" +#include "tlm_utils/simple_initiator_socket.h" +//#include <systemc> +#include <cassert> +//#include <iostream> + +class SimpleLTInitiator2 : public sc_core::sc_module +{ +public: + typedef tlm::tlm_generic_payload transaction_type; + typedef tlm::tlm_phase phase_type; + typedef tlm::tlm_sync_enum sync_enum_type; + typedef tlm_utils::simple_initiator_socket<SimpleLTInitiator2> initiator_socket_type; + +public: + initiator_socket_type socket; + +public: + SC_HAS_PROCESS(SimpleLTInitiator2); + SimpleLTInitiator2(sc_core::sc_module_name name, + unsigned int nrOfTransactions = 0x5, + unsigned int baseAddress = 0x0) : + sc_core::sc_module(name), + socket("socket"), + mNrOfTransactions(nrOfTransactions), + mBaseAddress(baseAddress), + mTransactionCount(0) + { + // Initiator thread + SC_THREAD(run); + } + + bool initTransaction(transaction_type& trans) + { + if (mTransactionCount < mNrOfTransactions) { + trans.set_address(mBaseAddress + 4*mTransactionCount); + mData = mTransactionCount; + trans.set_command(tlm::TLM_WRITE_COMMAND); + + } else if (mTransactionCount < 2 * mNrOfTransactions) { + trans.set_address(mBaseAddress + 4*(mTransactionCount - mNrOfTransactions)); + mData = 0; + trans.set_command(tlm::TLM_READ_COMMAND); + + } else { + return false; + } + + trans.set_data_ptr(reinterpret_cast<unsigned char*>(&mData)); + trans.set_data_length(4); + trans.set_streaming_width(4); + trans.set_dmi_allowed(false); + trans.set_response_status(tlm::TLM_INCOMPLETE_RESPONSE); + + ++mTransactionCount; + return true; + } + + void logStartTransation(transaction_type& trans) + { + if (trans.get_command() == tlm::TLM_WRITE_COMMAND) { + std::cout << name() << ": Send write request: A = 0x" + << std::hex << (unsigned int)trans.get_address() + << ", D = 0x" << mData << std::dec + << " @ " << sc_core::sc_time_stamp() << std::endl; + + } else { + std::cout << name() << ": Send read request: A = 0x" + << std::hex << (unsigned int)trans.get_address() << std::dec + << " @ " << sc_core::sc_time_stamp() << std::endl; + } + } + + void logEndTransaction(transaction_type& trans) + { + if (trans.get_response_status() != tlm::TLM_OK_RESPONSE) { + std::cout << name() << ": Received error response @ " + << sc_core::sc_time_stamp() << std::endl; + + } else { + std::cout << name() << ": Received ok response"; + if (trans.get_command() == tlm::TLM_READ_COMMAND) { + std::cout << ": D = 0x" << std::hex << mData << std::dec; + } + std::cout << " @ " << sc_core::sc_time_stamp() << std::endl; + } + } + + void run() + { + transaction_type trans; + sc_core::sc_time t; + + while (initTransaction(trans)) { + // Create transaction and initialise t + t = sc_core::SC_ZERO_TIME; + + logStartTransation(trans); + + socket->b_transport(trans, t); + wait(t); + + logEndTransaction(trans); + } + wait(); + + } + +private: + sc_core::sc_event mEndEvent; + unsigned int mNrOfTransactions; + unsigned int mBaseAddress; + unsigned int mTransactionCount; + unsigned int mData; +}; + +#endif |