Skip to content

Commit

Permalink
Fine tune hw2logical/logical2hw
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeaurivage committed Dec 11, 2023
1 parent b6ae25b commit a0d7865
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions hal/src/async_hal/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ impl Priority {
/// See LICENSE-MIT for the license.
///
/// [`cortex-m-interrupt`]: https://github.com/datdenkikniet/cortex-m-interrupt
const fn logical2hw(self) -> u8 {
#[inline]
#[must_use]
pub const fn logical2hw(self) -> u8 {
((1 << NVIC_PRIO_BITS) - self as u8) << (8 - NVIC_PRIO_BITS)
}

Expand All @@ -421,7 +423,9 @@ impl Priority {
/// and so on. Any other value will cause a panic. To save yourself some
/// trouble, use this method only with hardware priority values gotten
/// directly from the NVIC.
const fn hw2logical(prio: u8) -> Self {
#[inline]
#[must_use]
pub const fn hw2logical(prio: u8) -> Self {
assert!(prio % 0x20 == 0);
unsafe { mem::transmute((1 << NVIC_PRIO_BITS) - (prio >> (8 - NVIC_PRIO_BITS))) }
}
Expand Down

0 comments on commit a0d7865

Please sign in to comment.