veecle_freertos_integration/
isr.rs

1use veecle_freertos_sys::bindings::{BaseType_t, taskYIELD};
2
3/// Keep track of whether we need to yield the execution to a different
4/// task at the end of the interrupt.
5///
6/// Should be dropped as the last thing inside a interrupt.
7#[derive(Debug)]
8pub struct InterruptContext {
9    x_higher_priority_task_woken: BaseType_t,
10}
11
12impl Default for InterruptContext {
13    fn default() -> InterruptContext {
14        InterruptContext::new()
15    }
16}
17
18impl InterruptContext {
19    /// Instantiate a new context.
20    pub fn new() -> InterruptContext {
21        InterruptContext {
22            x_higher_priority_task_woken: 0,
23        }
24    }
25
26    pub fn get_task_field_mut(&mut self) -> *mut BaseType_t {
27        &raw mut self.x_higher_priority_task_woken
28    }
29    pub fn higher_priority_task_woken(&self) -> BaseType_t {
30        self.x_higher_priority_task_woken
31    }
32}
33
34impl Drop for InterruptContext {
35    fn drop(&mut self) {
36        if self.x_higher_priority_task_woken == 1 {
37            taskYIELD()
38        }
39    }
40}