gem5  v22.0.0.1
SimpleATInitiator2.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 __SIMPLE_AT_INITIATOR2_H__
33 #define __SIMPLE_AT_INITIATOR2_H__
34 
35 #include "tlm.h"
36 #include "tlm_utils/simple_initiator_socket.h"
37 //#include <systemc>
38 #include <cassert>
39 #include <queue>
40 //#include <iostream>
41 
43 {
44 public:
46  typedef tlm::tlm_phase phase_type;
49 
50 public:
51  // extended transaction, holds tlm_generic_payload + data storage
52  template <typename DT>
53  class MyTransaction : public transaction_type
54  {
55  public:
57  {
58  this->set_data_ptr(reinterpret_cast<unsigned char*>(&mData));
59  }
61  {
62  this->set_data_ptr(reinterpret_cast<unsigned char*>(&mData));
63  }
64 
65  void setData(DT& data) { mData = data; }
66  DT getData() const { return mData; }
67 
68  private:
69  DT mData;
70  };
72 
73  // Dummy Transaction Pool
74  class SimplePool : public tlm::tlm_mm_interface
75  {
76  public:
79  {
81  t->acquire();
82  return t;
83  }
85  {
86  t->release();
87  }
89  {
90  t->reset();
91  delete t;
92  }
93  };
94 
95 public:
97 
98 public:
101  unsigned int nrOfTransactions = 0x5,
102  unsigned int baseAddress = 0) :
104  socket("socket"),
106  mNrOfTransactions(nrOfTransactions),
107  mBaseAddress(baseAddress),
110  {
111  // register nb_transport method
113 
114  // Initiator thread
115  SC_THREAD(run);
116  }
117 
118  bool initTransaction(mytransaction_type*& trans)
119  {
121  trans = transPool.claim();
123  trans->setData(mTransactionCount);
125 
126  } else if (mTransactionCount < 2 * mNrOfTransactions) {
127  trans = transPool.claim();
130 
131  } else {
132  return false;
133  }
134 
135  trans->set_data_length(4);
136  trans->set_streaming_width(4);
137 
139  return true;
140  }
141 
143  {
144  if (trans.get_command() == tlm::TLM_WRITE_COMMAND) {
145  std::cout << name() << ": Send write request: A = 0x"
146  << std::hex << (unsigned int)trans.get_address()
147  << ", D = 0x" << trans.getData() << std::dec
148  << " @ " << sc_core::sc_time_stamp() << std::endl;
149 
150  } else {
151  std::cout << name() << ": Send read request: A = 0x"
152  << std::hex << (unsigned int)trans.get_address() << std::dec
153  << " @ " << sc_core::sc_time_stamp() << std::endl;
154  }
155  }
156 
158  {
159  if (trans.get_response_status() != tlm::TLM_OK_RESPONSE) {
160  std::cout << name() << ": Received error response @ "
161  << sc_core::sc_time_stamp() << std::endl;
162 
163  } else {
164  std::cout << name() << ": Received ok response";
165  if (trans.get_command() == tlm::TLM_READ_COMMAND) {
166  std::cout << ": D = 0x" << std::hex << trans.getData() << std::dec;
167  }
168  std::cout << " @ " << sc_core::sc_time_stamp() << std::endl;
169  }
170  }
171 
172  //
173  // Simple AT Initiator
174  // - Request must be accepted by the target before the next request can be
175  // send
176  // - Responses can come out of order
177  // - Responses will be accepted after fixed delay
178  //
179  void run()
180  {
181  phase_type phase;
183 
184  mytransaction_type* ptrans;
185  while (initTransaction(ptrans)) {
186  // Create transaction and initialise phase and t
187  mytransaction_type& trans = *ptrans;
188  phase = tlm::BEGIN_REQ;
190 
191  logStartTransation(trans);
192 
193  switch (socket->nb_transport_fw(trans, phase, t)) {
194  case tlm::TLM_COMPLETED:
195  // Transaction Finished, wait for the returned delay
196  wait(t);
197  logEndTransaction(trans);
198  transPool.release(&trans);
199  break;
200 
201  case tlm::TLM_ACCEPTED:
202  case tlm::TLM_UPDATED:
203  switch (phase) {
204  case tlm::BEGIN_REQ:
205  // Request phase not yet finished
206  // Wait until end of request phase before sending new request
207 
208  // FIXME
209  mCurrentTransaction = &trans;
212  break;
213 
214  case tlm::END_REQ:
215  // Request phase ended
216  if (t != sc_core::SC_ZERO_TIME) {
217  // Wait until end of request time before sending new request
218  wait(t);
219  }
220  break;
221 
222  case tlm::BEGIN_RESP:
223  // Request phase ended and response phase already started
224  if (t != sc_core::SC_ZERO_TIME) {
225  // Wait until end of request time before sending new request
226  wait(t);
227  }
228  // Notify end of response phase after ACCEPT delay
229  t += ACCEPT_DELAY;
230  phase = tlm::END_RESP;
231  socket->nb_transport_fw(trans, phase, t);
232  logEndTransaction(trans);
233  transPool.release(&trans);
234  break;
235 
236  case tlm::END_RESP: // fall-through
237  default:
238  // A target should never return with these phases
239  // If phase == END_RESP, nb_transport should have returned true
240  assert(0); exit(1);
241  break;
242  }
243  break;
244 
245  default:
246  assert(0); exit(1);
247  };
248  }
249  wait();
250 
251  }
252 
254  {
255  switch (phase) {
256  case tlm::END_REQ:
257  assert(t == sc_core::SC_ZERO_TIME); // FIXME: can t != 0?
258  // Request phase ended
260  return tlm::TLM_ACCEPTED;
261 
262  case tlm::BEGIN_RESP:
263  {
264  assert(t == sc_core::SC_ZERO_TIME); // FIXME: can t != 0?
265 
266  // Notify end of request phase if run thread is waiting for it
267  // FIXME
268  if (&trans == mCurrentTransaction) {
270  }
271 
272  assert(dynamic_cast<mytransaction_type*>(&trans));
273  mytransaction_type* myTrans = static_cast<mytransaction_type*>(&trans);
274  assert(myTrans);
275 
276  // Notify end of response phase after ACCEPT delay
277  t += ACCEPT_DELAY;
278  phase = tlm::END_RESP;
279  logEndTransaction(*myTrans);
280  transPool.release(myTrans);
281 
282  return tlm::TLM_COMPLETED;
283  }
284 
285  case tlm::BEGIN_REQ: // fall-through
286  case tlm::END_RESP: // fall-through
287  default:
288  // A target should never call nb_transport with these phases
289  assert(0); exit(1);
290 // return tlm::TLM_COMPLETED; //unreachable code
291  };
292  }
293 
294 private:
296 
297 private:
298  unsigned int mNrOfTransactions;
299  unsigned int mBaseAddress;
300  SimplePool transPool;
301  unsigned int mTransactionCount;
304 };
305 
306 #endif
SimpleATInitiator2::SimplePool::release
void release(mytransaction_type *t)
Definition: SimpleATInitiator2.h:101
SimpleATInitiator2::MyTransaction::getData
DT getData() const
Definition: SimpleATInitiator2.h:83
SimpleATInitiator2::MyTransaction::setData
void setData(DT &data)
Definition: SimpleATInitiator2.h:82
tlm::tlm_generic_payload::set_data_length
void set_data_length(const unsigned int length)
Definition: gp.hh:210
SimpleATInitiator2::logEndTransaction
void logEndTransaction(mytransaction_type &trans)
Definition: SimpleATInitiator2.h:174
SC_THREAD
#define SC_THREAD(name)
Definition: sc_module.hh:313
data
const char data[]
Definition: circlebuf.test.cc:48
tlm_utils::simple_initiator_socket_b::register_nb_transport_bw
void register_nb_transport_bw(MODULE *mod, sync_enum_type(MODULE::*cb)(transaction_type &, phase_type &, sc_core::sc_time &))
Definition: simple_initiator_socket.h:97
sc_core::sc_module
Definition: sc_module.hh:101
tlm::tlm_phase
Definition: phase.hh:47
SimpleATInitiator2::SimpleATInitiator2
SimpleATInitiator2(sc_core::sc_module_name name, unsigned int nrOfTransactions=0x5, unsigned int baseAddress=0)
Definition: SimpleATInitiator2.h:117
SimpleATInitiator2::logStartTransation
void logStartTransation(mytransaction_type &trans)
Definition: SimpleATInitiator2.h:159
tlm::TLM_COMPLETED
@ TLM_COMPLETED
Definition: fw_bw_ifs.hh:65
sc_core
Definition: messages.cc:31
tlm::TLM_WRITE_COMMAND
@ TLM_WRITE_COMMAND
Definition: gp.hh:102
tlm::TLM_UPDATED
@ TLM_UPDATED
Definition: fw_bw_ifs.hh:65
SimpleATInitiator2::initiator_socket_type
tlm_utils::simple_initiator_socket< SimpleATInitiator2 > initiator_socket_type
Definition: SimpleATInitiator2.h:65
tlm::TLM_OK_RESPONSE
@ TLM_OK_RESPONSE
Definition: gp.hh:108
tlm::END_REQ
@ END_REQ
Definition: phase.hh:42
sc_core::sc_module::sc_module
sc_module()
Definition: sc_module.cc:256
sc_core::SC_ZERO_TIME
const sc_time SC_ZERO_TIME
Definition: sc_time.cc:290
SimpleATInitiator2::socket
initiator_socket_type socket
Definition: SimpleATInitiator2.h:113
SimpleATInitiator2::initTransaction
bool initTransaction(mytransaction_type *&trans)
Definition: SimpleATInitiator2.h:135
SimpleATInitiator2::myNBTransport
sync_enum_type myNBTransport(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
Definition: SimpleATInitiator2.h:270
SimpleATInitiator2::mNrOfTransactions
unsigned int mNrOfTransactions
Definition: SimpleATInitiator2.h:315
SimpleATInitiator2::MyTransaction
Definition: SimpleATInitiator2.h:70
SimpleATInitiator2::SimplePool::free
void free(tlm::tlm_generic_payload *t)
Definition: SimpleATInitiator2.h:105
SimpleATInitiator2::MyTransaction::MyTransaction
MyTransaction()
Definition: SimpleATInitiator2.h:73
SimpleATInitiator2::ACCEPT_DELAY
const sc_core::sc_time ACCEPT_DELAY
Definition: SimpleATInitiator2.h:312
SimpleATInitiator2::phase_type
tlm::tlm_phase phase_type
Definition: SimpleATInitiator2.h:63
sc_core::SC_NS
@ SC_NS
Definition: sc_time.hh:43
tlm::tlm_generic_payload::set_command
void set_command(const tlm_command command)
Definition: gp.hh:198
gem5::VegaISA::t
Bitfield< 51 > t
Definition: pagetable.hh:56
sc_core::sc_event
Definition: sc_event.hh:169
SimpleATInitiator2::SimplePool::claim
mytransaction_type * claim()
Definition: SimpleATInitiator2.h:95
sc_core::sc_time
Definition: sc_time.hh:49
tlm::TLM_READ_COMMAND
@ TLM_READ_COMMAND
Definition: gp.hh:101
tlm_utils::simple_initiator_socket< SimpleATInitiator2 >
sc_core::sc_module_name
Definition: sc_module_name.hh:41
mm
Definition: mm.h:8
SimpleATInitiator2::SimplePool::SimplePool
SimplePool()
Definition: SimpleATInitiator2.h:94
tlm::tlm_generic_payload::set_streaming_width
void set_streaming_width(const unsigned int streaming_width)
Definition: gp.hh:230
SimpleATInitiator2::mTransactionCount
unsigned int mTransactionCount
Definition: SimpleATInitiator2.h:318
tlm::END_RESP
@ END_RESP
Definition: phase.hh:44
SimpleATInitiator2::MyTransaction::mData
DT mData
Definition: SimpleATInitiator2.h:86
gem5::X86ISA::exit
Bitfield< 3 > exit
Definition: misc.hh:848
sc_core::sc_event::notify
void notify()
Definition: sc_event.cc:337
SimpleATInitiator2::transPool
SimplePool transPool
Definition: SimpleATInitiator2.h:317
tlm::BEGIN_REQ
@ BEGIN_REQ
Definition: phase.hh:41
tlm::tlm_generic_payload
Definition: gp.hh:133
SimpleATInitiator2::SimplePool
Definition: SimpleATInitiator2.h:91
SimpleATInitiator2::run
void run()
Definition: SimpleATInitiator2.h:196
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
tlm::tlm_generic_payload::set_address
void set_address(const sc_dt::uint64 address)
Definition: gp.hh:202
SimpleATInitiator2::transaction_type
tlm::tlm_generic_payload transaction_type
Definition: SimpleATInitiator2.h:62
tlm::tlm_sync_enum
tlm_sync_enum
Definition: fw_bw_ifs.hh:48
sc_core::sc_module::wait
void wait()
Definition: sc_module.cc:428
SimpleATInitiator2::mBaseAddress
unsigned int mBaseAddress
Definition: SimpleATInitiator2.h:316
SimpleATInitiator2
Definition: SimpleATInitiator2.h:42
SimpleATInitiator2::sync_enum_type
tlm::tlm_sync_enum sync_enum_type
Definition: SimpleATInitiator2.h:64
tlm::tlm_mm_interface
Definition: gp.hh:50
SimpleATInitiator2::mEndRequestPhase
sc_core::sc_event mEndRequestPhase
Definition: SimpleATInitiator2.h:319
SimpleATInitiator2::mytransaction_type
MyTransaction< unsigned int > mytransaction_type
Definition: SimpleATInitiator2.h:88
sc_core::sc_time_stamp
const sc_time & sc_time_stamp()
Definition: sc_main.cc:127
tlm::BEGIN_RESP
@ BEGIN_RESP
Definition: phase.hh:43
SimpleATInitiator2::mCurrentTransaction
transaction_type * mCurrentTransaction
Definition: SimpleATInitiator2.h:320
SimpleATInitiator2::SC_HAS_PROCESS
SC_HAS_PROCESS(SimpleATInitiator2)
tlm::tlm_generic_payload::set_data_ptr
void set_data_ptr(unsigned char *data)
Definition: gp.hh:206
tlm::TLM_ACCEPTED
@ TLM_ACCEPTED
Definition: fw_bw_ifs.hh:65

Generated on Sat Jun 18 2022 08:12:35 for gem5 by doxygen 1.8.17