gem5  v20.1.0.0
ExplicitATTarget.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 #ifndef __EXPLICIT_AT_TARGET_H__
21 #define __EXPLICIT_AT_TARGET_H__
22 
23 #include "tlm.h"
24 #include "tlm_utils/simple_target_socket.h"
25 //#include <systemc>
26 #include <cassert>
27 #include <vector>
28 #include <queue>
29 //#include <iostream>
30 
32 {
33 public:
35  typedef tlm::tlm_phase phase_type;
38 
39 public:
41 
42 public:
46  socket("socket"),
48  {
49  // register nb_transport method
52 
54  }
55 
57  {
58  if (phase == tlm::BEGIN_REQ) {
59  sc_dt::uint64 address = trans.get_address();
60  assert(address < 400);
61 
62  // This target only supports one transaction at a time
63  // This will only work with LT initiators
64  assert(mCurrentTransaction == 0);
65 
66  unsigned int& data = *reinterpret_cast<unsigned int*>(trans.get_data_ptr());
67  if (trans.get_command() == tlm::TLM_WRITE_COMMAND) {
68  std::cout << name() << ": Received write request: A = 0x"
69  << std::hex << (unsigned int)address << ", D = 0x" << data
70  << std::dec << " @ " << sc_core::sc_time_stamp()
71  << std::endl;
72 
73  *reinterpret_cast<unsigned int*>(&mMem[address]) = data;
74 
75  // Synchronization on demand (eg need to assert an interrupt)
77  mCurrentTransaction = &trans;
78 
79  // End request phase
80  phase = tlm::END_REQ;
81  return tlm::TLM_UPDATED;
82 
83  } else {
84  std::cout << name() << ": Received read request: A = 0x"
85  << std::hex << (unsigned int)address
86  << std::dec << " @ " << sc_core::sc_time_stamp()
87  << std::endl;
88 
89  data = *reinterpret_cast<unsigned int*>(&mMem[address]);
90  trans.set_response_status(tlm::TLM_OK_RESPONSE);
91 
92  // Finish transaction (use timing annotation)
94  return tlm::TLM_COMPLETED;
95  }
96 
97  } else if (phase == tlm::END_RESP) {
98 
99  // Transaction finished
101  return tlm::TLM_COMPLETED;
102  }
103 
104  // Not possible
105  assert(0); exit(1);
106 // return tlm::TLM_COMPLETED; //unreachable code
107  }
108 
109  void beginResponse()
110  {
111  while (true) {
112  // Wait for next synchronization request
114 
115  assert(mCurrentTransaction);
116  // start response phase
117  phase_type phase = tlm::BEGIN_RESP;
119 
120  // Set response data
123 
125  assert(address < 400);
126  *reinterpret_cast<unsigned int*>(mCurrentTransaction->get_data_ptr()) =
127  *reinterpret_cast<unsigned int*>(&mMem[address]);
128 
129  // We are synchronized, we can read/write sc_signals, wait,...
130  // Wait before sending the response
131  wait(50, sc_core::SC_NS);
132 
133  if (socket->nb_transport_bw(*mCurrentTransaction, phase, t) == tlm::TLM_COMPLETED) {
135 
136  } else {
137  // Initiator will call nb_transport(trans, END_RESP, t)
138  }
139  }
140  }
141 
142  unsigned int transport_dbg(transaction_type& r)
143  {
144  if (r.get_address() >= 400) return 0;
145 
146  unsigned int tmp = (int)r.get_address();
147  unsigned int num_bytes;
148  if (tmp + r.get_data_length() >= 400) {
149  num_bytes = 400 - tmp;
150 
151  } else {
152  num_bytes = r.get_data_length();
153  }
154  if (!r.is_read() && !r.is_write()) {
155  return 0;
156  }
157  if (r.is_read()) {
158  for (unsigned int i = 0; i < num_bytes; ++i) {
159  r.get_data_ptr()[i] = mMem[i + tmp];
160  }
161 
162  } else {
163  for (unsigned int i = 0; i < num_bytes; ++i) {
164  mMem[i + tmp] = r.get_data_ptr()[i];
165  }
166  }
167  return num_bytes;
168  }
169 
170 private:
171  unsigned char mMem[400];
174 };
175 
176 #endif
SC_THREAD
#define SC_THREAD(name)
Definition: sc_module.hh:309
data
const char data[]
Definition: circlebuf.test.cc:42
ExplicitATTarget::mCurrentTransaction
transaction_type * mCurrentTransaction
Definition: ExplicitATTarget.h:190
ExplicitATTarget::socket
target_socket_type socket
Definition: ExplicitATTarget.h:57
sc_core::sc_module
Definition: sc_module.hh:97
tlm::tlm_phase
Definition: phase.hh:47
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
ExplicitATTarget::transaction_type
tlm::tlm_generic_payload transaction_type
Definition: ExplicitATTarget.h:51
X86ISA::exit
Bitfield< 3 > exit
Definition: misc.hh:848
ExplicitATTarget::phase_type
tlm::tlm_phase phase_type
Definition: ExplicitATTarget.h:52
tlm::TLM_COMPLETED
@ TLM_COMPLETED
Definition: fw_bw_ifs.hh:65
tlm::TLM_WRITE_COMMAND
@ TLM_WRITE_COMMAND
Definition: gp.hh:102
tlm::TLM_UPDATED
@ TLM_UPDATED
Definition: fw_bw_ifs.hh:65
tlm::TLM_OK_RESPONSE
@ TLM_OK_RESPONSE
Definition: gp.hh:108
tlm::END_REQ
@ END_REQ
Definition: phase.hh:42
ExplicitATTarget::SC_HAS_PROCESS
SC_HAS_PROCESS(ExplicitATTarget)
sc_core::SC_ZERO_TIME
const sc_time SC_ZERO_TIME
Definition: sc_time.cc:290
ExplicitATTarget::target_socket_type
tlm_utils::simple_target_socket< ExplicitATTarget > target_socket_type
Definition: ExplicitATTarget.h:54
tlm_utils::simple_target_socket_b::register_transport_dbg
void register_transport_dbg(MODULE *mod, unsigned int(MODULE::*cb)(transaction_type &))
Definition: simple_target_socket.h:125
ExplicitATTarget::beginResponse
void beginResponse()
Definition: ExplicitATTarget.h:126
ExplicitATTarget::sync_enum_type
tlm::tlm_sync_enum sync_enum_type
Definition: ExplicitATTarget.h:53
ExplicitATTarget
Definition: ExplicitATTarget.h:31
ExplicitATTarget::mResponseEvent
sc_core::sc_event mResponseEvent
Definition: ExplicitATTarget.h:189
sc_core::SC_NS
@ SC_NS
Definition: sc_time.hh:43
tlm::tlm_generic_payload::get_command
tlm_command get_command() const
Definition: gp.hh:197
sc_dt::uint64
uint64_t uint64
Definition: sc_nbdefs.hh:206
sc_core::sc_event
Definition: sc_event.hh:169
MipsISA::r
r
Definition: pra_constants.hh:95
sc_core::sc_time
Definition: sc_time.hh:49
ExplicitATTarget::mMem
unsigned char mMem[400]
Definition: ExplicitATTarget.h:188
sc_core::sc_module_name
Definition: sc_module_name.hh:41
tlm::END_RESP
@ END_RESP
Definition: phase.hh:44
tlm_utils::simple_target_socket< ExplicitATTarget >
ExplicitATTarget::transport_dbg
unsigned int transport_dbg(transaction_type &r)
Definition: ExplicitATTarget.h:159
sc_core::sc_event::notify
void notify()
Definition: sc_event.cc:337
tlm::BEGIN_REQ
@ BEGIN_REQ
Definition: phase.hh:41
tlm::tlm_generic_payload
Definition: gp.hh:133
ArmISA::t
Bitfield< 5 > t
Definition: miscregs_types.hh:67
sc_core::sc_object::name
const char * name() const
Definition: sc_object.cc:44
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
ExplicitATTarget::myNBTransport
sync_enum_type myNBTransport(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
Definition: ExplicitATTarget.h:73
tlm::tlm_generic_payload::get_address
sc_dt::uint64 get_address() const
Definition: gp.hh:201
sc_core::sc_time_stamp
const sc_time & sc_time_stamp()
Definition: sc_main.cc:128
tlm::tlm_generic_payload::get_data_ptr
unsigned char * get_data_ptr() const
Definition: gp.hh:205
tlm::BEGIN_RESP
@ BEGIN_RESP
Definition: phase.hh:43
ExplicitATTarget::ExplicitATTarget
ExplicitATTarget(sc_core::sc_module_name name)
Definition: ExplicitATTarget.h:61
tlm_utils::simple_target_socket_b::register_nb_transport_fw
void register_nb_transport_fw(MODULE *mod, sync_enum_type(MODULE::*cb)(transaction_type &, phase_type &, sc_core::sc_time &))
Definition: simple_target_socket.h:108
tlm::tlm_generic_payload::set_response_status
void set_response_status(const tlm_response_status response_status)
Definition: gp.hh:221

Generated on Wed Sep 30 2020 14:02:16 for gem5 by doxygen 1.8.17