1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Interrupts
// This is based on Work (c) by Jorge Aparicio, see
// https://github.com/rust-embedded/cortex-m

type IrqSave = u32;

/// Enable multi-vectored interrupts
#[inline]
pub fn enable_mv_irq() {
    extern "C" {
        fn mips_enable_mv_irq();
    }
    unsafe {
        mips_enable_mv_irq();
    }
}

/// Disables all interrupts and return previous status
#[inline]
pub fn disable() -> IrqSave {
    extern "C" {
        fn mips_di() -> u32;
    }
    unsafe { mips_di() }
}

/// Enables all the interrupts and return previous status
///
/// # Safety
///
/// Do not call this function inside a critical section
#[inline]
pub unsafe fn enable() -> IrqSave {
    extern "C" {
        fn mips_ei() -> u32;
    }
    mips_ei()
}

/// Restore previously saved IRQ enablement state
///
/// # Safety
///
/// Do not call this function inside a critical section
pub unsafe fn restore(previous_status: IrqSave) {
    extern "C" {
        fn mips_restore_irq(previous_status: u32);
    }
    mips_restore_irq(previous_status)
}

/// Wait for interrupts
///
/// Use the MIPS `wait` instruction to wait for interrupts and to put the
/// processor in a power saving mode.
pub fn wait() {
    extern "C" {
        fn mips_wait();
    }
    unsafe {
        mips_wait();
    }
}