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

csr: add ability to express clusters #1659

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dalegaard
Copy link
Contributor

This adds the ability to express clusters of registers. This can be very useful for peripherals with repeated groups of registers.

A CSRCluster class, emulating a simplified array, is added. Peripherals can add items to the cluster, and the CSRs will, for JSON, CSV, and HTML, be collected as normal.

For SVD, the code is extended to be able to handle outputting clusters directly in the XML structure. This way, code generation tools like svd2rust can generate nested array structures, making ergonomics significantly better when working with peripherals.

The code supports nesting of CSRClusters too.

An example usecase:

class Sample(Module, AutoCSR):
    def __init__(self):
        self._before = CSRStatus()
        self.subs = CSRCluster()
        for i in range(3):
            self.subs[i] = SampleSub()
        self._after = CSRStatus()

class SampleSub(Module, AutoCSR):
    def __init__(self):
        self._nested = CSRCluster([SampleNested(), SampleNested()])
        self._after_nested = CSRStatus()

class SampleNested(Module, AutoCSR):
    def __init__(self):
        self._field_a = CSRStatus()
        self._field_b = CSRStorage()
        self._field_c = CSRStatus()

class YourSoC(SoCMini):
    def __init__(self):
        self.sample = Sample()

I tried to make sure that the touched codebase was as small as possible, to minimize breakage of existing tools. As far as I can tell, everything that doesn't use CSRCluster should work as before with no changes.

Best regards,
Lasse

This adds the ability to express clusters of registers. This can be very
useful for peripherals with repeated groups of registers.

A `CSRCluster` class, emulating a simplified array, is added.
Peripherals can add items to the cluster, and the CSRs will, for JSON,
CSV, and HTML, be collected as normal.

For SVD, the code is extended to be able to handle outputting clusters
directly in the XML structure. This way, code generation tools like
`svd2rust` can generate nested array structures, making ergonomics
significantly better when working with peripherals.

The code supports nesting of `CSRClusters` too.
@enjoy-digital
Copy link
Owner

Thanks @dalegaard, I'll study this. I've planned some work to cleanup and document CSRs, so I'll probably want to do this first and will study your changes while doing this.

@dalegaard
Copy link
Contributor Author

Hi @enjoy-digital

Sounds great, let me know if you need me to do any changes.

Best regards,
Lasse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants