Coder Social home page Coder Social logo

Comments (5)

sendyne-nicocvn avatar sendyne-nicocvn commented on July 29, 2024

Hi @stephenwhittle
First, I am glad to hear that cppreg is working fine for you.

I first want to confirm what this issue is about. Say we have a register of the form:

.... Field A Field B ....
.... 1 0 ....

Assuming Field A and Field B are "write 1 to toggle" the issue is that if you
write 1 to Field B the current cppreg implementation will "rewrite" the value 1
in Field A thus leading to:

.... Field A Field B ....
.... 0 1 ....

while you would want to have:

.... Field A Field B ....
.... 1 1 ....

Can you confirm that my understanding is correct? I can think of several ways to
tackle this issue but I first want to make sure I understand correctly.

As a side note, it is possible to read the register memory (for both packed and
normal registers). Register memory handling in the current version of cppreg
(v0.4) was significantly revised compared to previous versions: registers and
packed registers now go through the same facility to manager the memory (see the
Memory header). This means that if you have a type Reg (packed or not)
you can use:

  • Reg::rw_mem_device() to get a read-write access to the memory,
  • Reg::ro_mem_device() to get a read-only access to the memory.

Note that similar functions are also available in previous cppreg versions but
the details of their implementations differ.

from cppreg.

stephenwhittle avatar stephenwhittle commented on July 29, 2024

Yes, you're correct in your understanding of the issue at hand. Thanks for the reminder re cppreg versions too - I'm using it as a submodule and had somehow forgotten to update. It might be worth mentioning rw_mem_device etc in the quick start guide, if you have a few moments to include a note on it, as I wasn't aware of that at all.
With that in mind, it looks like a call to ro_mem_device to get the existing state, followed by a merge_write call to all the fields in the register, would give me the equivalent behaviour to the original implementation, but I'm happy to hear your alternative suggestions.

from cppreg.

sendyne-nicocvn avatar sendyne-nicocvn commented on July 29, 2024

Ok I created #15 and documentation will be updated very soon.

Regarding this issue a few comments first:

  • the shadow value implementation is not really designed for this type of issue; it is intended to be used for write-only registers and I do not see a clear path on how to implement handling of "toggle fields",
  • we could implement a dedicated access policy for such fields but this does not solve the problem; what would be needed is for the register to be aware that it contains "toggle fields" so that it could properly manage the read/write for these fields.

Your approach (reading the whole register and managing the writes through merge_write) is typically what we do in various edge cases that requires additional logic for group of fields. If you want I can add to cppreg a generic implementation of a "managed register" that could handle toggle fields or other edge cases. This is in my opinion the best approach.

The other solution is to add more logic to the register implementation with custom access policies but this will be less generic than the "managed register" approach and will take more time as I would have to think on how to do it in practice.

from cppreg.

stephenwhittle avatar stephenwhittle commented on July 29, 2024

The managed register idea sounds like the best way to accomplish this in an extensible way, so that gets my vote. I was just really dreading having to manage this single register CMSIS-style to avoid messing up the toggles :)

from cppreg.

sendyne-nicocvn avatar sendyne-nicocvn commented on July 29, 2024

Sounds good; will add the manager register implementation as soon as possible.

from cppreg.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.