|
| 1 | +#![no_std] |
| 2 | + |
| 3 | +/// Trait for enums of target-specific external interrupt numbers. |
| 4 | +/// |
| 5 | +/// This trait should be implemented by a peripheral access crate (PAC) |
| 6 | +/// on its enum of available external interrupts for a specific device. |
| 7 | +/// Each variant must convert to a `u16` of its interrupt number. |
| 8 | +/// |
| 9 | +/// # Safety |
| 10 | +/// |
| 11 | +/// * This trait must only be implemented on a PAC of a RISC-V target. |
| 12 | +/// * This trait must only be implemented on enums of external interrupts. |
| 13 | +/// * Each enum variant must represent a distinct value (no duplicates are permitted), |
| 14 | +/// * Each enum variant must always return the same value (do not change at runtime). |
| 15 | +/// * All the interrupt numbers must be less than or equal to `MAX_INTERRUPT_NUMBER`. |
| 16 | +/// * `MAX_INTERRUPT_NUMBER` must coincide with the highest allowed interrupt number. |
| 17 | +pub unsafe trait InterruptNumber: Copy { |
| 18 | + /// Highest number assigned to an interrupt source. |
| 19 | + const MAX_INTERRUPT_NUMBER: u16; |
| 20 | + |
| 21 | + /// Converts an interrupt source to its corresponding number. |
| 22 | + fn number(self) -> u16; |
| 23 | + |
| 24 | + /// Tries to convert a number to a valid interrupt source. |
| 25 | + /// If the conversion fails, it returns an error with the number back. |
| 26 | + fn from_number(value: u16) -> Result<Self, u16>; |
| 27 | +} |
| 28 | + |
| 29 | +/// Trait for enums of priority levels. |
| 30 | +/// |
| 31 | +/// This trait should be implemented by a peripheral access crate (PAC) |
| 32 | +/// on its enum of available priority numbers for a specific device. |
| 33 | +/// Each variant must convert to a `u8` of its priority level. |
| 34 | +/// |
| 35 | +/// # Safety |
| 36 | +/// |
| 37 | +/// * This trait must only be implemented on a PAC of a RISC-V target. |
| 38 | +/// * This trait must only be implemented on enums of priority levels. |
| 39 | +/// * Each enum variant must represent a distinct value (no duplicates are permitted). |
| 40 | +/// * Each enum variant must always return the same value (do not change at runtime). |
| 41 | +/// * All the priority level numbers must be less than or equal to `MAX_PRIORITY_NUMBER`. |
| 42 | +/// * `MAX_PRIORITY_NUMBER` must coincide with the highest allowed priority number. |
| 43 | +pub unsafe trait PriorityNumber: Copy { |
| 44 | + /// Number assigned to the highest priority level. |
| 45 | + const MAX_PRIORITY_NUMBER: u8; |
| 46 | + |
| 47 | + /// Converts a priority level to its corresponding number. |
| 48 | + fn number(self) -> u8; |
| 49 | + |
| 50 | + /// Tries to convert a number to a valid priority level. |
| 51 | + /// If the conversion fails, it returns an error with the number back. |
| 52 | + fn from_number(value: u8) -> Result<Self, u8>; |
| 53 | +} |
| 54 | + |
| 55 | +/// Trait for enums of HART identifiers. |
| 56 | +/// |
| 57 | +/// This trait should be implemented by a peripheral access crate (PAC) |
| 58 | +/// on its enum of available HARTs for a specific device. |
| 59 | +/// Each variant must convert to a `u16` of its HART ID number. |
| 60 | +/// |
| 61 | +/// # Safety |
| 62 | +/// |
| 63 | +/// * This trait must only be implemented on a PAC of a RISC-V target. |
| 64 | +/// * This trait must only be implemented on enums of HART IDs. |
| 65 | +/// * Each enum variant must represent a distinct value (no duplicates are permitted), |
| 66 | +/// * Each anum variant must always return the same value (do not change at runtime). |
| 67 | +/// * All the HART ID numbers must be less than or equal to `MAX_HART_ID_NUMBER`. |
| 68 | +/// * `MAX_HART_ID_NUMBER` must coincide with the highest allowed HART ID number. |
| 69 | +pub unsafe trait HartIdNumber: Copy { |
| 70 | + /// Highest number assigned to a context. |
| 71 | + const MAX_HART_ID_NUMBER: u16; |
| 72 | + |
| 73 | + /// Converts a HART ID to its corresponding number. |
| 74 | + fn number(self) -> u16; |
| 75 | + |
| 76 | + /// Tries to convert a number to a valid HART ID. |
| 77 | + /// If the conversion fails, it returns an error with the number back. |
| 78 | + fn from_number(value: u16) -> Result<Self, u16>; |
| 79 | +} |
0 commit comments