move most interrupt methods to InterruptExt extension trait. Fixes #35

This commit is contained in:
Dario Nieuwenhuis
2021-03-01 00:44:38 +01:00
parent 8a641d1312
commit 45355f184a
11 changed files with 33 additions and 11 deletions

View File

@ -17,7 +17,7 @@ mod waker;
use self::util::UninitCell;
use crate::fmt::panic;
use crate::interrupt::Interrupt;
use crate::interrupt::{Interrupt, InterruptExt};
use crate::time::Alarm;
// repr(C) is needed to guarantee that the raw::Task is located at offset 0

View File

@ -37,7 +37,24 @@ pub unsafe trait Interrupt {
/// Implementation detail, do not use outside embassy crates.
#[doc(hidden)]
unsafe fn __handler(&self) -> &'static Handler;
}
pub trait InterruptExt: Interrupt {
fn set_handler(&self, func: unsafe fn(*mut ()));
fn remove_handler(&self);
fn set_handler_context(&self, ctx: *mut ());
fn enable(&self);
fn disable(&self);
fn is_active(&self) -> bool;
fn is_enabled(&self) -> bool;
fn is_pending(&self) -> bool;
fn pend(&self);
fn unpend(&self);
fn get_priority(&self) -> Self::Priority;
fn set_priority(&self, prio: Self::Priority);
}
impl<T: Interrupt + ?Sized> InterruptExt for T {
fn set_handler(&self, func: unsafe fn(*mut ())) {
let handler = unsafe { self.__handler() };
handler.func.store(func as *mut (), Ordering::Release);

View File

@ -1,6 +1,3 @@
use crate::executor;
use crate::fmt::panic;
use crate::interrupt::Interrupt;
use core::cell::UnsafeCell;
use core::future::Future;
use core::mem;
@ -9,6 +6,10 @@ use core::task::{Context, Poll, Waker};
use cortex_m::peripheral::NVIC;
use cortex_m::peripheral::{scb, SCB};
use crate::executor;
use crate::fmt::panic;
use crate::interrupt::{Interrupt, InterruptExt};
pub struct Signal<T> {
state: UnsafeCell<State<T>>,
}