Skip to content

add NVIC::{mask,unmask} #150

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
merged 1 commit into from
Jun 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/peripheral/nvic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,44 @@ impl NVIC {
}

/// Disables `interrupt`
pub fn disable<I>(&mut self, interrupt: I)
pub fn mask<I>(interrupt: I)
where
I: Nr,
{
let nr = interrupt.nr();

unsafe { self.icer[usize::from(nr / 32)].write(1 << (nr % 32)) }
// NOTE(unsafe) this is a write to a stateless register
unsafe { (*Self::ptr()).icer[usize::from(nr / 32)].write(1 << (nr % 32)) }
}

/// Enables `interrupt`
pub fn enable<I>(&mut self, interrupt: I)
///
/// This function is `unsafe` because it can break mask-based critical sections
pub unsafe fn unmask<I>(interrupt: I)
where
I: Nr,
{
let nr = interrupt.nr();
// NOTE(ptr) this is a write to a stateless register
(*Self::ptr()).iser[usize::from(nr / 32)].write(1 << (nr % 32))
}

/// Disables `interrupt`
#[deprecated(since = "0.6.1", note = "Use `NVIC::mask`")]
pub fn disable<I>(&mut self, interrupt: I)
where
I: Nr,
{
Self::mask(interrupt)
}

unsafe { self.iser[usize::from(nr / 32)].write(1 << (nr % 32)) }
/// **WARNING** This method is a soundness hole in the API; it should actually be an `unsafe`
/// function. Use `NVIC::unmask` which has the right unsafety.
#[deprecated(since = "0.6.1", note = "Use `NVIC::unmask`")]
pub fn enable<I>(&mut self, interrupt: I)
where
I: Nr,
{
unsafe { Self::unmask(interrupt) }
}

/// Returns the NVIC priority of `interrupt`
Expand Down