gem5  v22.1.0.0
CoreDecouplingLTInitiator.h
Go to the documentation of this file.
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 //====================================================================
21 // Nov 06, 2008
22 //
23 // Updated by:
24 // Xiaopeng Qiu, JEDA Technologies, Inc
25 // Email: qiuxp@jedatechnologies.net
26 //
27 // To fix violations of TLM2.0 rules, which are detected by JEDA
28 // TLM2.0 checker.
29 //
30 //====================================================================
31 
32 #ifndef __CORE_DECOUPLING_LT_INITIATOR_H__
33 #define __CORE_DECOUPLING_LT_INITIATOR_H__
34 
35 #include "tlm.h"
36 #include "tlm_utils/simple_initiator_socket.h"
37 #include "tlm_utils/tlm_quantumkeeper.h"
38 //#include <systemc>
39 #include <cassert>
40 //#include <iostream>
41 
43 {
44 public:
47 
48 public:
50 
51 public:
54  unsigned int nrOfTransactions = 0x5,
55  unsigned int baseAddress = 0) :
57  socket("socket"),
58  mNrOfTransactions(nrOfTransactions),
59  mBaseAddress(baseAddress),
61  {
64 
65  // Initiator thread
66  SC_THREAD(run);
67  }
68 
70  {
75 
76  } else if (mTransactionCount < 2 * mNrOfTransactions) {
78  mData = 0;
80 
81  } else {
82  return false;
83  }
84 
85  trans.set_data_ptr(reinterpret_cast<unsigned char*>(&mData));
86  trans.set_data_length(4);
87  trans.set_streaming_width(4);
89 
91  return true;
92  }
93 
95  {
96  if (trans.get_command() == tlm::TLM_WRITE_COMMAND) {
97  std::cout << name() << ": Send write request: A = 0x"
98  << std::hex << (unsigned int)trans.get_address()
99  << ", D = 0x" << mData << std::dec
100  << " @ " << mQuantumKeeper.get_current_time()
101  << " (" << sc_core::sc_time_stamp() << " + "
102  << mQuantumKeeper.get_local_time() << ")"
103  << std::endl;
104 
105  } else {
106  std::cout << name() << ": Send read request: A = 0x"
107  << std::hex << (unsigned int)trans.get_address()
108  << " @ " << mQuantumKeeper.get_current_time()
109  << " (" << sc_core::sc_time_stamp() << " + "
110  << mQuantumKeeper.get_local_time() << ")"
111  << std::endl;
112  }
113  }
114 
116  {
117  if (trans.get_response_status() != tlm::TLM_OK_RESPONSE) {
118  std::cout << name() << ": Received error response @ "
120  << " (" << sc_core::sc_time_stamp() << " + "
121  << mQuantumKeeper.get_local_time() << ")"
122  << std::endl;
123 
124  } else {
125  std::cout << name() << ": Received ok response";
126  if (trans.get_command() == tlm::TLM_READ_COMMAND) {
127  std::cout << ": D = 0x" << std::hex << mData << std::dec;
128  }
129  std::cout << " @ " << mQuantumKeeper.get_current_time()
130  << " (" << sc_core::sc_time_stamp() << " + "
131  << mQuantumKeeper.get_local_time() << ")"
132  << std::endl;
133  }
134  }
135 
136  void run()
137  {
138  transaction_type trans;
139 
140  while (initTransaction(trans)) {
141  logStartTransation(trans);
142 
143  // exec instr
145  socket->b_transport(trans, t);
147  // Target may have added a delay to the quantum -> sync if needed
148  if (mQuantumKeeper.need_sync()) {
149  std::cout << "Sync'ing..." << std::endl;
151  }
152 
153  logEndTransaction(trans);
154  }
155  wait();
156  }
157 
158 private:
159  unsigned int mNrOfTransactions;
160  unsigned int mBaseAddress;
161  unsigned int mTransactionCount;
162  unsigned int mData;
164 };
165 
166 #endif
CoreDecouplingLTInitiator(sc_core::sc_module_name name, unsigned int nrOfTransactions=0x5, unsigned int baseAddress=0)
tlm_utils::tlm_quantumkeeper mQuantumKeeper
void logEndTransaction(transaction_type &trans)
tlm::tlm_generic_payload transaction_type
tlm_utils::simple_initiator_socket< CoreDecouplingLTInitiator > initiator_socket_type
void logStartTransation(transaction_type &trans)
bool initTransaction(transaction_type &trans)
SC_HAS_PROCESS(CoreDecouplingLTInitiator)
const char * name() const
Definition: sc_object.cc:44
void set_data_ptr(unsigned char *data)
Definition: gp.hh:189
void set_response_status(const tlm_response_status response_status)
Definition: gp.hh:204
void set_address(const sc_dt::uint64 address)
Definition: gp.hh:185
void set_command(const tlm_command command)
Definition: gp.hh:181
sc_dt::uint64 get_address() const
Definition: gp.hh:184
tlm_response_status get_response_status() const
Definition: gp.hh:199
void set_data_length(const unsigned int length)
Definition: gp.hh:193
tlm_command get_command() const
Definition: gp.hh:180
void set_streaming_width(const unsigned int streaming_width)
Definition: gp.hh:213
virtual sc_core::sc_time get_current_time() const
virtual sc_core::sc_time get_local_time() const
virtual void set(const sc_core::sc_time &t)
static void set_global_quantum(const sc_core::sc_time &t)
virtual bool need_sync() const
Bitfield< 51 > t
Definition: pagetable.hh:56
@ SC_NS
Definition: sc_time.hh:43
const sc_time & sc_time_stamp()
Definition: sc_main.cc:127
@ TLM_READ_COMMAND
Definition: gp.hh:84
@ TLM_WRITE_COMMAND
Definition: gp.hh:85
@ TLM_OK_RESPONSE
Definition: gp.hh:91
@ TLM_INCOMPLETE_RESPONSE
Definition: gp.hh:92
#define SC_THREAD(name)
Definition: sc_module.hh:313

Generated on Wed Dec 21 2022 10:22:42 for gem5 by doxygen 1.9.1