misc: SystemC Elastic Trace Player Example.
[gem5.git] / util / tlm / sc_target.hh
1 /*
2 * Copyright (c) 2015, University of Kaiserslautern
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
24 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * Authors: Matthias Jung
33 */
34
35 #ifndef __SIM_SC_TARGET_HH__
36 #define __SIM_SC_TARGET_HH__
37
38 #include <tlm_utils/peq_with_cb_and_phase.h>
39 #include <tlm_utils/simple_target_socket.h>
40
41 #include <iostream>
42 #include <systemc>
43 #include <tlm>
44
45 using namespace sc_core;
46 using namespace std;
47
48 struct Target: sc_module
49 {
50 /** TLM interface socket: */
51 tlm_utils::simple_target_socket<Target> socket;
52
53 /** TLM related member variables: */
54 tlm::tlm_generic_payload* transaction_in_progress;
55 sc_event target_done_event;
56 bool response_in_progress;
57 bool debug;
58 tlm::tlm_generic_payload* next_response_pending;
59 tlm::tlm_generic_payload* end_req_pending;
60 tlm_utils::peq_with_cb_and_phase<Target> m_peq;
61
62 /** Storage, may be implemented with a map for large devices */
63 unsigned char *mem;
64
65 Target(sc_core::sc_module_name name,
66 bool debug,
67 unsigned long long int size,
68 unsigned int offset);
69 SC_HAS_PROCESS(Target);
70
71 /** TLM interface functions */
72 virtual void b_transport(tlm::tlm_generic_payload& trans,
73 sc_time& delay);
74 virtual unsigned int transport_dbg(tlm::tlm_generic_payload& trans);
75 virtual tlm::tlm_sync_enum nb_transport_fw(
76 tlm::tlm_generic_payload& trans,
77 tlm::tlm_phase& phase,
78 sc_time& delay);
79
80 /** Callback of Payload Event Queue: */
81 void peq_cb(tlm::tlm_generic_payload& trans,
82 const tlm::tlm_phase& phase);
83
84 /** Helping function common to b_transport and nb_transport */
85 void execute_transaction(tlm::tlm_generic_payload& trans);
86
87 /** Helping functions and processes: */
88 void send_end_req(tlm::tlm_generic_payload& trans);
89 void send_response(tlm::tlm_generic_payload& trans);
90
91 /** Method process that runs on target_done_event */
92 void execute_transaction_process();
93
94 /** Helping Variables **/
95 unsigned long long int size;
96 unsigned offset;
97 };
98
99 #endif //__SIM_SC_TARGET_HH__
100