blob: 9a62442cb933cd6df945265d333fb723f34435a7 (
plain)
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
64
65
66
67
68
69
|
/*
* Copyright (c) 2006-2025, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author notes
* 2025-10-10 foxglove latest version
*/
use crate::bindings::*;
#[cfg(not(feature = "smp"))]
unsafe fn irq_close() -> rt_base_t {
rt_hw_interrupt_disable()
}
#[cfg(feature = "smp")]
unsafe fn irq_close() -> rt_base_t {
rt_cpus_lock()
}
#[cfg(not(feature = "smp"))]
unsafe fn irq_open(f: rt_base_t) {
rt_hw_interrupt_enable(f)
}
#[cfg(feature = "smp")]
unsafe fn irq_open(f: rt_base_t) {
rt_cpus_unlock(f)
}
pub fn no_irq<F, T>(f: F) -> T
where
F: FnOnce() -> T,
{
let level;
let out;
unsafe { level = irq_close() }
out = f();
unsafe { irq_open(level) }
out
}
#[derive(Debug, Copy, Clone)]
pub struct InterruptFlag(rt_base_t);
pub const INTERRUPT_FLAG_INIT: InterruptFlag = InterruptFlag { 0: 0 as _ };
pub fn interrupt_disable() -> InterruptFlag {
unsafe { InterruptFlag(irq_close()) }
}
pub fn interrupt_enable(f: InterruptFlag) {
unsafe { irq_open(f.0) }
}
pub fn interrupt_enter() {
unsafe {
rt_interrupt_enter();
}
}
pub fn interrupt_leave() {
unsafe {
rt_interrupt_leave();
}
}
pub fn is_irq_context() -> bool {
unsafe { rt_interrupt_get_nest() != 0 }
}
|