gem5  v22.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:
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]);
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 
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 
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
const char data[]
target_socket_type socket
tlm_utils::simple_target_socket< ExplicitATTarget > target_socket_type
transaction_type * mCurrentTransaction
tlm::tlm_phase phase_type
tlm::tlm_sync_enum sync_enum_type
unsigned int transport_dbg(transaction_type &r)
ExplicitATTarget(sc_core::sc_module_name name)
SC_HAS_PROCESS(ExplicitATTarget)
sync_enum_type myNBTransport(transaction_type &trans, phase_type &phase, sc_core::sc_time &t)
unsigned char mMem[400]
sc_core::sc_event mResponseEvent
tlm::tlm_generic_payload transaction_type
const char * name() const
Definition: sc_object.cc:44
unsigned char * get_data_ptr() const
Definition: gp.hh:188
void set_response_status(const tlm_response_status response_status)
Definition: gp.hh:204
sc_dt::uint64 get_address() const
Definition: gp.hh:184
tlm_command get_command() const
Definition: gp.hh:180
void register_nb_transport_fw(MODULE *mod, sync_enum_type(MODULE::*cb)(transaction_type &, phase_type &, sc_core::sc_time &))
void register_transport_dbg(MODULE *mod, unsigned int(MODULE::*cb)(transaction_type &))
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 5 > r
Definition: pagetable.hh:60
Bitfield< 51 > t
Definition: pagetable.hh:56
Bitfield< 3 > exit
Definition: misc.hh:855
const sc_time SC_ZERO_TIME
Definition: sc_time.cc:290
@ SC_NS
Definition: sc_time.hh:43
const sc_time & sc_time_stamp()
Definition: sc_main.cc:127
uint64_t uint64
Definition: sc_nbdefs.hh:172
@ BEGIN_RESP
Definition: phase.hh:43
@ END_RESP
Definition: phase.hh:44
@ BEGIN_REQ
Definition: phase.hh:41
@ END_REQ
Definition: phase.hh:42
@ TLM_WRITE_COMMAND
Definition: gp.hh:85
@ TLM_OK_RESPONSE
Definition: gp.hh:91
tlm_sync_enum
Definition: fw_bw_ifs.hh:31
@ TLM_COMPLETED
Definition: fw_bw_ifs.hh:31
@ TLM_UPDATED
Definition: fw_bw_ifs.hh:31
#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