scc  2024.06
SystemC components library
apb_tlm.h
1 /*******************************************************************************
2  * Copyright 2019-2024 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 _APB_TLM_H_
18 #define _APB_TLM_H_
19 
20 #include <array>
21 #include <cstdint>
22 #include <tlm>
23 
25 namespace apb {
26 
33 std::ostream& operator<<(std::ostream& os, tlm::tlm_generic_payload const& t);
34 
35 struct apb_extension : public tlm::tlm_extension<apb_extension> {
36  // PPROT[0]
37  bool is_privileged() const;
38  void set_privileged(bool = true);
39  // HPROT[2]
40  void set_non_secure(bool = true);
41  bool is_non_secure() const;
42  // PPROT[2]
43  bool is_instruction() const;
44  void set_instruction(bool = true);
45 
46  uint8_t get_protection() const;
47  void set_protection(uint8_t);
48 
49  // PNSE
50  void set_nse(bool = true);
51  bool is_nse() const;
52 
53  apb_extension() = default;
54 
55  apb_extension(const apb_extension& o) = default;
60  tlm::tlm_extension_base* clone() const override;
65  void copy_from(tlm::tlm_extension_base const& ext) override;
66 
67 private:
68  enum { PRIV = 1, NON_SEC = 2, INSTR = 4, NSE = 8 };
69  uint8_t ext_prot{0};
70 };
71 
72 /*****************************************************************************
73  * Implementation details
74  *****************************************************************************/
75 inline bool apb_extension::is_privileged() const { return ext_prot & PRIV; }
76 
77 inline void apb_extension::set_privileged(bool priv) {
78  if(priv)
79  ext_prot |= PRIV;
80  else
81  ext_prot &= ~PRIV;
82 }
83 
84 inline bool apb_extension::is_non_secure() const { return ext_prot & NON_SEC; }
85 
86 inline void apb_extension::set_non_secure(bool priv) {
87  if(priv)
88  ext_prot |= NON_SEC;
89  else
90  ext_prot &= ~NON_SEC;
91 }
92 
93 inline bool apb_extension::is_instruction() const { return ext_prot & INSTR; }
94 
95 inline void apb_extension::set_instruction(bool instr) {
96  if(instr)
97  ext_prot |= INSTR;
98  else
99  ext_prot &= ~INSTR;
100 }
101 
102 inline uint8_t apb_extension::get_protection() const { return ext_prot & 0x7; }
103 inline void apb_extension::set_protection(uint8_t prot) { ext_prot = (ext_prot & 0x8) | (prot & 0x7); }
104 
105 inline bool apb_extension::is_nse() const { return ext_prot & NSE; }
106 
107 inline void apb_extension::set_nse(bool instr) {
108  if(instr)
109  ext_prot |= NSE;
110  else
111  ext_prot &= ~NSE;
112 }
113 
114 inline tlm::tlm_extension_base* apb_extension::clone() const { return new apb_extension(*this); }
115 
116 inline void apb_extension::copy_from(const tlm::tlm_extension_base& ext) {
117  auto const* ahb_ext = dynamic_cast<const apb_extension*>(&ext);
118  assert(ahb_ext);
119  (*this) = *ahb_ext;
120 }
121 } // namespace apb
122 
123 #endif /* _AHB_TLM_H_ */
TLM2.0 components modeling APB.
Definition: apb_tlm.cpp:21
std::ostream & operator<<(std::ostream &os, const tlm::tlm_generic_payload &t)
Definition: apb_tlm.cpp:25
tlm::tlm_extension_base * clone() const override
the clone function to create deep copies of
Definition: apb_tlm.h:114
void copy_from(tlm::tlm_extension_base const &ext) override
deep copy all values from ext
Definition: apb_tlm.h:116