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

@ -66,9 +66,9 @@ use defmt::panic;
use nrf52840_hal::clocks;
use embassy::executor::{task, Executor, IrqExecutor};
use embassy::interrupt::InterruptExt;
use embassy::time::{Duration, Instant, Timer};
use embassy::util::Forever;
use embassy_nrf::interrupt::Interrupt;
use embassy_nrf::{interrupt, pac, rtc};
#[task]

View File

@ -10,6 +10,7 @@ use core::ops::Deref;
use core::pin::Pin;
use core::sync::atomic::{compiler_fence, Ordering};
use core::task::{Context, Poll};
use embassy::interrupt::InterruptExt;
use embassy::io::{AsyncBufRead, AsyncWrite, Result};
use embassy::util::WakerRegistration;
use embedded_hal::digital::v2::OutputPin;

View File

@ -5,11 +5,11 @@ use core::pin::Pin;
use core::ptr;
use core::task::{Context, Poll};
use embassy::gpio::{WaitForHigh, WaitForLow};
use embassy::interrupt::InterruptExt;
use embassy::util::Signal;
use crate::hal::gpio::{Input, Level, Output, Pin as GpioPin, Port};
use crate::interrupt;
use crate::interrupt::Interrupt;
use crate::pac;
use crate::pac::generic::Reg;
use crate::pac::gpiote::_TASKS_OUT;

View File

@ -2,6 +2,7 @@ use core::cell::Cell;
use core::ops::Deref;
use core::sync::atomic::{compiler_fence, AtomicU32, Ordering};
use embassy::interrupt::InterruptExt;
use embassy::time::Clock;
use crate::interrupt;

View File

@ -9,6 +9,7 @@ use core::ops::Deref;
use core::sync::atomic::{compiler_fence, Ordering};
use core::task::{Context, Poll};
use embassy::interrupt::InterruptExt;
use embassy::util::Signal;
use crate::fmt::{assert, *};

View File

@ -4,6 +4,8 @@ use core::mem::MaybeUninit;
use core::pin::Pin;
use core::sync::atomic::{compiler_fence, Ordering};
use embassy::interrupt::InterruptExt;
use crate::fmt::{assert, *};
use crate::interrupt::Interrupt;

View File

@ -1,11 +1,12 @@
use core::cell::Cell;
use core::convert::TryInto;
use core::sync::atomic::{compiler_fence, AtomicU32, Ordering};
use embassy::time::{Clock, TICKS_PER_SECOND};
use stm32f4xx_hal::bb;
use stm32f4xx_hal::rcc::Clocks;
use embassy::interrupt::InterruptExt;
use embassy::time::{Clock, TICKS_PER_SECOND};
use crate::interrupt;
use crate::interrupt::{CriticalSection, Interrupt, Mutex};

View File

@ -8,7 +8,7 @@ use core::future::Future;
use core::ptr;
use core::sync::atomic::{self, Ordering};
use embassy::interrupt::Interrupt;
use embassy::interrupt::InterruptExt;
use embassy::uart::{Error, Uart};
use embassy::util::Signal;
@ -19,9 +19,7 @@ use crate::hal::rcc::Clocks;
use crate::hal::serial::config::{Config as SerialConfig, DmaConfig as SerialDmaConfig};
use crate::hal::serial::Pins;
use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial};
use crate::interrupt;
use crate::pac::{DMA2, USART1};
/// Interface to the Serial peripheral

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>>,
}