17 #ifndef _TLM_TLM_SIGNAL_GP_H_
18 #define _TLM_TLM_SIGNAL_GP_H_
22 #include <tlm_h/tlm_generic_payload/tlm_gp.h>
24 #include <tlm_core/tlm_2/tlm_generic_payload/tlm_gp.h>
32 struct tlm_generic_payload_base;
45 : m_extensions(max_num_extensions())
50 for(
unsigned int i = 0; i < m_extensions.size(); i++)
52 m_extensions[i]->free();
55 void reset() { m_extensions.free_entire_cache(); }
63 sc_assert(m_mm != 0 && m_ref_count > 0);
64 if(--m_ref_count == 0)
68 int get_ref_count()
const {
return m_ref_count; }
71 bool has_mm()
const {
return m_mm != 0; }
78 void free_all_extensions();
81 template <
typename T> T* set_extension(T* ext) {
return static_cast<T*
>(set_extension(T::ID, ext)); }
84 tlm_extension_base* set_extension(
unsigned int index, tlm_extension_base* ext);
88 template <
typename T> T* set_auto_extension(T* ext) {
return static_cast<T*
>(set_auto_extension(T::ID, ext)); }
91 tlm_extension_base* set_auto_extension(
unsigned int index, tlm_extension_base* ext);
94 template <
typename T>
void get_extension(T*& ext)
const { ext = get_extension<T>(); }
95 template <
typename T> T* get_extension()
const {
return static_cast<T*
>(get_extension(T::ID)); }
97 tlm_extension_base* get_extension(
unsigned int index)
const;
103 template <
typename T>
void clear_extension(
const T* ext) { clear_extension<T>(); }
109 template <
typename T>
void clear_extension() { clear_extension(T::ID); }
114 template <
typename T>
void release_extension(T* ext) { release_extension<T>(); }
119 template <
typename T>
void release_extension() { release_extension(T::ID); }
123 void clear_extension(
unsigned int index);
125 void release_extension(
unsigned int index);
133 void resize_extensions();
136 tlm_array<tlm_extension_base*> m_extensions;
138 unsigned int m_ref_count;
158 tlm_command get_command()
const {
return m_command; }
159 void set_command(
const tlm_command command) { m_command = command; }
161 SIG get_value()
const {
return m_value; }
162 void set_value(
const SIG value) { m_value = value; }
165 bool is_response_ok()
const {
return (m_response_status > 0); }
166 bool is_response_error()
const {
return (m_response_status <= 0); }
167 tlm_response_status get_response_status()
const {
return m_response_status; }
168 void set_response_status(
const tlm_response_status response_status) { m_response_status = response_status; }
169 std::string get_response_string()
const;
174 auto ret = pool.front();
182 t->free_all_extensions();
191 std::deque<tlm_signal_gp<SIG>*> pool;
195 static thread_local
gp_mm mm;
200 tlm_command m_command;
202 tlm_response_status m_response_status;
207 template <
typename SIG>
208 inline tlm_signal_gp<SIG>::tlm_signal_gp()
209 : tlm_generic_payload_base()
210 , m_command(TLM_IGNORE_COMMAND)
211 , m_response_status(TLM_OK_RESPONSE) {}
213 template <
typename SIG>
214 inline tlm_signal_gp<SIG>::tlm_signal_gp(tlm_base_mm_interface* mm)
215 : tlm_generic_payload_base(mm)
216 , m_command(TLM_IGNORE_COMMAND)
217 , m_response_status(TLM_OK_RESPONSE) {}
219 inline void tlm_generic_payload_base::free_all_extensions() {
220 m_extensions.free_entire_cache();
221 for(
unsigned int i = 0; i < m_extensions.size(); i++) {
222 if(m_extensions[i]) {
223 m_extensions[i]->free();
229 template <
typename SIG>
void tlm_signal_gp<SIG>::deep_copy_from(
const tlm_signal_gp& other) {
230 m_command = other.get_command();
231 m_response_status = other.get_response_status();
232 m_value = other.get_value();
233 copy_extensions_from(other);
236 template <
typename SIG> std::string tlm_signal_gp<SIG>::get_response_string()
const {
237 switch(m_response_status) {
238 case TLM_OK_RESPONSE:
239 return "TLM_OK_RESPONSE";
240 case TLM_INCOMPLETE_RESPONSE:
241 return "TLM_INCOMPLETE_RESPONSE";
242 case TLM_GENERIC_ERROR_RESPONSE:
243 return "TLM_GENERIC_ERROR_RESPONSE";
244 case TLM_ADDRESS_ERROR_RESPONSE:
245 return "TLM_ADDRESS_ERROR_RESPONSE";
246 case TLM_COMMAND_ERROR_RESPONSE:
247 return "TLM_COMMAND_ERROR_RESPONSE";
248 case TLM_BURST_ERROR_RESPONSE:
249 return "TLM_BURST_ERROR_RESPONSE";
250 case TLM_BYTE_ENABLE_ERROR_RESPONSE:
251 return "TLM_BYTE_ENABLE_ERROR_RESPONSE";
253 return "TLM_UNKNOWN_RESPONSE";
256 inline tlm_extension_base* tlm_generic_payload_base::set_extension(
unsigned int index, tlm_extension_base* ext) {
257 sc_assert(index < m_extensions.size());
258 tlm_extension_base* tmp = m_extensions[index];
259 m_extensions[index] = ext;
263 inline tlm_extension_base* tlm_generic_payload_base::set_auto_extension(
unsigned int index, tlm_extension_base* ext) {
264 sc_assert(index < m_extensions.size());
265 tlm_extension_base* tmp = m_extensions[index];
266 m_extensions[index] = ext;
268 m_extensions.insert_in_cache(&m_extensions[index]);
269 sc_assert(m_mm != 0);
273 inline tlm_extension_base* tlm_generic_payload_base::get_extension(
unsigned int index)
const {
274 sc_assert(index < m_extensions.size());
275 return m_extensions[index];
278 inline void tlm_generic_payload_base::clear_extension(
unsigned int index) {
279 sc_assert(index < m_extensions.size());
280 m_extensions[index] =
static_cast<tlm_extension_base*
>(0);
283 inline void tlm_generic_payload_base::release_extension(
unsigned int index) {
284 sc_assert(index < m_extensions.size());
286 m_extensions.insert_in_cache(&m_extensions[index]);
288 m_extensions[index]->free();
289 m_extensions[index] =
static_cast<tlm_extension_base*
>(0);
293 inline void tlm_generic_payload_base::update_extensions_from(
const tlm_generic_payload_base& other) {
295 sc_assert(m_extensions.size() <= other.m_extensions.size());
296 for(
unsigned int i = 0; i < m_extensions.size(); i++) {
297 if(other.m_extensions[i]) {
298 if(m_extensions[i]) {
299 m_extensions[i]->copy_from(*other.m_extensions[i]);
305 inline void tlm_generic_payload_base::copy_extensions_from(
const tlm_generic_payload_base& other) {
307 if(m_extensions.size() < other.m_extensions.size())
308 m_extensions.expand(other.m_extensions.size());
309 for(
unsigned int i = 0; i < other.m_extensions.size(); i++) {
310 if(other.m_extensions[i]) {
311 if(!m_extensions[i]) {
312 tlm_extension_base* ext = other.m_extensions[i]->clone();
315 set_auto_extension(i, ext);
317 set_extension(i, ext);
321 m_extensions[i]->copy_from(*other.m_extensions[i]);
327 inline void tlm_generic_payload_base::resize_extensions() { m_extensions.expand(max_num_extensions()); }