move most interrupt methods to InterruptExt extension trait. Fixes #35
This commit is contained in:
parent
8a641d1312
commit
45355f184a
@ -66,9 +66,9 @@ use defmt::panic;
|
|||||||
use nrf52840_hal::clocks;
|
use nrf52840_hal::clocks;
|
||||||
|
|
||||||
use embassy::executor::{task, Executor, IrqExecutor};
|
use embassy::executor::{task, Executor, IrqExecutor};
|
||||||
|
use embassy::interrupt::InterruptExt;
|
||||||
use embassy::time::{Duration, Instant, Timer};
|
use embassy::time::{Duration, Instant, Timer};
|
||||||
use embassy::util::Forever;
|
use embassy::util::Forever;
|
||||||
use embassy_nrf::interrupt::Interrupt;
|
|
||||||
use embassy_nrf::{interrupt, pac, rtc};
|
use embassy_nrf::{interrupt, pac, rtc};
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
|
@ -10,6 +10,7 @@ use core::ops::Deref;
|
|||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
use core::sync::atomic::{compiler_fence, Ordering};
|
use core::sync::atomic::{compiler_fence, Ordering};
|
||||||
use core::task::{Context, Poll};
|
use core::task::{Context, Poll};
|
||||||
|
use embassy::interrupt::InterruptExt;
|
||||||
use embassy::io::{AsyncBufRead, AsyncWrite, Result};
|
use embassy::io::{AsyncBufRead, AsyncWrite, Result};
|
||||||
use embassy::util::WakerRegistration;
|
use embassy::util::WakerRegistration;
|
||||||
use embedded_hal::digital::v2::OutputPin;
|
use embedded_hal::digital::v2::OutputPin;
|
||||||
|
@ -5,11 +5,11 @@ use core::pin::Pin;
|
|||||||
use core::ptr;
|
use core::ptr;
|
||||||
use core::task::{Context, Poll};
|
use core::task::{Context, Poll};
|
||||||
use embassy::gpio::{WaitForHigh, WaitForLow};
|
use embassy::gpio::{WaitForHigh, WaitForLow};
|
||||||
|
use embassy::interrupt::InterruptExt;
|
||||||
use embassy::util::Signal;
|
use embassy::util::Signal;
|
||||||
|
|
||||||
use crate::hal::gpio::{Input, Level, Output, Pin as GpioPin, Port};
|
use crate::hal::gpio::{Input, Level, Output, Pin as GpioPin, Port};
|
||||||
use crate::interrupt;
|
use crate::interrupt;
|
||||||
use crate::interrupt::Interrupt;
|
|
||||||
use crate::pac;
|
use crate::pac;
|
||||||
use crate::pac::generic::Reg;
|
use crate::pac::generic::Reg;
|
||||||
use crate::pac::gpiote::_TASKS_OUT;
|
use crate::pac::gpiote::_TASKS_OUT;
|
||||||
|
@ -2,6 +2,7 @@ use core::cell::Cell;
|
|||||||
use core::ops::Deref;
|
use core::ops::Deref;
|
||||||
use core::sync::atomic::{compiler_fence, AtomicU32, Ordering};
|
use core::sync::atomic::{compiler_fence, AtomicU32, Ordering};
|
||||||
|
|
||||||
|
use embassy::interrupt::InterruptExt;
|
||||||
use embassy::time::Clock;
|
use embassy::time::Clock;
|
||||||
|
|
||||||
use crate::interrupt;
|
use crate::interrupt;
|
||||||
|
@ -9,6 +9,7 @@ use core::ops::Deref;
|
|||||||
use core::sync::atomic::{compiler_fence, Ordering};
|
use core::sync::atomic::{compiler_fence, Ordering};
|
||||||
use core::task::{Context, Poll};
|
use core::task::{Context, Poll};
|
||||||
|
|
||||||
|
use embassy::interrupt::InterruptExt;
|
||||||
use embassy::util::Signal;
|
use embassy::util::Signal;
|
||||||
|
|
||||||
use crate::fmt::{assert, *};
|
use crate::fmt::{assert, *};
|
||||||
|
@ -4,6 +4,8 @@ use core::mem::MaybeUninit;
|
|||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
use core::sync::atomic::{compiler_fence, Ordering};
|
use core::sync::atomic::{compiler_fence, Ordering};
|
||||||
|
|
||||||
|
use embassy::interrupt::InterruptExt;
|
||||||
|
|
||||||
use crate::fmt::{assert, *};
|
use crate::fmt::{assert, *};
|
||||||
use crate::interrupt::Interrupt;
|
use crate::interrupt::Interrupt;
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
use core::sync::atomic::{compiler_fence, AtomicU32, Ordering};
|
use core::sync::atomic::{compiler_fence, AtomicU32, Ordering};
|
||||||
|
|
||||||
use embassy::time::{Clock, TICKS_PER_SECOND};
|
|
||||||
use stm32f4xx_hal::bb;
|
use stm32f4xx_hal::bb;
|
||||||
use stm32f4xx_hal::rcc::Clocks;
|
use stm32f4xx_hal::rcc::Clocks;
|
||||||
|
|
||||||
|
use embassy::interrupt::InterruptExt;
|
||||||
|
use embassy::time::{Clock, TICKS_PER_SECOND};
|
||||||
|
|
||||||
use crate::interrupt;
|
use crate::interrupt;
|
||||||
use crate::interrupt::{CriticalSection, Interrupt, Mutex};
|
use crate::interrupt::{CriticalSection, Interrupt, Mutex};
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use core::future::Future;
|
|||||||
use core::ptr;
|
use core::ptr;
|
||||||
use core::sync::atomic::{self, Ordering};
|
use core::sync::atomic::{self, Ordering};
|
||||||
|
|
||||||
use embassy::interrupt::Interrupt;
|
use embassy::interrupt::InterruptExt;
|
||||||
use embassy::uart::{Error, Uart};
|
use embassy::uart::{Error, Uart};
|
||||||
use embassy::util::Signal;
|
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::config::{Config as SerialConfig, DmaConfig as SerialDmaConfig};
|
||||||
use crate::hal::serial::Pins;
|
use crate::hal::serial::Pins;
|
||||||
use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial};
|
use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial};
|
||||||
|
|
||||||
use crate::interrupt;
|
use crate::interrupt;
|
||||||
|
|
||||||
use crate::pac::{DMA2, USART1};
|
use crate::pac::{DMA2, USART1};
|
||||||
|
|
||||||
/// Interface to the Serial peripheral
|
/// Interface to the Serial peripheral
|
||||||
|
@ -17,7 +17,7 @@ mod waker;
|
|||||||
|
|
||||||
use self::util::UninitCell;
|
use self::util::UninitCell;
|
||||||
use crate::fmt::panic;
|
use crate::fmt::panic;
|
||||||
use crate::interrupt::Interrupt;
|
use crate::interrupt::{Interrupt, InterruptExt};
|
||||||
use crate::time::Alarm;
|
use crate::time::Alarm;
|
||||||
|
|
||||||
// repr(C) is needed to guarantee that the raw::Task is located at offset 0
|
// repr(C) is needed to guarantee that the raw::Task is located at offset 0
|
||||||
|
@ -37,7 +37,24 @@ pub unsafe trait Interrupt {
|
|||||||
/// Implementation detail, do not use outside embassy crates.
|
/// Implementation detail, do not use outside embassy crates.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
unsafe fn __handler(&self) -> &'static Handler;
|
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 ())) {
|
fn set_handler(&self, func: unsafe fn(*mut ())) {
|
||||||
let handler = unsafe { self.__handler() };
|
let handler = unsafe { self.__handler() };
|
||||||
handler.func.store(func as *mut (), Ordering::Release);
|
handler.func.store(func as *mut (), Ordering::Release);
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
use crate::executor;
|
|
||||||
use crate::fmt::panic;
|
|
||||||
use crate::interrupt::Interrupt;
|
|
||||||
use core::cell::UnsafeCell;
|
use core::cell::UnsafeCell;
|
||||||
use core::future::Future;
|
use core::future::Future;
|
||||||
use core::mem;
|
use core::mem;
|
||||||
@ -9,6 +6,10 @@ use core::task::{Context, Poll, Waker};
|
|||||||
use cortex_m::peripheral::NVIC;
|
use cortex_m::peripheral::NVIC;
|
||||||
use cortex_m::peripheral::{scb, SCB};
|
use cortex_m::peripheral::{scb, SCB};
|
||||||
|
|
||||||
|
use crate::executor;
|
||||||
|
use crate::fmt::panic;
|
||||||
|
use crate::interrupt::{Interrupt, InterruptExt};
|
||||||
|
|
||||||
pub struct Signal<T> {
|
pub struct Signal<T> {
|
||||||
state: UnsafeCell<State<T>>,
|
state: UnsafeCell<State<T>>,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user