-
Notifications
You must be signed in to change notification settings - Fork 186
Add mtopi CSR #360
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
Merged
+104
−0
Merged
Add mtopi CSR #360
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e279538
Add mtopi CSR
KushalMeghani1644 56fe4c8
Update riscv/src/register/mtopi.rs
KushalMeghani1644 7b691f1
Update macros.rs
KushalMeghani1644 7415500
Merge branch 'mtopi' of github.com:KushalMeghani1644/riscv into mtopi
KushalMeghani1644 f1a0906
Update riscv/src/register/macros.rs
KushalMeghani1644 51b82ff
Update riscv/src/register/macros.rs
KushalMeghani1644 e4d57d2
Update riscv/src/register/mtopi.rs
KushalMeghani1644 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| //! mtopi register — Machine Top Priority Interrupt (0x7C0) | ||
| //! | ||
| //! Provides information about the highest-priority pending interrupt when AIA (Advanced Interrupt Architecture) is supported. | ||
| //! This CSR is part of the RISC-V Advanced Interrupt Architecture extension and allows software to quickly | ||
| //! identify the most important pending interrupt without scanning through multiple interrupt pending registers. | ||
| //! | ||
| //! # Usage | ||
| //! | ||
| //! ```no_run | ||
| //! use riscv::register::mtopi; | ||
| //! | ||
| //! // Read the machine top priority interrupt register | ||
| //! let mtopi_val = mtopi::read(); | ||
| //! | ||
| //! if mtopi_val.is_interrupt_pending() { | ||
| //! let interrupt_id = mtopi_val.iid(); | ||
| //! let priority = mtopi_val.iprio(); | ||
| //! println!("Highest priority interrupt: ID={}, Priority={}", interrupt_id, priority); | ||
| //! } else { | ||
| //! println!("No interrupts pending"); | ||
| //! } | ||
| //! ``` | ||
|
|
||
| read_only_csr! { | ||
| /// Machine Top Priority Interrupt Register | ||
| Mtopi: 0x7C0, | ||
| mask: 0x0FFF_00FF, | ||
| } | ||
|
|
||
| read_only_csr_field! { | ||
| Mtopi, | ||
| /// Interrupt ID (bits 16..27) | ||
| /// | ||
| /// Identifies the specific interrupt source. A value of 0 indicates no interrupt is pending. | ||
| /// Non-zero values correspond to specific interrupt sources as defined by the interrupt controller. | ||
| iid: [16:27], | ||
| } | ||
|
|
||
| read_only_csr_field! { | ||
| Mtopi, | ||
| /// Interrupt Priority ID (bits 0..7) | ||
| /// | ||
| /// Represents the priority level of the pending interrupt. | ||
| /// Lower numerical values indicate higher priority interrupts. | ||
| iprio: [0:7], | ||
| } | ||
|
|
||
| impl Mtopi { | ||
| /// Returns true if there is a valid interrupt pending | ||
| /// | ||
| /// When this returns true, both `interrupt_id()` and `priority()` will return meaningful values. | ||
| #[inline] | ||
| pub fn is_interrupt_pending(&self) -> bool { | ||
| self.iid() != 0 | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_mtopi_fields() { | ||
| let mtopi = Mtopi::from_bits(0); | ||
| test_ro_csr_field!(mtopi, iid: [16, 27], 0x0); | ||
| test_ro_csr_field!(mtopi, iprio: [0, 7], 0x0); | ||
|
|
||
| let mtopi = Mtopi::from_bits((0xB << 16) | 5); | ||
| test_ro_csr_field!(mtopi, iid: [16, 27], 0xB); | ||
| test_ro_csr_field!(mtopi, iprio: [0, 7], 0x5); | ||
|
|
||
| let mtopi = Mtopi::from_bits((0xFFF << 16) | 0xFF); | ||
| test_ro_csr_field!(mtopi, iid: [16, 27], 0xFFF); | ||
| test_ro_csr_field!(mtopi, iprio: [0, 7], 0xFF); | ||
|
|
||
| let mtopi = Mtopi::from_bits(1 << 16); | ||
| test_ro_csr_field!(mtopi, iid: [16, 27], 0x1); | ||
| test_ro_csr_field!(mtopi, iprio: [0, 7], 0x0); | ||
|
|
||
| let mtopi = Mtopi::from_bits(1); | ||
| test_ro_csr_field!(mtopi, iid: [16, 27], 0x0); | ||
| test_ro_csr_field!(mtopi, iprio: [0, 7], 0x1); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_mtopi_bitmask() { | ||
| let mtopi = Mtopi::from_bits(usize::MAX); | ||
| assert_eq!(mtopi.bits(), 0x0FFF_00FFusize); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.