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

Read-only storage support #13

Closed
eldruin opened this issue Mar 4, 2021 · 0 comments · Fixed by #12
Closed

Read-only storage support #13

eldruin opened this issue Mar 4, 2021 · 0 comments · Fixed by #12

Comments

@eldruin
Copy link
Member

eldruin commented Mar 4, 2021

Regarding the read-only storage trait split discussed in #9, I have two use cases:

  1. Read-only memory: For chips that really cannot be reprogrammed after leaving the factory, it would be nicer if any attempt to do a write() would simply not compile, rather than adding some kind of UnsupportedOperation error variant (which now you need to handle) or panicking at runtime.
  2. Lockable memory: For chips that provide lockable memory, initially the driver could provide an struct implementing only ReadOnlyStorage.
    2a. Then on an unlock() driver method, it can transform that into one implementing the full ReadWriteStorage.
    2b. When done, another lock() method can transform that into a ReadOnlyStorage.

In several drivers I have written a somewhat similar implementation of (2), offering only some of the operations depending on the mode. See for example this driver.

Advantadges

  • Support ROM natively.
  • Impossible to run the wrong operation for the mode the device is in as the code will not compile.
  • Skip that OopsWrongMode error variant or panics and any runtime handling thereof.

Disadvantadges

  • Locking/unlocking dance is more complicated than when just returning an error, especially around error recovery.
  • Devices/setups where the memory does a reset independently of the software need to be modeled correctly by the driver/app or cannot use the ReadOnly version, depending on how the system works.

PS: Please feel free to choose different names.

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

Successfully merging a pull request may close this issue.

1 participant