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

[Request] A proposal for CSRs #2

Closed
nmigen-issue-migration opened this issue Sep 27, 2019 · 4 comments
Closed

[Request] A proposal for CSRs #2

nmigen-issue-migration opened this issue Sep 27, 2019 · 4 comments

Comments

@nmigen-issue-migration
Copy link

Issue by HarryHo90sHK
Friday Sep 27, 2019 at 07:10 GMT
Originally opened as m-labs/nmigen-soc#2


#1 Following the general ideas discussed, I have made a new abstraction for CSR objects in my fork (HarryMakes/nmigen-soc@ba5f354 fixed). An example script is given below, which will print all the fields and their properties in a CSR named "test". You might also test the slicing functionality using the format mycsr[beginbit:endbit], but please note that the upper boundary is exclusive.

from nmigen import *

from nmigen_soc.csr import *

if __name__ == "__main__":
    mycsr = CSRGeneric("test", size=64, access=ACCESS_R_W, desc="A R/W test register")
    mycsr.f += CSRField("enable", desc="Enable signal", enums=['OFF', 'ON'])
    mycsr.f += CSRField("is_writing", size=2, access=ACCESS_R, desc="Status signal of writing or not",
                        enums=[
                              ("YES", 1),
                              ("NO", 0),
                              ("UNDEFINED", 2)
                        ])
    mycsr.f += CSRField("is_reading", size=2, access=ACCESS_R, desc="Status signal of reading or not")
    mycsr.f.is_reading.e += [
        ("UNDEFINED", 2),
        ("YES", 1),
        ("NO", 0)
    ]
    mycsr.f += CSRField("is_busy", size=2, access=ACCESS_R_WONCE, desc="Busy signal",
                        enums=[
                              ("YES", 1),
                              ("NO", 0),
                              ("UNKNOWN", -1)
                        ])
    mycsr.f += [
        CSRField("misc_a", size=32),
        CSRField("misc_b"),
        CSRField("misc_c")
    ]
    mycsr.f.misc_a.e += [
        ("HOT", 100000000),
        ("COLD", -100000000),
        ("NEUTRAL", 0)
    ]
    #mycsr.f += CSRField("impossible", size=30, startbit=6)

    print("{} (size={}) is {} : {}".format(
            mycsr.name, 
            mycsr.size,
            mycsr.access,
            mycsr.desc))
    for x in mycsr._fields:
        print("    {} [{},{}] (size={}) is {}{}".format(
            mycsr._fields[x].name, 
            mycsr._fields[x].startbit,
            mycsr._fields[x].endbit, 
            mycsr._fields[x].size,
            mycsr._fields[x].access,
            (" : "+mycsr._fields[x].desc if mycsr._fields[x].desc is not None else "")))
@nmigen-issue-migration
Copy link
Author

Comment by HarryHo90sHK
Friday Sep 27, 2019 at 07:17 GMT


For reference, here are the meanings of the access type Enums:

  • ACCESS_R : Read-only
  • ACCESS_W : Write-only
  • ACCESS_R_W : Both read and write are allowed
  • ACCESS_WONCE : Write-only, and only once per reset
  • ACCESS_R_WONCE : Both read and write are allowed, but only one write is allowed per reset

Please also refer to: http://www.keil.com/pack/doc/CMSIS/SVD/html/elem_special.html#elem_access

@nmigen-issue-migration
Copy link
Author

Comment by whitequark
Friday Sep 27, 2019 at 07:20 GMT


Thanks, I'll take a look soon.

@nmigen-issue-migration
Copy link
Author

Comment by whitequark
Wednesday Oct 16, 2019 at 15:52 GMT


Thank you for the proposal. I have in mind some ways to simplify the code in your branch. I'm going to sketch out an implementation I have in mind, and then ask you for feedback to make sure I didn't miss anything important.

@jfng
Copy link
Member

jfng commented Jun 4, 2024

Superseded by #68.

@jfng jfng closed this as completed Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants