Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for word-addressed registers #24

Closed
tk-ka opened this issue Feb 22, 2022 · 4 comments
Closed

Add support for word-addressed registers #24

tk-ka opened this issue Feb 22, 2022 · 4 comments

Comments

@tk-ka
Copy link
Contributor

tk-ka commented Feb 22, 2022

Currently, only byte-addressed resources can be used with scc::tlm_target. The underlying type util::range_lut throws a std::runtime_error("range already mapped") if word-addressed entries are added.

Use case: Integrated circuits (discrete components) typically communicate over serial interfaces (I2C, SPI, ...) and use word addressing for the registers. To model this properly with TLM, SCC should support this.

The issue can be reproduced with the following register container class.

class test_regs : public sc_core::sc_module, public scc::resetable
{
public:
  uint32_t reg_one;
  uint32_t reg_two;
  uint32_t reg_three;
  uint32_t reg_four;

  scc::sc_register<uint32_t> one;
  scc::sc_register<uint32_t> two;
  scc::sc_register<uint32_t> three;
  scc::sc_register<uint32_t> four;

  test_regs(sc_core::sc_module_name name) :
      sc_core::sc_module(name),
      NAMED(one, reg_one, 1111, *this),
      NAMED(two, reg_two, 2222, *this),
      NAMED(three, reg_three, 3333, *this)
      NAMED(four, reg_four, 4444, *this)
  { }

    inline void registerResources(scc::tlm_target<32> &target)
    {
      target.addResource(one, 0x01);
      target.addResource(two, 0x02);
      target.addResource(three, 0x03);
      target.addResource(four, 0x04);
    }
};

Note: Multiplying the real addresses by the byte-size of the registers is a work-around but not a decent solution.

@eyck
Copy link
Contributor

eyck commented Feb 24, 2022

Actually addresses are always treated as byte addresses by convention since this is the smallest common denominator amongst the variety of systems. This also applies to the registration of resources at the sockets. So your workaround is not a workaround it is the correct implementation.
The regstration and hence the resulting address map is independent of the way it is being accessed via the socket.
I do not see why this is not a decent solution. Pls. explain.

@tk-ka
Copy link
Contributor Author

tk-ka commented Feb 25, 2022

I don't see byte-addressing as the one-and-only convention because both ways are used in applications and so both are equally valid. Feel free to pick a datasheet of an arbitrary IC with a digital interface and take a look at the address map.
The workaround is no decent implementation because you are forced to build model in which the registers will have a different address than it is in reality (IP documentation, user-perspective). This deviation is an obvious source of error when developing, maintaining and debugging the model.
And in general: It is the cleaner approach to adapt the tool (SCC) to fit to the modelling task instead of making the model fit to the tool.

@tk-ka
Copy link
Contributor Author

tk-ka commented Mar 9, 2022

Thank you @staskau for that commit!
The new template arguments works for me with GCC under Linux but I experienced a problem with MSVC. See my comment

@eyck
Copy link
Contributor

eyck commented Mar 9, 2022

fixed the std::max compile isse with 9b587f3

@eyck eyck closed this as completed Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants