Jump to content

Recommended Posts

Dear all, 

I am new to payload extensions and I would appreciate a feedback on whether I am doing things right.. 

I need to declare a simple payload extension, including two additional fields: 

  • a reset value 
  • a 16 bit bit vector representing the value of a register

In the header, I simply declare the clone/copy from functions, plus my additional fields:

class reg_extension : public tlm::tlm_extension<reg_extension>{

  tlm::tlm_extension_base* clone() const ; 
  void copy_from(tlm::tlm_extension_base const &); 
  bool reset; 
  sc_bv<16> value; 

And then I implemented the functions, by taking care of the additional reset and value fields: 

  reset = false; 
  value = sc_bv<16>(0); 

tlm::tlm_extension_base * reg_extension::clone() const{
  cout<<"Executing clone!"<<endl;
  reg_extension * ext = new reg_extension();
  ext->reset = this->reset; 
  ext->value = this->value; 
  return ext;

void reg_extension::copy_from(tlm::tlm_extension_base const & ext){
  reset = static_cast<reg_extension const &>(ext).reset;  
  value = static_cast<reg_extension const &>(ext).value;  

Is this enough for the extension to work?
Best regards,


Link to comment
Share on other sites

  • 5 weeks later...

In general: Yes, this implementation is sufficient to implement a TLM2 extension.

Still, there is a more reliable pattern to implement the copy_from and clone methods by using the copy constructor and assignment operator of your extension type (which you may need to implement in some cases anyway and will be provided for free in your particular example):

class reg_extension : public tlm::tlm_extension<reg_extension>
  tlm::tlm_extension_base* clone() const
     { return new reg_extension(*this); } // use copy constructor
  void copy_from(tlm::tlm_extension_base const & that )
     { *this = static_cast<const reg_extension&>(that); } // use assignment operator
  // ...

This pattern works very well for all Copyable and CopyAssignable classes without having to enumerate the members in clone and copy_from.

Hope that helps,

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...