gem5  v22.1.0.0
ExplicitLTTarget.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_LT_TARGET_H__
21 #define __EXPLICIT_LT_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")
47  {
48  // register nb_transport method
51  }
52 
54  {
55  sc_dt::uint64 address = trans.get_address();
56  assert(address < 400);
57 
58  unsigned int& data = *reinterpret_cast<unsigned int*>(trans.get_data_ptr());
59  if (trans.get_command() == tlm::TLM_WRITE_COMMAND) {
60  std::cout << name() << ": Received write request: A = 0x"
61  << std::hex << (unsigned int)address << ", D = 0x" << data
62  << std::dec << " @ " << sc_core::sc_time_stamp()
63  << std::endl;
64 
65  *reinterpret_cast<unsigned int*>(&mMem[address]) = data;
66 
67  // Synchronization on demand (eg need to assert an interrupt)
68  // Wait for passed timing annotation + wait for an extra 50 ns
71 
72  // We are synchronized, we can read/write sc_signals, wait,...
73 
74  *reinterpret_cast<unsigned int*>(trans.get_data_ptr()) =
75  *reinterpret_cast<unsigned int*>(&mMem[address]);
76 
77  } else {
78  std::cout << name() << ": Received read request: A = 0x"
79  << std::hex << (unsigned int)address
80  << std::dec << " @ " << sc_core::sc_time_stamp()
81  << std::endl;
82 
83  data = *reinterpret_cast<unsigned int*>(&mMem[address]);
84 
85  // Finish transaction (use timing annotation)
87  }
88 
90  }
91 
93  {
94  if (r.get_address() >= 400) return 0;
95 
96  unsigned int tmp = (int)r.get_address();
97  unsigned int num_bytes;
98  if (tmp + r.get_data_length() >= 400) {
99  num_bytes = 400 - tmp;
100 
101  } else {
102  num_bytes = r.get_data_length();
103  }
104  if (!r.is_read() && !r.is_write()) {
105  return 0;
106  }
107  if (r.is_read()) {
108  for (unsigned int i = 0; i < num_bytes; ++i) {
109  r.get_data_ptr()[i] = mMem[i + tmp];
110  }
111 
112  } else {
113  for (unsigned int i = 0; i < num_bytes; ++i) {
114  mMem[i + tmp] = r.get_data_ptr()[i];
115  }
116  }
117  return num_bytes;
118  }
119 
120 private:
121  unsigned char mMem[400];
122 };
123 
124 #endif
const char data[]
unsigned char mMem[400]
tlm::tlm_generic_payload transaction_type
ExplicitLTTarget(sc_core::sc_module_name name)
tlm_utils::simple_target_socket< ExplicitLTTarget > target_socket_type
target_socket_type socket
unsigned int transport_dbg(transaction_type &r)
tlm::tlm_sync_enum sync_enum_type
tlm::tlm_phase phase_type
void myBTransport(transaction_type &trans, sc_core::sc_time &t)
SC_HAS_PROCESS(ExplicitLTTarget)
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_b_transport(MODULE *mod, void(MODULE::*cb)(transaction_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
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
@ TLM_WRITE_COMMAND
Definition: gp.hh:85
@ TLM_OK_RESPONSE
Definition: gp.hh:91
tlm_sync_enum
Definition: fw_bw_ifs.hh:31

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