[][src]Struct interrupture::InterruptTable

pub struct InterruptTable<'a, IC: InterruptController> { /* fields omitted */ }

The InterruptTable guarantees safe and 'free of data races' use of interrupts.

To ensure that no data races can occur, it uses the Send and Sync concurrency concept from Rust. The InterruptTable can only be used in the code(&mut InterruptTable) function passed to the scope function, to ensure that InterruptTable.drop() is called.

Examples

interrupts::scope(nvic, |irq| { hprintln!("Default handler: {}", irq) },
    use stm32f7::interrupts::interrupt_request::InterruptRequest::Tim7;
    use interrupts::Priority::P1;
    |interrupt_table| {

        let _ = interrupt_table.register(Tim7, P1, || {
        hprintln!("Interrupt handler for Tim7");
    });
});

Methods

impl<'a, IC: InterruptController> InterruptTable<'a, IC>[src]

pub fn register<F>(
    &mut self,
    irq: IC::Request,
    priority: IC::Priority,
    isr: F
) -> Result<InterruptHandle<(), IC::Request>, Error> where
    F: FnMut() + 'a + Send
[src]

Registers an interrupt with the lifetime of the InterruptTable.

Examples

use stm32f7::interrupts::interrupt_request::InterruptRequest::Tim7;
use interrupts::Priority::P1;
interrupts::scope(nvic, |irq| { hprintln!("Default handler: {}", irq) },
    |interrupt_table| {
            let interrupt_handle = interrupt_table.register(Tim7, P1,
            || {
                // Isr for interrupt `Tim7`
            }).expect("Interrupt already used");

            /* Code that needs interrupt `Tim7` */

            // Unregister interrupt and get back the ownership to `data`
            let data = interrupt_table.unregister(interrupt_handle);
            assert!(data.is_none());
});

pub fn register_owned<F, T>(
    &mut self,
    irq: IC::Request,
    priority: IC::Priority,
    owned_data: T,
    isr: F
) -> Result<InterruptHandle<T, IC::Request>, Error> where
    T: Send,
    F: FnMut(&mut T) + 'a + Send
[src]

Registers an interrupt with the lifetime of the InterruptTable and pass ownership of a variable owned_data: T that is passed to the isr(&mut T) when the corresponding interupt irq occur.

The ownership of the data owned_data is returned in the unregister() function

Examples

use stm32f7::interrupts::interrupt_request::InterruptRequest::Tim7;
use interrupts::Priority::P1;
interrupts::scope(nvic, |irq| { hprintln!("Default handler: {}", irq) },
    |interrupt_table| {
            let data: SomeData = ...;
            let interrupt_handle = interrupt_table.register_owned(Tim7, P1, data,
            |owned_data| {
                // Isr for interrupt `Tim7`
                owned_data.do_anything();
            }).expect("Interrupt already used");

            /* Code that needs interrupt `Tim7` */

            // Unregister interrupt and get back the ownership to `data`
            let data = interrupt_table.unregister(interrupt_handle).unwrap();
});

pub fn with_interrupt<F, C>(
    &mut self,
    irq: IC::Request,
    priority: IC::Priority,
    isr: F,
    code: C
) -> Result<(), Error> where
    F: FnMut() + Send,
    C: FnOnce(&mut InterruptTable<IC>), 
[src]

Registers a temporary interrupt that is enabled while the function code is running.

isr() is called, when interrupt irq occur. Interrupt irq is disabled again after this function.

Examples

use stm32f7::interrupts::interrupt_request::InterruptRequest::Tim7;
use interrupts::Priority::P1;
// Open scope with interrupt support
interrupts::scope(nvic, |irq| { hprintln!("Default handler: {}", irq) },
    |interrupt_table| {
        let a = &mut some_data;
        interrupt_table.with_interrupt(Tim7, P1,
            || { // Isr for interrupt `Tim7``
                some_data.do_anything();
            },
            || { /* code that needs that interrupt `Tim7` to be set */ }
        );
        // interrupt is not set anymore, `some_data` is available again
});

pub fn unregister<T>(
    &mut self,
    interrupt_handle: InterruptHandle<T, IC::Request>
) -> T
[src]

Unregisters the interrupt corresponding to the interrupt_handle.

The interrupt is diabled and the binded isr is removed.

Returns the ownership of the data that was passed to the InterruptTable with register_owned(..., owned_data: T, ...) or None when register(...) was used.

Examples

With owned data:

use stm32f7::interrupts::interrupt_request::InterruptRequest::Tim7;
use interrupts::Priority::P1;
interrupts::scope(nvic, |irq| { hprintln!("Default handler: {}", irq) },
    |interrupt_table| {
            let data: SomeData = ...;
            let interrupt_handle = interrupt_table.register_owned(Tim7, P1, data,
            |owned_data| {
                // Isr for interrupt `Tim7`
                owned_data.do_anything();
            }).expect("Interrupt already used");

            /* Code that needs interrupt `Tim7` */

            // Unregister interrupt and get back the ownership to `data`
            let data = interrupt_table.unregister(interrupt_handle);
            assert!(data.is_some());
            let data = data.unwrap();
});

Without owned data:

use stm32f7::interrupts::interrupt_request::InterruptRequest::Tim7;
use interrupts::Priority::P1;
interrupts::scope(nvic, |irq| { hprintln!("Default handler: {}", irq) },
    |interrupt_table| {
            let interrupt_handle = interrupt_table.register(Tim7, P1,
            || {
                // Isr for interrupt `Tim7`
            }).expect("Interrupt already used");

            /* Code that needs interrupt `Tim7` */

            // Unregister interrupt and get back the ownership to `data`
            let data = interrupt_table.unregister(interrupt_handle);
            assert!(data.is_none());
});

pub fn set_priority<T>(
    &mut self,
    interrupt_handle: &InterruptHandle<T, IC::Request>,
    priority: IC::Priority
)
[src]

Sets the priority of the interrupt corresponding to the interrupt_handle.

pub fn get_priority<T>(
    &self,
    interrupt_handle: &InterruptHandle<T, IC::Request>
) -> IC::Priority
[src]

Returns the priority of the interrupt corresponding to the interrupt_handle.

pub fn clear_pending_state<T>(
    &mut self,
    interrupt_handle: &InterruptHandle<T, IC::Request>
)
[src]

Clears the pending state of the interrupt corresponding to the interrupt_handle.

pub fn set_pending_state<T>(
    &mut self,
    interrupt_handle: &InterruptHandle<T, IC::Request>
)
[src]

Sets the pending state of the interrupt corresponding to the interrupt_handle.

pub fn get_pending_state<T>(
    &self,
    interrupt_handle: &InterruptHandle<T, IC::Request>
) -> bool
[src]

Returns the pending state of the interrupt corresponding to the interrupt_handle.

pub fn trigger(&mut self, irq: IC::Request)[src]

Triggers the given interrupt irq.

Trait Implementations

impl<'a, IC: InterruptController> Drop for InterruptTable<'a, IC>[src]

impl<'a, IC> !Sync for InterruptTable<'a, IC>[src]

Auto Trait Implementations

impl<'a, IC> !Send for InterruptTable<'a, IC>

Blanket Implementations

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]