scc  2022.4.0
SystemC components library
ahb_target.cpp
1 /*******************************************************************************
2  * Copyright 2020-2022 MINRES Technologies GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *******************************************************************************/
16 
17 #include "ahb_target.h"
18 #include <scc/report.h>
19 #include <systemc>
20 #include <tuple>
21 
22 using namespace sc_core;
23 using namespace tlm;
24 using namespace ahb;
25 using namespace ahb::pe;
26 
27 /******************************************************************************
28  * target
29  ******************************************************************************/
30 
31 ahb_target_b::ahb_target_b(const sc_core::sc_module_name& nm, sc_core::sc_port_b<tlm::tlm_bw_transport_if<tlm_base_protocol_types>>& port,
32  size_t transfer_width)
33 : sc_module(nm)
34 , socket_bw(port) {
35  add_attribute(wr_data_accept_delay);
36  add_attribute(rd_addr_accept_delay);
37  add_attribute(rd_data_beat_delay);
38  add_attribute(rd_resp_delay);
39  add_attribute(wr_resp_delay);
40  dont_initialize();
41  sensitive << clk_i.pos();
42 }
43 
44 void ahb_target_b::end_of_elaboration() { clk_if = dynamic_cast<sc_core::sc_clock*>(clk_i.get_interface()); }
45 
46 void ahb_target_b::b_transport(payload_type& trans, sc_time& t) {
47  auto latency = operation_cb ? operation_cb(trans) : trans.is_read() ? rd_resp_delay.value : wr_resp_delay.value;
48  trans.set_dmi_allowed(false);
49  trans.set_response_status(tlm::TLM_OK_RESPONSE);
50  clk_if = dynamic_cast<sc_core::sc_clock*>(clk_i.get_interface());
51  if(clk_if) {
52  t += clk_if->period() * latency;
53  }
54 }
55 
56 tlm_sync_enum ahb_target_b::nb_transport_fw(payload_type& trans, phase_type& phase, sc_time& t) {
57  // TODO:
58  return tlm::TLM_COMPLETED;
59 }
60 
61 bool ahb_target_b::get_direct_mem_ptr(payload_type& trans, tlm_dmi& dmi_data) {
62  trans.set_dmi_allowed(false);
63  return false;
64 }
65 
66 unsigned int ahb_target_b::transport_dbg(payload_type& trans) { return 0; }
67 
68 void ahb_target_b::operation_resp(payload_type& trans, bool sync) {
69  // TODO
70 }
71 
72 void ahb_target_b::send_resp_thread() {
73  while(true) {
74  // waiting for responses to send
75  // TODO
76  }
77 }
void operation_resp(payload_type &trans, bool sync=false)
Definition: ahb_target.cpp:68
sc_core::sc_attribute< unsigned > rd_resp_delay
the latency between request and response phase. Will be overwritten by the return of the callback fun...
Definition: ahb_target.h:62
sc_core::sc_attribute< unsigned > wr_resp_delay
the latency between request and response phase. Will be overwritten by the return of the callback fun...
Definition: ahb_target.h:67
protocol engine implementations
Definition: ahb_initiator.h:31
TLM2.0 components modeling AHB.
Definition: ahb_tlm.cpp:19
SystemC TLM.