scc  2024.06
SystemC components library
ocp_tlm.h
1 /*******************************************************************************
2  * Copyright 2021 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 #ifndef _BUS_OCP_TLM_H_
18 #define _BUS_OCP_TLM_H_
19 
20 #include <array>
21 #include <cstdint>
22 #include <tlm>
23 
25 namespace ocp {
26 
27 std::ostream& operator<<(std::ostream& os, tlm::tlm_generic_payload const& t);
28 
29 enum class cmd_e : uint8_t { IDLE, WRITE, READ, READEX, READ_LINKED, WRITE_NON_POSTED, WRITE_CONDITIONAL, BROADCAST };
30 
31 enum class resp_e : uint8_t { NULL_, DVA, FAIL, ERROR };
32 
33 struct ocp_extension : public tlm::tlm_extension<ocp_extension> {
34 
35  ocp_extension() = default;
36 
37  ocp_extension(const ocp_extension& o) = default;
42  tlm::tlm_extension_base* clone() const override;
47  void copy_from(tlm::tlm_extension_base const& ext) override;
48 
49  cmd_e get_mcmd() const { return mcmd; }
50 
51  void set_mcmd(cmd_e mCmd) { mcmd = mCmd; }
52 
53  resp_e get_sresp() const { return sresp; }
54 
55  void set_sresp(resp_e sres) { this->sresp = sresp; }
56 
57 private:
58  cmd_e mcmd{cmd_e::IDLE};
59  resp_e sresp{resp_e::NULL_};
60 };
61 
62 inline tlm::tlm_extension_base* ocp_extension::clone() const { return new ocp_extension(*this); }
63 
64 inline void ocp_extension::copy_from(const tlm::tlm_extension_base& ext) {
65  auto const* ocp_ext = dynamic_cast<const ocp_extension*>(&ext);
66  assert(ocp_ext);
67  (*this) = *ocp_ext;
68 }
69 
70 // inline unsigned get_ocp_id(tlm::tlm_generic_payload& trans) {
71 // auto* ext = trans.get_extension<ocp::ocp_extension>();
72 // assert(ext && "No ocp extension found");
73 // return ext->get_id();
74 // }
75 } // namespace ocp
76 #endif // _BUS_OCP_TLM_H_
std::ostream & operator<<(std::ostream &stream, const std::vector< T > &vector)
a print function for a vector
Definition: logging.h:305
TLM2.0 components modeling OCP.
Definition: ocp_tlm.cpp:20
void copy_from(tlm::tlm_extension_base const &ext) override
deep copy all values from ext
Definition: ocp_tlm.h:64
tlm::tlm_extension_base * clone() const override
the clone function to create deep copies of
Definition: ocp_tlm.h:62