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,


Share this post

Link to post
Share on other sites

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,

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now