diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-03-01 00:56:20 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-03-01 00:56:20 +0100 |
| commit | 67a6c4f4692db140f9aa27a920266d70857c06f6 (patch) | |
| tree | ee62833be88a5eba0f37e6ade3bbbd3e6ec2a376 | |
| parent | 282f00e7050653e98b4c0680b54fce8abc43a5a3 (diff) | |
| parent | 45355f184a8397730a3bd04a0abbebc685af63fe (diff) | |
Merge pull request #59 from akiles/interrupt_ext
move most interrupt methods to InterruptExt extension trait. Fixes #35
| -rw-r--r-- | embassy-nrf-examples/src/bin/multiprio.rs | 2 | ||||
| -rw-r--r-- | embassy-nrf/src/buffered_uarte.rs | 1 | ||||
| -rw-r--r-- | embassy-nrf/src/gpiote.rs | 2 | ||||
| -rw-r--r-- | embassy-nrf/src/rtc.rs | 1 | ||||
| -rw-r--r-- | embassy-nrf/src/uarte.rs | 1 | ||||
| -rw-r--r-- | embassy-nrf/src/util/peripheral.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32f4/src/rtc.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32f4/src/serial.rs | 4 | ||||
| -rw-r--r-- | embassy/src/executor/mod.rs | 2 | ||||
| -rw-r--r-- | embassy/src/interrupt.rs | 17 | ||||
| -rw-r--r-- | embassy/src/util/signal.rs | 7 |
11 files changed, 33 insertions, 11 deletions
diff --git a/embassy-nrf-examples/src/bin/multiprio.rs b/embassy-nrf-examples/src/bin/multiprio.rs index 850ef8fc0..d652633ab 100644 --- a/embassy-nrf-examples/src/bin/multiprio.rs +++ b/embassy-nrf-examples/src/bin/multiprio.rs | |||
| @@ -66,9 +66,9 @@ use defmt::panic; | |||
| 66 | use nrf52840_hal::clocks; | 66 | use nrf52840_hal::clocks; |
| 67 | 67 | ||
| 68 | use embassy::executor::{task, Executor, IrqExecutor}; | 68 | use embassy::executor::{task, Executor, IrqExecutor}; |
| 69 | use embassy::interrupt::InterruptExt; | ||
| 69 | use embassy::time::{Duration, Instant, Timer}; | 70 | use embassy::time::{Duration, Instant, Timer}; |
| 70 | use embassy::util::Forever; | 71 | use embassy::util::Forever; |
| 71 | use embassy_nrf::interrupt::Interrupt; | ||
| 72 | use embassy_nrf::{interrupt, pac, rtc}; | 72 | use embassy_nrf::{interrupt, pac, rtc}; |
| 73 | 73 | ||
| 74 | #[task] | 74 | #[task] |
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index 26a40507b..5cbba486e 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs | |||
| @@ -10,6 +10,7 @@ use core::ops::Deref; | |||
| 10 | use core::pin::Pin; | 10 | use core::pin::Pin; |
| 11 | use core::sync::atomic::{compiler_fence, Ordering}; | 11 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 12 | use core::task::{Context, Poll}; | 12 | use core::task::{Context, Poll}; |
| 13 | use embassy::interrupt::InterruptExt; | ||
| 13 | use embassy::io::{AsyncBufRead, AsyncWrite, Result}; | 14 | use embassy::io::{AsyncBufRead, AsyncWrite, Result}; |
| 14 | use embassy::util::WakerRegistration; | 15 | use embassy::util::WakerRegistration; |
| 15 | use embedded_hal::digital::v2::OutputPin; | 16 | use embedded_hal::digital::v2::OutputPin; |
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index 01e61bd5c..78bb2aeb6 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs | |||
| @@ -5,11 +5,11 @@ use core::pin::Pin; | |||
| 5 | use core::ptr; | 5 | use core::ptr; |
| 6 | use core::task::{Context, Poll}; | 6 | use core::task::{Context, Poll}; |
| 7 | use embassy::gpio::{WaitForHigh, WaitForLow}; | 7 | use embassy::gpio::{WaitForHigh, WaitForLow}; |
| 8 | use embassy::interrupt::InterruptExt; | ||
| 8 | use embassy::util::Signal; | 9 | use embassy::util::Signal; |
| 9 | 10 | ||
| 10 | use crate::hal::gpio::{Input, Level, Output, Pin as GpioPin, Port}; | 11 | use crate::hal::gpio::{Input, Level, Output, Pin as GpioPin, Port}; |
| 11 | use crate::interrupt; | 12 | use crate::interrupt; |
| 12 | use crate::interrupt::Interrupt; | ||
| 13 | use crate::pac; | 13 | use crate::pac; |
| 14 | use crate::pac::generic::Reg; | 14 | use crate::pac::generic::Reg; |
| 15 | use crate::pac::gpiote::_TASKS_OUT; | 15 | use crate::pac::gpiote::_TASKS_OUT; |
diff --git a/embassy-nrf/src/rtc.rs b/embassy-nrf/src/rtc.rs index 7a79580cc..e0e645fe8 100644 --- a/embassy-nrf/src/rtc.rs +++ b/embassy-nrf/src/rtc.rs | |||
| @@ -2,6 +2,7 @@ use core::cell::Cell; | |||
| 2 | use core::ops::Deref; | 2 | use core::ops::Deref; |
| 3 | use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; | 3 | use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; |
| 4 | 4 | ||
| 5 | use embassy::interrupt::InterruptExt; | ||
| 5 | use embassy::time::Clock; | 6 | use embassy::time::Clock; |
| 6 | 7 | ||
| 7 | use crate::interrupt; | 8 | use crate::interrupt; |
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 07718a1dd..9d5ff81aa 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -9,6 +9,7 @@ use core::ops::Deref; | |||
| 9 | use core::sync::atomic::{compiler_fence, Ordering}; | 9 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 10 | use core::task::{Context, Poll}; | 10 | use core::task::{Context, Poll}; |
| 11 | 11 | ||
| 12 | use embassy::interrupt::InterruptExt; | ||
| 12 | use embassy::util::Signal; | 13 | use embassy::util::Signal; |
| 13 | 14 | ||
| 14 | use crate::fmt::{assert, *}; | 15 | use crate::fmt::{assert, *}; |
diff --git a/embassy-nrf/src/util/peripheral.rs b/embassy-nrf/src/util/peripheral.rs index bfb023f56..bb88f0820 100644 --- a/embassy-nrf/src/util/peripheral.rs +++ b/embassy-nrf/src/util/peripheral.rs | |||
| @@ -4,6 +4,8 @@ use core::mem::MaybeUninit; | |||
| 4 | use core::pin::Pin; | 4 | use core::pin::Pin; |
| 5 | use core::sync::atomic::{compiler_fence, Ordering}; | 5 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 6 | 6 | ||
| 7 | use embassy::interrupt::InterruptExt; | ||
| 8 | |||
| 7 | use crate::fmt::{assert, *}; | 9 | use crate::fmt::{assert, *}; |
| 8 | use crate::interrupt::Interrupt; | 10 | use crate::interrupt::Interrupt; |
| 9 | 11 | ||
diff --git a/embassy-stm32f4/src/rtc.rs b/embassy-stm32f4/src/rtc.rs index 21589f5d6..824a47072 100644 --- a/embassy-stm32f4/src/rtc.rs +++ b/embassy-stm32f4/src/rtc.rs | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | use core::cell::Cell; | 1 | use core::cell::Cell; |
| 2 | use core::convert::TryInto; | 2 | use core::convert::TryInto; |
| 3 | use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; | 3 | use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; |
| 4 | |||
| 5 | use embassy::time::{Clock, TICKS_PER_SECOND}; | ||
| 6 | use stm32f4xx_hal::bb; | 4 | use stm32f4xx_hal::bb; |
| 7 | use stm32f4xx_hal::rcc::Clocks; | 5 | use stm32f4xx_hal::rcc::Clocks; |
| 8 | 6 | ||
| 7 | use embassy::interrupt::InterruptExt; | ||
| 8 | use embassy::time::{Clock, TICKS_PER_SECOND}; | ||
| 9 | |||
| 9 | use crate::interrupt; | 10 | use crate::interrupt; |
| 10 | use crate::interrupt::{CriticalSection, Interrupt, Mutex}; | 11 | use crate::interrupt::{CriticalSection, Interrupt, Mutex}; |
| 11 | 12 | ||
diff --git a/embassy-stm32f4/src/serial.rs b/embassy-stm32f4/src/serial.rs index 669d7856c..8f594ca13 100644 --- a/embassy-stm32f4/src/serial.rs +++ b/embassy-stm32f4/src/serial.rs | |||
| @@ -8,7 +8,7 @@ use core::future::Future; | |||
| 8 | use core::ptr; | 8 | use core::ptr; |
| 9 | use core::sync::atomic::{self, Ordering}; | 9 | use core::sync::atomic::{self, Ordering}; |
| 10 | 10 | ||
| 11 | use embassy::interrupt::Interrupt; | 11 | use embassy::interrupt::InterruptExt; |
| 12 | use embassy::uart::{Error, Uart}; | 12 | use embassy::uart::{Error, Uart}; |
| 13 | use embassy::util::Signal; | 13 | use embassy::util::Signal; |
| 14 | 14 | ||
| @@ -19,9 +19,7 @@ use crate::hal::rcc::Clocks; | |||
| 19 | use crate::hal::serial::config::{Config as SerialConfig, DmaConfig as SerialDmaConfig}; | 19 | use crate::hal::serial::config::{Config as SerialConfig, DmaConfig as SerialDmaConfig}; |
| 20 | use crate::hal::serial::Pins; | 20 | use crate::hal::serial::Pins; |
| 21 | use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial}; | 21 | use crate::hal::serial::{Event as SerialEvent, Serial as HalSerial}; |
| 22 | |||
| 23 | use crate::interrupt; | 22 | use crate::interrupt; |
| 24 | |||
| 25 | use crate::pac::{DMA2, USART1}; | 23 | use crate::pac::{DMA2, USART1}; |
| 26 | 24 | ||
| 27 | /// Interface to the Serial peripheral | 25 | /// Interface to the Serial peripheral |
diff --git a/embassy/src/executor/mod.rs b/embassy/src/executor/mod.rs index be0d1b9e7..5f016f703 100644 --- a/embassy/src/executor/mod.rs +++ b/embassy/src/executor/mod.rs | |||
| @@ -17,7 +17,7 @@ mod waker; | |||
| 17 | 17 | ||
| 18 | use self::util::UninitCell; | 18 | use self::util::UninitCell; |
| 19 | use crate::fmt::panic; | 19 | use crate::fmt::panic; |
| 20 | use crate::interrupt::Interrupt; | 20 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 21 | use crate::time::Alarm; | 21 | use crate::time::Alarm; |
| 22 | 22 | ||
| 23 | // repr(C) is needed to guarantee that the raw::Task is located at offset 0 | 23 | // repr(C) is needed to guarantee that the raw::Task is located at offset 0 |
diff --git a/embassy/src/interrupt.rs b/embassy/src/interrupt.rs index 53413d41d..ba25ec8ec 100644 --- a/embassy/src/interrupt.rs +++ b/embassy/src/interrupt.rs | |||
| @@ -37,7 +37,24 @@ pub unsafe trait Interrupt { | |||
| 37 | /// Implementation detail, do not use outside embassy crates. | 37 | /// Implementation detail, do not use outside embassy crates. |
| 38 | #[doc(hidden)] | 38 | #[doc(hidden)] |
| 39 | unsafe fn __handler(&self) -> &'static Handler; | 39 | unsafe fn __handler(&self) -> &'static Handler; |
| 40 | } | ||
| 41 | |||
| 42 | pub trait InterruptExt: Interrupt { | ||
| 43 | fn set_handler(&self, func: unsafe fn(*mut ())); | ||
| 44 | fn remove_handler(&self); | ||
| 45 | fn set_handler_context(&self, ctx: *mut ()); | ||
| 46 | fn enable(&self); | ||
| 47 | fn disable(&self); | ||
| 48 | fn is_active(&self) -> bool; | ||
| 49 | fn is_enabled(&self) -> bool; | ||
| 50 | fn is_pending(&self) -> bool; | ||
| 51 | fn pend(&self); | ||
| 52 | fn unpend(&self); | ||
| 53 | fn get_priority(&self) -> Self::Priority; | ||
| 54 | fn set_priority(&self, prio: Self::Priority); | ||
| 55 | } | ||
| 40 | 56 | ||
| 57 | impl<T: Interrupt + ?Sized> InterruptExt for T { | ||
| 41 | fn set_handler(&self, func: unsafe fn(*mut ())) { | 58 | fn set_handler(&self, func: unsafe fn(*mut ())) { |
| 42 | let handler = unsafe { self.__handler() }; | 59 | let handler = unsafe { self.__handler() }; |
| 43 | handler.func.store(func as *mut (), Ordering::Release); | 60 | handler.func.store(func as *mut (), Ordering::Release); |
diff --git a/embassy/src/util/signal.rs b/embassy/src/util/signal.rs index 0abcc75f3..41e27d4ca 100644 --- a/embassy/src/util/signal.rs +++ b/embassy/src/util/signal.rs | |||
| @@ -1,6 +1,3 @@ | |||
| 1 | use crate::executor; | ||
| 2 | use crate::fmt::panic; | ||
| 3 | use crate::interrupt::Interrupt; | ||
| 4 | use core::cell::UnsafeCell; | 1 | use core::cell::UnsafeCell; |
| 5 | use core::future::Future; | 2 | use core::future::Future; |
| 6 | use core::mem; | 3 | use core::mem; |
| @@ -9,6 +6,10 @@ use core::task::{Context, Poll, Waker}; | |||
| 9 | use cortex_m::peripheral::NVIC; | 6 | use cortex_m::peripheral::NVIC; |
| 10 | use cortex_m::peripheral::{scb, SCB}; | 7 | use cortex_m::peripheral::{scb, SCB}; |
| 11 | 8 | ||
| 9 | use crate::executor; | ||
| 10 | use crate::fmt::panic; | ||
| 11 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 12 | |||
| 12 | pub struct Signal<T> { | 13 | pub struct Signal<T> { |
| 13 | state: UnsafeCell<State<T>>, | 14 | state: UnsafeCell<State<T>>, |
| 14 | } | 15 | } |
