freertos_rust/
isr.rs

1use crate::base::*;
2use crate::shim::*;
3
4/// Keep track of whether we need to yield the execution to a different
5/// task at the end of the interrupt.
6///
7/// Should be dropped as the last thing inside a interrupt.
8pub struct InterruptContext {
9    x_higher_priority_task_woken: FreeRtosBaseType,
10}
11
12impl InterruptContext {
13    /// Instantiate a new context.
14    pub fn new() -> InterruptContext {
15        InterruptContext { x_higher_priority_task_woken: 0 }
16    }
17
18    pub unsafe fn get_task_field_mut(&self) -> FreeRtosBaseTypeMutPtr {
19        self.x_higher_priority_task_woken as *mut _
20    }
21}
22
23impl Drop for InterruptContext {
24    fn drop(&mut self) {
25        if self.x_higher_priority_task_woken == 1 {
26            unsafe { freertos_rs_isr_yield(); }
27        }
28    }
29}