-
Notifications
You must be signed in to change notification settings - Fork 174
Generic PLIC peripheral #125
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
Conversation
Thank you for the PR. I'll look it over as soon as I can. |
Not all riscv targets will have a PLIC, should this be feature gated? |
Although, having to supply a PLIC base address would kind of act like a feature gate 🤔 |
I'm fine with both. I plan to develop other peripherals (e.g., CLIC and (A)CLINT) in the same fashion. From what I read, they all have an implementation-specific base address. Using feature gates to only import the peripherals implemented on each PAC sounds reasonable. |
Maybe we need to reconsider the concept of a context for the PLIC peripheral. These are my thoughts:
So I was thinking that the pub type PLIC = riscv::peripheral::PLIC<BASE_ADDRESS, 0>; If the microcontroller has two contexts, then it would look like this: pub type PLIC0 = riscv::peripheral::PLIC<BASE_ADDRESS, 0>;
pub type PLIC1 = riscv::peripheral::PLIC<BASE_ADDRESS, 1>; And each HART can own a context. What do you think? |
@dkhayes117 I developed an alternative implementation of the PLIC that stores the context as a const generic. I also added a feature gate for optionally adding the peripheral. Let me know what you think! |
I added additional methods and generics to the current traits. The reason for that is that I am currently working on a port of RTIC for the E310X microcontrollers. As part of this work, I identified nice-to-have features that will ease the integration of RTIC to any platform with PLIC. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good to merge, but I'll give it a couple of days to see if the other members have any opinions.
@dkhayes117 take a look at my latest commit. Basically, I added utility functions to access the MIE and MIP CSRs. I also take advantage of the |
Sorry for all these changes, but I've been discovering some deficiencies in my proposal. Unlike the I developed an alternative version of the I think this PR is now good to go (fingers crossed). |
I developed an alternative version of the |
Yaaay it works :D https://github.com/romancardenas/hifive1/blob/master/examples/interrupt.rs |
Some PLIC peripherals do not reset. This method eases the initialization of the peripheral.
I opened a new PR with a clean commit history of this very same implementation |
129: PLIC peripheral r=romancardenas a=romancardenas Same as #125 (closing right now) but with a clean commit history. I've been playing around with this implementation and detected nice-to-have features and boring patterns that could be implemented using macros. Pointers to repos that are already working with it: - [`e310x` PAC](https://github.com/greenlsi/e310x) - [`e310x-hal` HAL](https://github.com/greenlsi/e310x-hal) - [`hifive1` BSP](https://github.com/romancardenas/hifive1) with an illustrative [example](https://github.com/romancardenas/hifive1/blob/master/examples/interrupt.rs) Co-authored-by: Román Cárdenas <[email protected]>
Remove label-check from merge_group
I developed a generic driver for interfacing PLIC peripherals, as mentioned in #124.
References
For developing this peripheral, I got inspired by the following resources:
e310x
ande310x-hal
crates.cortex-m
crate.Particularities
For atomic operations, I use the
volatile-register
crate (as done incortex-m
).Unlike the NVIC for Cortex-M microcontrollers, the standard leaves the base address as "implementation-specific". Thus, my implementation uses a const generic to define the base address of the PLIC. In PACs, developers can do something like this:
I decided to use associated functions whenever possible, so we don't need to steal/pass the control of the PLIC. However, those functions that are not atomic are defined as methods.
Finally, I followed the safety guidelines of the NVIC implementation, so those associated functions that modify priorities/thresholds are marked as
unsafe
.Let me know what you think. If you prefer any other style, I'll happily modify my implementation.