diff options
Diffstat (limited to 'src/peripheral/nvic.rs')
-rw-r--r-- | src/peripheral/nvic.rs | 119 |
1 files changed, 0 insertions, 119 deletions
diff --git a/src/peripheral/nvic.rs b/src/peripheral/nvic.rs deleted file mode 100644 index 8c12698..0000000 --- a/src/peripheral/nvic.rs +++ /dev/null @@ -1,119 +0,0 @@ -//! Nested Vector Interrupt Controller - -use interrupt::Nr; -use volatile_register::{RO, RW}; - -/// Registers -#[repr(C)] -pub struct Registers { - /// Interrupt Set-Enable - iser: [RW<u32>; 8], - reserved0: [u32; 24], - /// Interrupt Clear-Enable - icer: [RW<u32>; 8], - reserved1: [u32; 24], - /// Interrupt Set-Pending - ispr: [RW<u32>; 8], - reserved2: [u32; 24], - /// Interrupt Clear-Pending - icpr: [RW<u32>; 8], - reserved3: [u32; 24], - /// Interrupt Active Bit - iabr: [RO<u32>; 8], - reserved4: [u32; 56], - /// Interrupt Priority - ipr: [RW<u8>; 240], -} - -impl Registers { - /// Clears `interrupt` pending state - pub fn clear_pending<I>(&mut self, interrupt: I) - where I: Nr - { - let nr = interrupt.nr(); - - self.icpr[usize::from(nr / 32)].write(1 << (nr % 32)); - } - - /// Disables `interrupt` - pub fn disable<I>(&mut self, interrupt: I) - where I: Nr - { - let nr = interrupt.nr(); - - self.icer[usize::from(nr / 32)].write(1 << (nr % 32)); - } - - /// Enables `interrupt` - pub fn enable<I>(&mut self, interrupt: I) - where I: Nr - { - let nr = interrupt.nr(); - - self.iser[usize::from(nr / 32)].write(1 << (nr % 32)); - } - - /// Gets the "priority" of `interrupt` - /// - /// NOTE NVIC encodes priority in the highest bits of a byte so values like - /// `1` and `2` have the same priority. Also for NVIC priorities, a lower - /// value (e.g. `16`) has higher priority than a larger value (e.g. `32`). - pub fn get_priority<I>(&mut self, interrupt: I) -> u8 - where I: Nr - { - let nr = interrupt.nr(); - - self.ipr[usize::from(nr)].read() - } - - /// Is `interrupt` active or pre-empted and stacked - pub fn is_active<I>(&self, interrupt: I) -> bool - where I: Nr - { - let nr = interrupt.nr(); - let mask = 1 << (nr % 32); - - (self.iabr[usize::from(nr / 32)].read() & mask) == mask - } - - /// Checks if `interrupt` is enabled - pub fn is_enabled<I>(&self, interrupt: I) -> bool - where I: Nr - { - let nr = interrupt.nr(); - let mask = 1 << (nr % 32); - - (self.iser[usize::from(nr / 32)].read() & mask) == mask - } - - /// Checks if `interrupt` is pending - pub fn is_pending<I>(&self, interrupt: I) -> bool - where I: Nr - { - let nr = interrupt.nr(); - let mask = 1 << (nr % 32); - - (self.ispr[usize::from(nr / 32)].read() & mask) == mask - } - - /// Forces `interrupt` into pending state - pub fn set_pending<I>(&mut self, interrupt: I) - where I: Nr - { - let nr = interrupt.nr(); - - self.ispr[usize::from(nr / 32)].write(1 << (nr % 32)); - } - - /// Sets the "priority" of `interrupt` to `prio` - /// - /// NOTE See `get_priority` method for an explanation of how NVIC priorities - /// work. - pub fn set_priority<I>(&mut self, interrupt: I, prio: u8) - where I: Nr - { - let nr = interrupt.nr(); - - self.ipr[usize::from(nr)].write(prio); - } -} |