gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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:
40  target_socket_type socket;
41 
42 public:
45  sc_core::sc_module(name),
46  socket("socket")
47  {
48  // register nb_transport method
51  }
52 
53  void myBTransport(transaction_type& trans, sc_core::sc_time& t)
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 
92  unsigned int transport_dbg(transaction_type& r)
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
bool is_write() const
Definition: gp.hh:178
void set_response_status(const tlm_response_status response_status)
Definition: gp.hh:204
unsigned int transport_dbg(transaction_type &r)
Bitfield< 7 > i
tlm_utils::simple_target_socket< ExplicitLTTarget > target_socket_type
SC_HAS_PROCESS(ExplicitLTTarget)
const char * name() const
Definition: sc_object.cc:46
sc_dt::uint64 get_address() const
Definition: gp.hh:184
unsigned char * get_data_ptr() const
Definition: gp.hh:188
unsigned int get_data_length() const
Definition: gp.hh:192
unsigned char mMem[400]
target_socket_type socket
const sc_time & sc_time_stamp()
Definition: sc_main.cc:130
void register_transport_dbg(MODULE *mod, unsigned int(MODULE::*cb)(transaction_type &))
const sc_time SC_ZERO_TIME
Definition: sc_time.cc:292
uint64_t uint64
Definition: sc_nbdefs.hh:172
tlm_command get_command() const
Definition: gp.hh:180
ExplicitLTTarget(sc_core::sc_module_name name)
tlm::tlm_phase phase_type
tlm_sync_enum
Definition: fw_bw_ifs.hh:31
Bitfield< 5 > t
tlm::tlm_generic_payload transaction_type
void register_b_transport(MODULE *mod, void(MODULE::*cb)(transaction_type &, sc_core::sc_time &))
tlm::tlm_sync_enum sync_enum_type
const char data[]
bool is_read() const
Definition: gp.hh:176
void myBTransport(transaction_type &trans, sc_core::sc_time &t)

Generated on Fri Feb 28 2020 16:27:04 for gem5 by doxygen 1.8.13