Skip to content

Commit

Permalink
Make InterruptNumber Copy; replace references with copies in some arm…
Browse files Browse the repository at this point in the history
…v6m-only functions
  • Loading branch information
adamgreig committed Jul 14, 2020
1 parent b7c3ebc commit 00467cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use bare_metal::{CriticalSection, Mutex};
/// and must always return the same value (do not change at runtime).
///
/// These requirements ensure safe nesting of critical sections.
pub unsafe trait InterruptNumber: Into<u16> {}
pub unsafe trait InterruptNumber: Into<u16> + Copy {}

/// Disables all interrupts
#[inline]
Expand Down
14 changes: 7 additions & 7 deletions src/peripheral/nvic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ impl NVIC {
#[cfg(armv6m)]
{
// NOTE(unsafe) atomic read with no side effects
let ipr_n = unsafe { (*Self::ptr()).ipr[Self::ipr_index(&interrupt)].read() };
let prio = (ipr_n >> Self::ipr_shift(&interrupt)) & 0x0000_00ff;
let ipr_n = unsafe { (*Self::ptr()).ipr[Self::ipr_index(interrupt)].read() };
let prio = (ipr_n >> Self::ipr_shift(interrupt)) & 0x0000_00ff;
prio as u8
}
}
Expand Down Expand Up @@ -222,9 +222,9 @@ impl NVIC {

#[cfg(armv6m)]
{
self.ipr[Self::ipr_index(&interrupt)].modify(|value| {
let mask = 0x0000_00ff << Self::ipr_shift(&interrupt);
let prio = u32::from(prio) << Self::ipr_shift(&interrupt);
self.ipr[Self::ipr_index(interrupt)].modify(|value| {
let mask = 0x0000_00ff << Self::ipr_shift(interrupt);
let prio = u32::from(prio) << Self::ipr_shift(interrupt);

(value & !mask) | prio
})
Expand All @@ -245,7 +245,7 @@ impl NVIC {

#[cfg(armv6m)]
#[inline]
fn ipr_index<I>(interrupt: &I) -> usize
fn ipr_index<I>(interrupt: I) -> usize
where
I: InterruptNumber,
{
Expand All @@ -254,7 +254,7 @@ impl NVIC {

#[cfg(armv6m)]
#[inline]
fn ipr_shift<I>(interrupt: &I) -> usize
fn ipr_shift<I>(interrupt: I) -> usize
where
I: InterruptNumber,
{
Expand Down

0 comments on commit 00467cd

Please sign in to comment.