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

Rename @Register to @RegisterDescriptor #69

Open
fumoboy007 opened this issue Jan 14, 2024 · 0 comments
Open

Rename @Register to @RegisterDescriptor #69

fumoboy007 opened this issue Jan 14, 2024 · 0 comments
Labels
mmio Related to the MMIO library

Comments

@fumoboy007
Copy link

fumoboy007 commented Jan 14, 2024

(I originally proposed this change here.)


The @Register macro is used like so:

@Register(bitWidth: 32)
struct CR1 {
  @ReadOnly(bits: 0..<1)
  var en: Bool
  @WriteOnly(bits: 1..<2)
  var clken: Bool
}

The @Register macro generates Read and Write structs using the properties of the given struct. Those generated structs are the ones that will be read from or written to. I think the macro name @Register is a little misleading because it is those generated structs that will be read from or written to, not the given struct.

By contrast, the Register struct is well-named. The struct is initialized with the memory address of the register and provides the caller with an API to access the Read/Write structs that were generated from the @Register struct:

var cr1 = Register<CR1>(unsafeAddress: 0x1000)
cr1.modify { (read, write) in
  print(read.en)
  write.clken = true
}

I propose renaming @Register to @RegisterDescriptor to make it clear that the struct is only used to describe the register and that one still needs to use the Register struct (with the @RegisterDescriptor type as a generic type parameter) to access the register’s memory.

@rauhul rauhul added the mmio Related to the MMIO library label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mmio Related to the MMIO library
Projects
None yet
Development

No branches or pull requests

2 participants