diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-06-11 05:08:57 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-06-12 21:45:38 +0200 |
| commit | 5085100df2845745f13715669c18a785a374a879 (patch) | |
| tree | d24d264b23753d628e58fa3b92da77a78e28ce35 | |
| parent | db344c2bda55bd0352a43720788185cc4d3a420e (diff) | |
Add embassy-cortex-m crate.
- Move Interrupt and InterruptExecutor from `embassy` to `embassy-cortex-m`.
- Move Unborrow from `embassy` to `embassy-hal-common` (nothing in `embassy` requires it anymore)
- Move PeripheralMutex from `embassy-hal-common` to `embassy-cortex-m`.
104 files changed, 809 insertions, 455 deletions
diff --git a/embassy-cortex-m/Cargo.toml b/embassy-cortex-m/Cargo.toml new file mode 100644 index 000000000..8bd30403e --- /dev/null +++ b/embassy-cortex-m/Cargo.toml | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | [package] | ||
| 2 | name = "embassy-cortex-m" | ||
| 3 | version = "0.1.0" | ||
| 4 | authors = ["Dario Nieuwenhuis <[email protected]>"] | ||
| 5 | edition = "2018" | ||
| 6 | resolver = "2" | ||
| 7 | |||
| 8 | [package.metadata.embassy_docs] | ||
| 9 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-cortex-m-v$VERSION/embassy-cortex-m/src/" | ||
| 10 | src_base_git = "https://github.com/embassy-rs/embassy/blob/master/embassy-cortex-m/src/" | ||
| 11 | features = [] | ||
| 12 | flavors = [ | ||
| 13 | { name = "thumbv6m-none-eabi", target = "thumbv6m-none-eabi", features = [] }, | ||
| 14 | { name = "thumbv7m-none-eabi", target = "thumbv7m-none-eabi", features = [] }, | ||
| 15 | { name = "thumbv7em-none-eabi", target = "thumbv7em-none-eabi", features = [] }, | ||
| 16 | { name = "thumbv7em-none-eabihf", target = "thumbv7em-none-eabihf", features = [] }, | ||
| 17 | { name = "thumbv8m.base-none-eabi", target = "thumbv8m.base-none-eabi", features = [] }, | ||
| 18 | { name = "thumbv8m.main-none-eabi", target = "thumbv8m.main-none-eabi", features = [] }, | ||
| 19 | { name = "thumbv8m.main-none-eabihf", target = "thumbv8m.main-none-eabihf", features = [] }, | ||
| 20 | ] | ||
| 21 | |||
| 22 | [features] | ||
| 23 | default = [] | ||
| 24 | |||
| 25 | # Define the number of NVIC priority bits. | ||
| 26 | prio-bits-0 = [] | ||
| 27 | prio-bits-1 = [] | ||
| 28 | prio-bits-2 = [] | ||
| 29 | prio-bits-3 = [] | ||
| 30 | prio-bits-4 = [] | ||
| 31 | prio-bits-5 = [] | ||
| 32 | prio-bits-6 = [] | ||
| 33 | prio-bits-7 = [] | ||
| 34 | prio-bits-8 = [] | ||
| 35 | |||
| 36 | [dependencies] | ||
| 37 | defmt = { version = "0.3", optional = true } | ||
| 38 | log = { version = "0.4.14", optional = true } | ||
| 39 | |||
| 40 | embassy = { version = "0.1.0", path = "../embassy"} | ||
| 41 | embassy-macros = { version = "0.1.0", path = "../embassy-macros"} | ||
| 42 | embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common"} | ||
| 43 | atomic-polyfill = "0.1.5" | ||
| 44 | critical-section = "0.2.5" | ||
| 45 | cfg-if = "1.0.0" | ||
| 46 | cortex-m = "0.7.3" | ||
| 47 | |||
diff --git a/embassy-cortex-m/build.rs b/embassy-cortex-m/build.rs new file mode 100644 index 000000000..6fe82b44f --- /dev/null +++ b/embassy-cortex-m/build.rs | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | use std::env; | ||
| 2 | |||
| 3 | fn main() { | ||
| 4 | let target = env::var("TARGET").unwrap(); | ||
| 5 | |||
| 6 | if target.starts_with("thumbv6m-") { | ||
| 7 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 8 | println!("cargo:rustc-cfg=armv6m"); | ||
| 9 | } else if target.starts_with("thumbv7m-") { | ||
| 10 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 11 | println!("cargo:rustc-cfg=armv7m"); | ||
| 12 | } else if target.starts_with("thumbv7em-") { | ||
| 13 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 14 | println!("cargo:rustc-cfg=armv7m"); | ||
| 15 | println!("cargo:rustc-cfg=armv7em"); // (not currently used) | ||
| 16 | } else if target.starts_with("thumbv8m.base") { | ||
| 17 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 18 | println!("cargo:rustc-cfg=armv8m"); | ||
| 19 | println!("cargo:rustc-cfg=armv8m_base"); | ||
| 20 | } else if target.starts_with("thumbv8m.main") { | ||
| 21 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 22 | println!("cargo:rustc-cfg=armv8m"); | ||
| 23 | println!("cargo:rustc-cfg=armv8m_main"); | ||
| 24 | } | ||
| 25 | |||
| 26 | if target.ends_with("-eabihf") { | ||
| 27 | println!("cargo:rustc-cfg=has_fpu"); | ||
| 28 | } | ||
| 29 | } | ||
diff --git a/embassy-cortex-m/src/executor.rs b/embassy-cortex-m/src/executor.rs new file mode 100644 index 000000000..63a1519cf --- /dev/null +++ b/embassy-cortex-m/src/executor.rs | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | use core::marker::PhantomData; | ||
| 2 | |||
| 3 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 4 | use embassy::executor::{raw, SendSpawner}; | ||
| 5 | |||
| 6 | pub use embassy::executor::Executor; | ||
| 7 | |||
| 8 | fn pend_by_number(n: u16) { | ||
| 9 | #[derive(Clone, Copy)] | ||
| 10 | struct N(u16); | ||
| 11 | unsafe impl cortex_m::interrupt::InterruptNumber for N { | ||
| 12 | fn number(self) -> u16 { | ||
| 13 | self.0 | ||
| 14 | } | ||
| 15 | } | ||
| 16 | cortex_m::peripheral::NVIC::pend(N(n)) | ||
| 17 | } | ||
| 18 | |||
| 19 | /// Interrupt mode executor. | ||
| 20 | /// | ||
| 21 | /// This executor runs tasks in interrupt mode. The interrupt handler is set up | ||
| 22 | /// to poll tasks, and when a task is woken the interrupt is pended from software. | ||
| 23 | /// | ||
| 24 | /// This allows running async tasks at a priority higher than thread mode. One | ||
| 25 | /// use case is to leave thread mode free for non-async tasks. Another use case is | ||
| 26 | /// to run multiple executors: one in thread mode for low priority tasks and another in | ||
| 27 | /// interrupt mode for higher priority tasks. Higher priority tasks will preempt lower | ||
| 28 | /// priority ones. | ||
| 29 | /// | ||
| 30 | /// It is even possible to run multiple interrupt mode executors at different priorities, | ||
| 31 | /// by assigning different priorities to the interrupts. For an example on how to do this, | ||
| 32 | /// See the 'multiprio' example for 'embassy-nrf'. | ||
| 33 | /// | ||
| 34 | /// To use it, you have to pick an interrupt that won't be used by the hardware. | ||
| 35 | /// Some chips reserve some interrupts for this purpose, sometimes named "software interrupts" (SWI). | ||
| 36 | /// If this is not the case, you may use an interrupt from any unused peripheral. | ||
| 37 | /// | ||
| 38 | /// It is somewhat more complex to use, it's recommended to use the thread-mode | ||
| 39 | /// [`Executor`] instead, if it works for your use case. | ||
| 40 | pub struct InterruptExecutor<I: Interrupt> { | ||
| 41 | irq: I, | ||
| 42 | inner: raw::Executor, | ||
| 43 | not_send: PhantomData<*mut ()>, | ||
| 44 | } | ||
| 45 | |||
| 46 | impl<I: Interrupt> InterruptExecutor<I> { | ||
| 47 | /// Create a new Executor. | ||
| 48 | pub fn new(irq: I) -> Self { | ||
| 49 | let ctx = irq.number() as *mut (); | ||
| 50 | Self { | ||
| 51 | irq, | ||
| 52 | inner: raw::Executor::new(|ctx| pend_by_number(ctx as u16), ctx), | ||
| 53 | not_send: PhantomData, | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | /// Start the executor. | ||
| 58 | /// | ||
| 59 | /// This initializes the executor, configures and enables the interrupt, and returns. | ||
| 60 | /// The executor keeps running in the background through the interrupt. | ||
| 61 | /// | ||
| 62 | /// This returns a [`SendSpawner`] you can use to spawn tasks on it. A [`SendSpawner`] | ||
| 63 | /// is returned instead of a [`Spawner`] because the executor effectively runs in a | ||
| 64 | /// different "thread" (the interrupt), so spawning tasks on it is effectively | ||
| 65 | /// sending them. | ||
| 66 | /// | ||
| 67 | /// To obtain a [`Spawner`] for this executor, use [`Spawner::for_current_executor`] from | ||
| 68 | /// a task running in it. | ||
| 69 | /// | ||
| 70 | /// This function requires `&'static mut self`. This means you have to store the | ||
| 71 | /// Executor instance in a place where it'll live forever and grants you mutable | ||
| 72 | /// access. There's a few ways to do this: | ||
| 73 | /// | ||
| 74 | /// - a [Forever](crate::util::Forever) (safe) | ||
| 75 | /// - a `static mut` (unsafe) | ||
| 76 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) | ||
| 77 | pub fn start(&'static mut self) -> SendSpawner { | ||
| 78 | self.irq.disable(); | ||
| 79 | |||
| 80 | self.irq.set_handler(|ctx| unsafe { | ||
| 81 | let executor = &*(ctx as *const raw::Executor); | ||
| 82 | executor.poll(); | ||
| 83 | }); | ||
| 84 | self.irq.set_handler_context(&self.inner as *const _ as _); | ||
| 85 | self.irq.enable(); | ||
| 86 | |||
| 87 | self.inner.spawner().make_send() | ||
| 88 | } | ||
| 89 | } | ||
diff --git a/embassy-cortex-m/src/fmt.rs b/embassy-cortex-m/src/fmt.rs new file mode 100644 index 000000000..f8bb0a035 --- /dev/null +++ b/embassy-cortex-m/src/fmt.rs | |||
| @@ -0,0 +1,228 @@ | |||
| 1 | #![macro_use] | ||
| 2 | #![allow(unused_macros)] | ||
| 3 | |||
| 4 | #[cfg(all(feature = "defmt", feature = "log"))] | ||
| 5 | compile_error!("You may not enable both `defmt` and `log` features."); | ||
| 6 | |||
| 7 | macro_rules! assert { | ||
| 8 | ($($x:tt)*) => { | ||
| 9 | { | ||
| 10 | #[cfg(not(feature = "defmt"))] | ||
| 11 | ::core::assert!($($x)*); | ||
| 12 | #[cfg(feature = "defmt")] | ||
| 13 | ::defmt::assert!($($x)*); | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | } | ||
| 17 | |||
| 18 | macro_rules! assert_eq { | ||
| 19 | ($($x:tt)*) => { | ||
| 20 | { | ||
| 21 | #[cfg(not(feature = "defmt"))] | ||
| 22 | ::core::assert_eq!($($x)*); | ||
| 23 | #[cfg(feature = "defmt")] | ||
| 24 | ::defmt::assert_eq!($($x)*); | ||
| 25 | } | ||
| 26 | }; | ||
| 27 | } | ||
| 28 | |||
| 29 | macro_rules! assert_ne { | ||
| 30 | ($($x:tt)*) => { | ||
| 31 | { | ||
| 32 | #[cfg(not(feature = "defmt"))] | ||
| 33 | ::core::assert_ne!($($x)*); | ||
| 34 | #[cfg(feature = "defmt")] | ||
| 35 | ::defmt::assert_ne!($($x)*); | ||
| 36 | } | ||
| 37 | }; | ||
| 38 | } | ||
| 39 | |||
| 40 | macro_rules! debug_assert { | ||
| 41 | ($($x:tt)*) => { | ||
| 42 | { | ||
| 43 | #[cfg(not(feature = "defmt"))] | ||
| 44 | ::core::debug_assert!($($x)*); | ||
| 45 | #[cfg(feature = "defmt")] | ||
| 46 | ::defmt::debug_assert!($($x)*); | ||
| 47 | } | ||
| 48 | }; | ||
| 49 | } | ||
| 50 | |||
| 51 | macro_rules! debug_assert_eq { | ||
| 52 | ($($x:tt)*) => { | ||
| 53 | { | ||
| 54 | #[cfg(not(feature = "defmt"))] | ||
| 55 | ::core::debug_assert_eq!($($x)*); | ||
| 56 | #[cfg(feature = "defmt")] | ||
| 57 | ::defmt::debug_assert_eq!($($x)*); | ||
| 58 | } | ||
| 59 | }; | ||
| 60 | } | ||
| 61 | |||
| 62 | macro_rules! debug_assert_ne { | ||
| 63 | ($($x:tt)*) => { | ||
| 64 | { | ||
| 65 | #[cfg(not(feature = "defmt"))] | ||
| 66 | ::core::debug_assert_ne!($($x)*); | ||
| 67 | #[cfg(feature = "defmt")] | ||
| 68 | ::defmt::debug_assert_ne!($($x)*); | ||
| 69 | } | ||
| 70 | }; | ||
| 71 | } | ||
| 72 | |||
| 73 | macro_rules! todo { | ||
| 74 | ($($x:tt)*) => { | ||
| 75 | { | ||
| 76 | #[cfg(not(feature = "defmt"))] | ||
| 77 | ::core::todo!($($x)*); | ||
| 78 | #[cfg(feature = "defmt")] | ||
| 79 | ::defmt::todo!($($x)*); | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | } | ||
| 83 | |||
| 84 | macro_rules! unreachable { | ||
| 85 | ($($x:tt)*) => { | ||
| 86 | { | ||
| 87 | #[cfg(not(feature = "defmt"))] | ||
| 88 | ::core::unreachable!($($x)*); | ||
| 89 | #[cfg(feature = "defmt")] | ||
| 90 | ::defmt::unreachable!($($x)*); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
| 94 | |||
| 95 | macro_rules! panic { | ||
| 96 | ($($x:tt)*) => { | ||
| 97 | { | ||
| 98 | #[cfg(not(feature = "defmt"))] | ||
| 99 | ::core::panic!($($x)*); | ||
| 100 | #[cfg(feature = "defmt")] | ||
| 101 | ::defmt::panic!($($x)*); | ||
| 102 | } | ||
| 103 | }; | ||
| 104 | } | ||
| 105 | |||
| 106 | macro_rules! trace { | ||
| 107 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 108 | { | ||
| 109 | #[cfg(feature = "log")] | ||
| 110 | ::log::trace!($s $(, $x)*); | ||
| 111 | #[cfg(feature = "defmt")] | ||
| 112 | ::defmt::trace!($s $(, $x)*); | ||
| 113 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 114 | let _ = ($( & $x ),*); | ||
| 115 | } | ||
| 116 | }; | ||
| 117 | } | ||
| 118 | |||
| 119 | macro_rules! debug { | ||
| 120 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 121 | { | ||
| 122 | #[cfg(feature = "log")] | ||
| 123 | ::log::debug!($s $(, $x)*); | ||
| 124 | #[cfg(feature = "defmt")] | ||
| 125 | ::defmt::debug!($s $(, $x)*); | ||
| 126 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 127 | let _ = ($( & $x ),*); | ||
| 128 | } | ||
| 129 | }; | ||
| 130 | } | ||
| 131 | |||
| 132 | macro_rules! info { | ||
| 133 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 134 | { | ||
| 135 | #[cfg(feature = "log")] | ||
| 136 | ::log::info!($s $(, $x)*); | ||
| 137 | #[cfg(feature = "defmt")] | ||
| 138 | ::defmt::info!($s $(, $x)*); | ||
| 139 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 140 | let _ = ($( & $x ),*); | ||
| 141 | } | ||
| 142 | }; | ||
| 143 | } | ||
| 144 | |||
| 145 | macro_rules! warn { | ||
| 146 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 147 | { | ||
| 148 | #[cfg(feature = "log")] | ||
| 149 | ::log::warn!($s $(, $x)*); | ||
| 150 | #[cfg(feature = "defmt")] | ||
| 151 | ::defmt::warn!($s $(, $x)*); | ||
| 152 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 153 | let _ = ($( & $x ),*); | ||
| 154 | } | ||
| 155 | }; | ||
| 156 | } | ||
| 157 | |||
| 158 | macro_rules! error { | ||
| 159 | ($s:literal $(, $x:expr)* $(,)?) => { | ||
| 160 | { | ||
| 161 | #[cfg(feature = "log")] | ||
| 162 | ::log::error!($s $(, $x)*); | ||
| 163 | #[cfg(feature = "defmt")] | ||
| 164 | ::defmt::error!($s $(, $x)*); | ||
| 165 | #[cfg(not(any(feature = "log", feature="defmt")))] | ||
| 166 | let _ = ($( & $x ),*); | ||
| 167 | } | ||
| 168 | }; | ||
| 169 | } | ||
| 170 | |||
| 171 | #[cfg(feature = "defmt")] | ||
| 172 | macro_rules! unwrap { | ||
| 173 | ($($x:tt)*) => { | ||
| 174 | ::defmt::unwrap!($($x)*) | ||
| 175 | }; | ||
| 176 | } | ||
| 177 | |||
| 178 | #[cfg(not(feature = "defmt"))] | ||
| 179 | macro_rules! unwrap { | ||
| 180 | ($arg:expr) => { | ||
| 181 | match $crate::fmt::Try::into_result($arg) { | ||
| 182 | ::core::result::Result::Ok(t) => t, | ||
| 183 | ::core::result::Result::Err(e) => { | ||
| 184 | ::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e); | ||
| 185 | } | ||
| 186 | } | ||
| 187 | }; | ||
| 188 | ($arg:expr, $($msg:expr),+ $(,)? ) => { | ||
| 189 | match $crate::fmt::Try::into_result($arg) { | ||
| 190 | ::core::result::Result::Ok(t) => t, | ||
| 191 | ::core::result::Result::Err(e) => { | ||
| 192 | ::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e); | ||
| 193 | } | ||
| 194 | } | ||
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 198 | #[cfg(feature = "defmt-timestamp-uptime")] | ||
| 199 | defmt::timestamp! {"{=u64:us}", crate::time::Instant::now().as_micros() } | ||
| 200 | |||
| 201 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | ||
| 202 | pub struct NoneError; | ||
| 203 | |||
| 204 | pub trait Try { | ||
| 205 | type Ok; | ||
| 206 | type Error; | ||
| 207 | fn into_result(self) -> Result<Self::Ok, Self::Error>; | ||
| 208 | } | ||
| 209 | |||
| 210 | impl<T> Try for Option<T> { | ||
| 211 | type Ok = T; | ||
| 212 | type Error = NoneError; | ||
| 213 | |||
| 214 | #[inline] | ||
| 215 | fn into_result(self) -> Result<T, NoneError> { | ||
| 216 | self.ok_or(NoneError) | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | impl<T, E> Try for Result<T, E> { | ||
| 221 | type Ok = T; | ||
| 222 | type Error = E; | ||
| 223 | |||
| 224 | #[inline] | ||
| 225 | fn into_result(self) -> Self { | ||
| 226 | self | ||
| 227 | } | ||
| 228 | } | ||
diff --git a/embassy-hal-common/src/interrupt.rs b/embassy-cortex-m/src/interrupt.rs index 80b2cad5d..df2aad0ec 100644 --- a/embassy-hal-common/src/interrupt.rs +++ b/embassy-cortex-m/src/interrupt.rs | |||
| @@ -1,49 +1,198 @@ | |||
| 1 | use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; | ||
| 1 | use core::mem; | 2 | use core::mem; |
| 3 | use core::ptr; | ||
| 4 | use cortex_m::peripheral::NVIC; | ||
| 5 | use embassy_hal_common::Unborrow; | ||
| 2 | 6 | ||
| 3 | macro_rules! prio { | 7 | pub use embassy_macros::cortex_m_interrupt_take as take; |
| 4 | ($name:ident, $mask:expr, ($($k:ident = $v:expr,)*)) => { | 8 | |
| 5 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] | 9 | /// Implementation detail, do not use outside embassy crates. |
| 6 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 10 | #[doc(hidden)] |
| 7 | #[repr(u8)] | 11 | pub struct Handler { |
| 8 | pub enum $name { | 12 | pub func: AtomicPtr<()>, |
| 9 | $($k = $v),* | 13 | pub ctx: AtomicPtr<()>, |
| 14 | } | ||
| 15 | |||
| 16 | impl Handler { | ||
| 17 | pub const fn new() -> Self { | ||
| 18 | Self { | ||
| 19 | func: AtomicPtr::new(ptr::null_mut()), | ||
| 20 | ctx: AtomicPtr::new(ptr::null_mut()), | ||
| 10 | } | 21 | } |
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | #[derive(Clone, Copy)] | ||
| 26 | pub(crate) struct NrWrap(pub(crate) u16); | ||
| 27 | unsafe impl cortex_m::interrupt::InterruptNumber for NrWrap { | ||
| 28 | fn number(self) -> u16 { | ||
| 29 | self.0 | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | pub unsafe trait Interrupt: Unborrow<Target = Self> { | ||
| 34 | fn number(&self) -> u16; | ||
| 35 | unsafe fn steal() -> Self; | ||
| 36 | |||
| 37 | /// Implementation detail, do not use outside embassy crates. | ||
| 38 | #[doc(hidden)] | ||
| 39 | unsafe fn __handler(&self) -> &'static Handler; | ||
| 40 | } | ||
| 11 | 41 | ||
| 12 | impl From<u8> for $name { | 42 | pub trait InterruptExt: Interrupt { |
| 13 | fn from(priority: u8) -> Self { | 43 | fn set_handler(&self, func: unsafe fn(*mut ())); |
| 14 | unsafe { mem::transmute(priority & $mask) } | 44 | fn remove_handler(&self); |
| 15 | } | 45 | fn set_handler_context(&self, ctx: *mut ()); |
| 46 | fn enable(&self); | ||
| 47 | fn disable(&self); | ||
| 48 | #[cfg(not(armv6m))] | ||
| 49 | fn is_active(&self) -> bool; | ||
| 50 | fn is_enabled(&self) -> bool; | ||
| 51 | fn is_pending(&self) -> bool; | ||
| 52 | fn pend(&self); | ||
| 53 | fn unpend(&self); | ||
| 54 | fn get_priority(&self) -> Priority; | ||
| 55 | fn set_priority(&self, prio: Priority); | ||
| 56 | } | ||
| 57 | |||
| 58 | impl<T: Interrupt + ?Sized> InterruptExt for T { | ||
| 59 | fn set_handler(&self, func: unsafe fn(*mut ())) { | ||
| 60 | compiler_fence(Ordering::SeqCst); | ||
| 61 | let handler = unsafe { self.__handler() }; | ||
| 62 | handler.func.store(func as *mut (), Ordering::Relaxed); | ||
| 63 | compiler_fence(Ordering::SeqCst); | ||
| 64 | } | ||
| 65 | |||
| 66 | fn remove_handler(&self) { | ||
| 67 | compiler_fence(Ordering::SeqCst); | ||
| 68 | let handler = unsafe { self.__handler() }; | ||
| 69 | handler.func.store(ptr::null_mut(), Ordering::Relaxed); | ||
| 70 | compiler_fence(Ordering::SeqCst); | ||
| 71 | } | ||
| 72 | |||
| 73 | fn set_handler_context(&self, ctx: *mut ()) { | ||
| 74 | let handler = unsafe { self.__handler() }; | ||
| 75 | handler.ctx.store(ctx, Ordering::Relaxed); | ||
| 76 | } | ||
| 77 | |||
| 78 | #[inline] | ||
| 79 | fn enable(&self) { | ||
| 80 | compiler_fence(Ordering::SeqCst); | ||
| 81 | unsafe { | ||
| 82 | NVIC::unmask(NrWrap(self.number())); | ||
| 16 | } | 83 | } |
| 84 | } | ||
| 85 | |||
| 86 | #[inline] | ||
| 87 | fn disable(&self) { | ||
| 88 | NVIC::mask(NrWrap(self.number())); | ||
| 89 | compiler_fence(Ordering::SeqCst); | ||
| 90 | } | ||
| 91 | |||
| 92 | #[inline] | ||
| 93 | #[cfg(not(armv6m))] | ||
| 94 | fn is_active(&self) -> bool { | ||
| 95 | NVIC::is_active(NrWrap(self.number())) | ||
| 96 | } | ||
| 97 | |||
| 98 | #[inline] | ||
| 99 | fn is_enabled(&self) -> bool { | ||
| 100 | NVIC::is_enabled(NrWrap(self.number())) | ||
| 101 | } | ||
| 102 | |||
| 103 | #[inline] | ||
| 104 | fn is_pending(&self) -> bool { | ||
| 105 | NVIC::is_pending(NrWrap(self.number())) | ||
| 106 | } | ||
| 17 | 107 | ||
| 18 | impl From<$name> for u8 { | 108 | #[inline] |
| 19 | fn from(p: $name) -> Self { | 109 | fn pend(&self) { |
| 20 | p as u8 | 110 | NVIC::pend(NrWrap(self.number())) |
| 21 | } | 111 | } |
| 112 | |||
| 113 | #[inline] | ||
| 114 | fn unpend(&self) { | ||
| 115 | NVIC::unpend(NrWrap(self.number())) | ||
| 116 | } | ||
| 117 | |||
| 118 | #[inline] | ||
| 119 | fn get_priority(&self) -> Priority { | ||
| 120 | Priority::from(NVIC::get_priority(NrWrap(self.number()))) | ||
| 121 | } | ||
| 122 | |||
| 123 | #[inline] | ||
| 124 | fn set_priority(&self, prio: Priority) { | ||
| 125 | unsafe { | ||
| 126 | let mut nvic: cortex_m::peripheral::NVIC = mem::transmute(()); | ||
| 127 | nvic.set_priority(NrWrap(self.number()), prio.into()) | ||
| 22 | } | 128 | } |
| 23 | }; | 129 | } |
| 130 | } | ||
| 131 | |||
| 132 | impl From<u8> for Priority { | ||
| 133 | fn from(priority: u8) -> Self { | ||
| 134 | unsafe { mem::transmute(priority & PRIO_MASK) } | ||
| 135 | } | ||
| 24 | } | 136 | } |
| 25 | 137 | ||
| 26 | #[rustfmt::skip] | 138 | impl From<Priority> for u8 { |
| 27 | prio!(Priority0, 0x00, ( | 139 | fn from(p: Priority) -> Self { |
| 140 | p as u8 | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | #[cfg(feature = "prio-bits-0")] | ||
| 145 | const PRIO_MASK: u8 = 0x00; | ||
| 146 | #[cfg(feature = "prio-bits-1")] | ||
| 147 | const PRIO_MASK: u8 = 0x80; | ||
| 148 | #[cfg(feature = "prio-bits-2")] | ||
| 149 | const PRIO_MASK: u8 = 0xc0; | ||
| 150 | #[cfg(feature = "prio-bits-3")] | ||
| 151 | const PRIO_MASK: u8 = 0xe0; | ||
| 152 | #[cfg(feature = "prio-bits-4")] | ||
| 153 | const PRIO_MASK: u8 = 0xf0; | ||
| 154 | #[cfg(feature = "prio-bits-5")] | ||
| 155 | const PRIO_MASK: u8 = 0xf8; | ||
| 156 | #[cfg(feature = "prio-bits-6")] | ||
| 157 | const PRIO_MASK: u8 = 0xfc; | ||
| 158 | #[cfg(feature = "prio-bits-7")] | ||
| 159 | const PRIO_MASK: u8 = 0xfe; | ||
| 160 | #[cfg(feature = "prio-bits-8")] | ||
| 161 | const PRIO_MASK: u8 = 0xff; | ||
| 162 | |||
| 163 | #[cfg(feature = "prio-bits-0")] | ||
| 164 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] | ||
| 165 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 166 | #[repr(u8)] | ||
| 167 | pub enum Priority { | ||
| 28 | P0 = 0x0, | 168 | P0 = 0x0, |
| 29 | )); | 169 | } |
| 30 | 170 | ||
| 31 | #[rustfmt::skip] | 171 | #[cfg(feature = "prio-bits-1")] |
| 32 | prio!(Priority1, 0x80, ( | 172 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
| 173 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 174 | #[repr(u8)] | ||
| 175 | pub enum Priority { | ||
| 33 | P0 = 0x0, | 176 | P0 = 0x0, |
| 34 | P1 = 0x80, | 177 | P1 = 0x80, |
| 35 | )); | 178 | } |
| 36 | 179 | ||
| 37 | #[rustfmt::skip] | 180 | #[cfg(feature = "prio-bits-2")] |
| 38 | prio!(Priority2, 0xc0, ( | 181 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
| 182 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 183 | #[repr(u8)] | ||
| 184 | pub enum Priority { | ||
| 39 | P0 = 0x0, | 185 | P0 = 0x0, |
| 40 | P1 = 0x40, | 186 | P1 = 0x40, |
| 41 | P2 = 0x80, | 187 | P2 = 0x80, |
| 42 | P3 = 0xc0, | 188 | P3 = 0xc0, |
| 43 | )); | 189 | } |
| 44 | 190 | ||
| 45 | #[rustfmt::skip] | 191 | #[cfg(feature = "prio-bits-3")] |
| 46 | prio!(Priority3, 0xe0, ( | 192 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
| 193 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 194 | #[repr(u8)] | ||
| 195 | pub enum Priority { | ||
| 47 | P0 = 0x0, | 196 | P0 = 0x0, |
| 48 | P1 = 0x20, | 197 | P1 = 0x20, |
| 49 | P2 = 0x40, | 198 | P2 = 0x40, |
| @@ -52,10 +201,13 @@ prio!(Priority3, 0xe0, ( | |||
| 52 | P5 = 0xa0, | 201 | P5 = 0xa0, |
| 53 | P6 = 0xc0, | 202 | P6 = 0xc0, |
| 54 | P7 = 0xe0, | 203 | P7 = 0xe0, |
| 55 | )); | 204 | } |
| 56 | 205 | ||
| 57 | #[rustfmt::skip] | 206 | #[cfg(feature = "prio-bits-4")] |
| 58 | prio!(Priority4, 0xf0, ( | 207 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
| 208 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 209 | #[repr(u8)] | ||
| 210 | pub enum Priority { | ||
| 59 | P0 = 0x0, | 211 | P0 = 0x0, |
| 60 | P1 = 0x10, | 212 | P1 = 0x10, |
| 61 | P2 = 0x20, | 213 | P2 = 0x20, |
| @@ -72,10 +224,13 @@ prio!(Priority4, 0xf0, ( | |||
| 72 | P13 = 0xd0, | 224 | P13 = 0xd0, |
| 73 | P14 = 0xe0, | 225 | P14 = 0xe0, |
| 74 | P15 = 0xf0, | 226 | P15 = 0xf0, |
| 75 | )); | 227 | } |
| 76 | 228 | ||
| 77 | #[rustfmt::skip] | 229 | #[cfg(feature = "prio-bits-5")] |
| 78 | prio!(Priority5, 0xf8, ( | 230 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
| 231 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 232 | #[repr(u8)] | ||
| 233 | pub enum Priority { | ||
| 79 | P0 = 0x0, | 234 | P0 = 0x0, |
| 80 | P1 = 0x8, | 235 | P1 = 0x8, |
| 81 | P2 = 0x10, | 236 | P2 = 0x10, |
| @@ -108,10 +263,13 @@ prio!(Priority5, 0xf8, ( | |||
| 108 | P29 = 0xe8, | 263 | P29 = 0xe8, |
| 109 | P30 = 0xf0, | 264 | P30 = 0xf0, |
| 110 | P31 = 0xf8, | 265 | P31 = 0xf8, |
| 111 | )); | 266 | } |
| 112 | 267 | ||
| 113 | #[rustfmt::skip] | 268 | #[cfg(feature = "prio-bits-6")] |
| 114 | prio!(Priority6, 0xfc, ( | 269 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
| 270 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 271 | #[repr(u8)] | ||
| 272 | pub enum Priority { | ||
| 115 | P0 = 0x0, | 273 | P0 = 0x0, |
| 116 | P1 = 0x4, | 274 | P1 = 0x4, |
| 117 | P2 = 0x8, | 275 | P2 = 0x8, |
| @@ -176,10 +334,13 @@ prio!(Priority6, 0xfc, ( | |||
| 176 | P61 = 0xf4, | 334 | P61 = 0xf4, |
| 177 | P62 = 0xf8, | 335 | P62 = 0xf8, |
| 178 | P63 = 0xfc, | 336 | P63 = 0xfc, |
| 179 | )); | 337 | } |
| 180 | 338 | ||
| 181 | #[rustfmt::skip] | 339 | #[cfg(feature = "prio-bits-7")] |
| 182 | prio!(Priority7, 0xfe, ( | 340 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
| 341 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 342 | #[repr(u8)] | ||
| 343 | pub enum Priority { | ||
| 183 | P0 = 0x0, | 344 | P0 = 0x0, |
| 184 | P1 = 0x2, | 345 | P1 = 0x2, |
| 185 | P2 = 0x4, | 346 | P2 = 0x4, |
| @@ -308,10 +469,13 @@ prio!(Priority7, 0xfe, ( | |||
| 308 | P125 = 0xfa, | 469 | P125 = 0xfa, |
| 309 | P126 = 0xfc, | 470 | P126 = 0xfc, |
| 310 | P127 = 0xfe, | 471 | P127 = 0xfe, |
| 311 | )); | 472 | } |
| 312 | 473 | ||
| 313 | #[rustfmt::skip] | 474 | #[cfg(feature = "prio-bits-8")] |
| 314 | prio!(Priority8, 0xff, ( | 475 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] |
| 476 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 477 | #[repr(u8)] | ||
| 478 | pub enum Priority { | ||
| 315 | P0 = 0x0, | 479 | P0 = 0x0, |
| 316 | P1 = 0x1, | 480 | P1 = 0x1, |
| 317 | P2 = 0x2, | 481 | P2 = 0x2, |
| @@ -568,4 +732,4 @@ prio!(Priority8, 0xff, ( | |||
| 568 | P253 = 0xfd, | 732 | P253 = 0xfd, |
| 569 | P254 = 0xfe, | 733 | P254 = 0xfe, |
| 570 | P255 = 0xff, | 734 | P255 = 0xff, |
| 571 | )); | 735 | } |
diff --git a/embassy-cortex-m/src/lib.rs b/embassy-cortex-m/src/lib.rs new file mode 100644 index 000000000..143c56f39 --- /dev/null +++ b/embassy-cortex-m/src/lib.rs | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | #![no_std] | ||
| 2 | |||
| 3 | // This mod MUST go first, so that the others see its macros. | ||
| 4 | pub(crate) mod fmt; | ||
| 5 | |||
| 6 | pub mod executor; | ||
| 7 | pub mod interrupt; | ||
| 8 | pub mod peripheral; | ||
diff --git a/embassy-hal-common/src/peripheral.rs b/embassy-cortex-m/src/peripheral.rs index db2bc7888..40277691c 100644 --- a/embassy-hal-common/src/peripheral.rs +++ b/embassy-cortex-m/src/peripheral.rs | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | use core::mem::MaybeUninit; | 2 | use core::mem::MaybeUninit; |
| 3 | |||
| 4 | use cortex_m::peripheral::scb::VectActive; | 3 | use cortex_m::peripheral::scb::VectActive; |
| 5 | use cortex_m::peripheral::{NVIC, SCB}; | 4 | use cortex_m::peripheral::{NVIC, SCB}; |
| 6 | use embassy::interrupt::{Interrupt, InterruptExt}; | 5 | |
| 6 | use crate::interrupt::{Interrupt, InterruptExt, Priority}; | ||
| 7 | 7 | ||
| 8 | /// A type which can be used as state with `PeripheralMutex`. | 8 | /// A type which can be used as state with `PeripheralMutex`. |
| 9 | /// | 9 | /// |
| @@ -116,7 +116,7 @@ impl<'a, S: PeripheralState> PeripheralMutex<'a, S> { | |||
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | /// Gets the priority of the wrapped interrupt. | 118 | /// Gets the priority of the wrapped interrupt. |
| 119 | pub fn priority(&self) -> <S::Interrupt as Interrupt>::Priority { | 119 | pub fn priority(&self) -> Priority { |
| 120 | self.irq.get_priority() | 120 | self.irq.get_priority() |
| 121 | } | 121 | } |
| 122 | } | 122 | } |
diff --git a/embassy-hal-common/src/lib.rs b/embassy-hal-common/src/lib.rs index 6ee2ccd59..c8cf1c4cd 100644 --- a/embassy-hal-common/src/lib.rs +++ b/embassy-hal-common/src/lib.rs | |||
| @@ -5,11 +5,11 @@ | |||
| 5 | pub(crate) mod fmt; | 5 | pub(crate) mod fmt; |
| 6 | 6 | ||
| 7 | pub mod drop; | 7 | pub mod drop; |
| 8 | pub mod interrupt; | ||
| 9 | mod macros; | 8 | mod macros; |
| 10 | pub mod peripheral; | ||
| 11 | pub mod ratio; | 9 | pub mod ratio; |
| 12 | pub mod ring_buffer; | 10 | pub mod ring_buffer; |
| 11 | mod unborrow; | ||
| 12 | pub use unborrow::Unborrow; | ||
| 13 | 13 | ||
| 14 | /// Low power blocking wait loop using WFE/SEV. | 14 | /// Low power blocking wait loop using WFE/SEV. |
| 15 | pub fn low_power_wait_until(mut condition: impl FnMut() -> bool) { | 15 | pub fn low_power_wait_until(mut condition: impl FnMut() -> bool) { |
diff --git a/embassy-hal-common/src/macros.rs b/embassy-hal-common/src/macros.rs index 771db40f6..c054a87c4 100644 --- a/embassy-hal-common/src/macros.rs +++ b/embassy-hal-common/src/macros.rs | |||
| @@ -16,7 +16,7 @@ macro_rules! peripherals { | |||
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | $(#[$cfg])? | 18 | $(#[$cfg])? |
| 19 | unsafe impl embassy::util::Unborrow for $name { | 19 | unsafe impl $crate::Unborrow for $name { |
| 20 | type Target = $name; | 20 | type Target = $name; |
| 21 | #[inline] | 21 | #[inline] |
| 22 | unsafe fn unborrow(self) -> $name { | 22 | unsafe fn unborrow(self) -> $name { |
| @@ -80,7 +80,7 @@ macro_rules! unborrow { | |||
| 80 | #[macro_export] | 80 | #[macro_export] |
| 81 | macro_rules! unsafe_impl_unborrow { | 81 | macro_rules! unsafe_impl_unborrow { |
| 82 | ($type:ident) => { | 82 | ($type:ident) => { |
| 83 | unsafe impl ::embassy::util::Unborrow for $type { | 83 | unsafe impl $crate::Unborrow for $type { |
| 84 | type Target = $type; | 84 | type Target = $type; |
| 85 | #[inline] | 85 | #[inline] |
| 86 | unsafe fn unborrow(self) -> Self::Target { | 86 | unsafe fn unborrow(self) -> Self::Target { |
diff --git a/embassy/src/util/unborrow.rs b/embassy-hal-common/src/unborrow.rs index dacfa3d42..dacfa3d42 100644 --- a/embassy/src/util/unborrow.rs +++ b/embassy-hal-common/src/unborrow.rs | |||
diff --git a/embassy-lora/src/stm32wl/mod.rs b/embassy-lora/src/stm32wl/mod.rs index 7dc750cf9..b5ce278dc 100644 --- a/embassy-lora/src/stm32wl/mod.rs +++ b/embassy-lora/src/stm32wl/mod.rs | |||
| @@ -2,9 +2,9 @@ | |||
| 2 | use core::future::Future; | 2 | use core::future::Future; |
| 3 | use core::mem::MaybeUninit; | 3 | use core::mem::MaybeUninit; |
| 4 | use embassy::channel::signal::Signal; | 4 | use embassy::channel::signal::Signal; |
| 5 | use embassy::interrupt::InterruptExt; | ||
| 6 | use embassy::util::Unborrow; | ||
| 7 | use embassy_hal_common::unborrow; | 5 | use embassy_hal_common::unborrow; |
| 6 | use embassy_stm32::interrupt::InterruptExt; | ||
| 7 | use embassy_stm32::Unborrow; | ||
| 8 | use embassy_stm32::{ | 8 | use embassy_stm32::{ |
| 9 | dma::NoDma, | 9 | dma::NoDma, |
| 10 | gpio::{AnyPin, Output}, | 10 | gpio::{AnyPin, Output}, |
diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index 085f7889d..50f442438 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs | |||
| @@ -22,16 +22,20 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | #[proc_macro_attribute] | 24 | #[proc_macro_attribute] |
| 25 | pub fn interrupt(args: TokenStream, item: TokenStream) -> TokenStream { | 25 | pub fn cortex_m_interrupt(args: TokenStream, item: TokenStream) -> TokenStream { |
| 26 | let args = syn::parse_macro_input!(args as syn::AttributeArgs); | 26 | let args = syn::parse_macro_input!(args as syn::AttributeArgs); |
| 27 | let f = syn::parse_macro_input!(item as syn::ItemFn); | 27 | let f = syn::parse_macro_input!(item as syn::ItemFn); |
| 28 | interrupt::run(args, f).unwrap_or_else(|x| x).into() | 28 | cortex_m_interrupt::run(args, f) |
| 29 | .unwrap_or_else(|x| x) | ||
| 30 | .into() | ||
| 29 | } | 31 | } |
| 30 | 32 | ||
| 31 | #[proc_macro] | 33 | #[proc_macro] |
| 32 | pub fn interrupt_declare(item: TokenStream) -> TokenStream { | 34 | pub fn cortex_m_interrupt_declare(item: TokenStream) -> TokenStream { |
| 33 | let name = syn::parse_macro_input!(item as syn::Ident); | 35 | let name = syn::parse_macro_input!(item as syn::Ident); |
| 34 | interrupt_declare::run(name).unwrap_or_else(|x| x).into() | 36 | cortex_m_interrupt_declare::run(name) |
| 37 | .unwrap_or_else(|x| x) | ||
| 38 | .into() | ||
| 35 | } | 39 | } |
| 36 | 40 | ||
| 37 | /// # interrupt_take procedural macro | 41 | /// # interrupt_take procedural macro |
| @@ -40,7 +44,9 @@ pub fn interrupt_declare(item: TokenStream) -> TokenStream { | |||
| 40 | /// We are aware that this brings bloat in the form of core::fmt, but the bloat is already included with e.g. array indexing panics. | 44 | /// We are aware that this brings bloat in the form of core::fmt, but the bloat is already included with e.g. array indexing panics. |
| 41 | /// To get rid of this bloat, use the compiler flags `-Zbuild-std=core -Zbuild-std-features=panic_immediate_abort`. | 45 | /// To get rid of this bloat, use the compiler flags `-Zbuild-std=core -Zbuild-std-features=panic_immediate_abort`. |
| 42 | #[proc_macro] | 46 | #[proc_macro] |
| 43 | pub fn interrupt_take(item: TokenStream) -> TokenStream { | 47 | pub fn cortex_m_interrupt_take(item: TokenStream) -> TokenStream { |
| 44 | let name = syn::parse_macro_input!(item as syn::Ident); | 48 | let name = syn::parse_macro_input!(item as syn::Ident); |
| 45 | interrupt_take::run(name).unwrap_or_else(|x| x).into() | 49 | cortex_m_interrupt_take::run(name) |
| 50 | .unwrap_or_else(|x| x) | ||
| 51 | .into() | ||
| 46 | } | 52 | } |
diff --git a/embassy-macros/src/macros/interrupt.rs b/embassy-macros/src/macros/cortex_m_interrupt.rs index 32cc0e010..32cc0e010 100644 --- a/embassy-macros/src/macros/interrupt.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt.rs | |||
diff --git a/embassy-macros/src/macros/interrupt_declare.rs b/embassy-macros/src/macros/cortex_m_interrupt_declare.rs index 0059936d9..eeed5d483 100644 --- a/embassy-macros/src/macros/interrupt_declare.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt_declare.rs | |||
| @@ -9,8 +9,7 @@ pub fn run(name: syn::Ident) -> Result<TokenStream, TokenStream> { | |||
| 9 | let result = quote! { | 9 | let result = quote! { |
| 10 | #[allow(non_camel_case_types)] | 10 | #[allow(non_camel_case_types)] |
| 11 | pub struct #name_interrupt(()); | 11 | pub struct #name_interrupt(()); |
| 12 | unsafe impl ::embassy::interrupt::Interrupt for #name_interrupt { | 12 | unsafe impl ::embassy_cortex_m::interrupt::Interrupt for #name_interrupt { |
| 13 | type Priority = crate::interrupt::Priority; | ||
| 14 | fn number(&self) -> u16 { | 13 | fn number(&self) -> u16 { |
| 15 | use cortex_m::interrupt::InterruptNumber; | 14 | use cortex_m::interrupt::InterruptNumber; |
| 16 | let irq = InterruptEnum::#name; | 15 | let irq = InterruptEnum::#name; |
| @@ -19,14 +18,14 @@ pub fn run(name: syn::Ident) -> Result<TokenStream, TokenStream> { | |||
| 19 | unsafe fn steal() -> Self { | 18 | unsafe fn steal() -> Self { |
| 20 | Self(()) | 19 | Self(()) |
| 21 | } | 20 | } |
| 22 | unsafe fn __handler(&self) -> &'static ::embassy::interrupt::Handler { | 21 | unsafe fn __handler(&self) -> &'static ::embassy_cortex_m::interrupt::Handler { |
| 23 | #[export_name = #name_handler] | 22 | #[export_name = #name_handler] |
| 24 | static HANDLER: ::embassy::interrupt::Handler = ::embassy::interrupt::Handler::new(); | 23 | static HANDLER: ::embassy_cortex_m::interrupt::Handler = ::embassy_cortex_m::interrupt::Handler::new(); |
| 25 | &HANDLER | 24 | &HANDLER |
| 26 | } | 25 | } |
| 27 | } | 26 | } |
| 28 | 27 | ||
| 29 | unsafe impl ::embassy::util::Unborrow for #name_interrupt { | 28 | unsafe impl ::embassy_hal_common::Unborrow for #name_interrupt { |
| 30 | type Target = #name_interrupt; | 29 | type Target = #name_interrupt; |
| 31 | unsafe fn unborrow(self) -> #name_interrupt { | 30 | unsafe fn unborrow(self) -> #name_interrupt { |
| 32 | self | 31 | self |
diff --git a/embassy-macros/src/macros/interrupt_take.rs b/embassy-macros/src/macros/cortex_m_interrupt_take.rs index 230b9c741..29dca12fd 100644 --- a/embassy-macros/src/macros/interrupt_take.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt_take.rs | |||
| @@ -13,7 +13,7 @@ pub fn run(name: syn::Ident) -> Result<TokenStream, TokenStream> { | |||
| 13 | pub unsafe extern "C" fn trampoline() { | 13 | pub unsafe extern "C" fn trampoline() { |
| 14 | extern "C" { | 14 | extern "C" { |
| 15 | #[link_name = #name_handler] | 15 | #[link_name = #name_handler] |
| 16 | static HANDLER: ::embassy::interrupt::Handler; | 16 | static HANDLER: interrupt::Handler; |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | let func = HANDLER.func.load(::embassy::export::atomic::Ordering::Relaxed); | 19 | let func = HANDLER.func.load(::embassy::export::atomic::Ordering::Relaxed); |
diff --git a/embassy-macros/src/macros/mod.rs b/embassy-macros/src/macros/mod.rs index 4350f229f..e547736fc 100644 --- a/embassy-macros/src/macros/mod.rs +++ b/embassy-macros/src/macros/mod.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | pub mod interrupt; | 1 | pub mod cortex_m_interrupt; |
| 2 | pub mod interrupt_declare; | 2 | pub mod cortex_m_interrupt_declare; |
| 3 | pub mod interrupt_take; | 3 | pub mod cortex_m_interrupt_take; |
| 4 | pub mod main; | 4 | pub mod main; |
| 5 | pub mod task; | 5 | pub mod task; |
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml index bf903af6d..f1e6815a5 100644 --- a/embassy-nrf/Cargo.toml +++ b/embassy-nrf/Cargo.toml | |||
| @@ -66,6 +66,7 @@ _gpio-p1 = [] | |||
| 66 | 66 | ||
| 67 | [dependencies] | 67 | [dependencies] |
| 68 | embassy = { version = "0.1.0", path = "../embassy" } | 68 | embassy = { version = "0.1.0", path = "../embassy" } |
| 69 | embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} | ||
| 69 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]} | 70 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["nrf"]} |
| 70 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } | 71 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } |
| 71 | embassy-usb = {version = "0.1.0", path = "../embassy-usb", optional=true } | 72 | embassy-usb = {version = "0.1.0", path = "../embassy-usb", optional=true } |
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index 6972d625d..ef3ccdc93 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs | |||
| @@ -13,15 +13,15 @@ | |||
| 13 | //! | 13 | //! |
| 14 | //! Please also see [crate::uarte] to understand when [BufferedUarte] should be used. | 14 | //! Please also see [crate::uarte] to understand when [BufferedUarte] should be used. |
| 15 | 15 | ||
| 16 | use crate::interrupt::InterruptExt; | ||
| 17 | use crate::Unborrow; | ||
| 16 | use core::cmp::min; | 18 | use core::cmp::min; |
| 17 | use core::future::Future; | 19 | use core::future::Future; |
| 18 | use core::marker::PhantomData; | 20 | use core::marker::PhantomData; |
| 19 | use core::sync::atomic::{compiler_fence, Ordering}; | 21 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 20 | use core::task::Poll; | 22 | use core::task::Poll; |
| 21 | use embassy::interrupt::InterruptExt; | ||
| 22 | use embassy::util::Unborrow; | ||
| 23 | use embassy::waitqueue::WakerRegistration; | 23 | use embassy::waitqueue::WakerRegistration; |
| 24 | use embassy_hal_common::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 24 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 25 | use embassy_hal_common::ring_buffer::RingBuffer; | 25 | use embassy_hal_common::ring_buffer::RingBuffer; |
| 26 | use embassy_hal_common::{low_power_wait_until, unborrow}; | 26 | use embassy_hal_common::{low_power_wait_until, unborrow}; |
| 27 | use futures::future::poll_fn; | 27 | use futures::future::poll_fn; |
diff --git a/embassy-nrf/src/chips/nrf52805.rs b/embassy-nrf/src/chips/nrf52805.rs index c917dcdd0..31659859b 100644 --- a/embassy-nrf/src/chips/nrf52805.rs +++ b/embassy-nrf/src/chips/nrf52805.rs | |||
| @@ -198,7 +198,7 @@ impl_saadc_input!(P0_05, ANALOGINPUT3); | |||
| 198 | 198 | ||
| 199 | pub mod irqs { | 199 | pub mod irqs { |
| 200 | use crate::pac::Interrupt as InterruptEnum; | 200 | use crate::pac::Interrupt as InterruptEnum; |
| 201 | use embassy_macros::interrupt_declare as declare; | 201 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 202 | 202 | ||
| 203 | declare!(POWER_CLOCK); | 203 | declare!(POWER_CLOCK); |
| 204 | declare!(RADIO); | 204 | declare!(RADIO); |
diff --git a/embassy-nrf/src/chips/nrf52810.rs b/embassy-nrf/src/chips/nrf52810.rs index 922b683f9..195be51c8 100644 --- a/embassy-nrf/src/chips/nrf52810.rs +++ b/embassy-nrf/src/chips/nrf52810.rs | |||
| @@ -219,7 +219,7 @@ impl_saadc_input!(P0_31, ANALOGINPUT7); | |||
| 219 | 219 | ||
| 220 | pub mod irqs { | 220 | pub mod irqs { |
| 221 | use crate::pac::Interrupt as InterruptEnum; | 221 | use crate::pac::Interrupt as InterruptEnum; |
| 222 | use embassy_macros::interrupt_declare as declare; | 222 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 223 | 223 | ||
| 224 | declare!(POWER_CLOCK); | 224 | declare!(POWER_CLOCK); |
| 225 | declare!(RADIO); | 225 | declare!(RADIO); |
diff --git a/embassy-nrf/src/chips/nrf52811.rs b/embassy-nrf/src/chips/nrf52811.rs index d23ab5b39..18f054059 100644 --- a/embassy-nrf/src/chips/nrf52811.rs +++ b/embassy-nrf/src/chips/nrf52811.rs | |||
| @@ -220,7 +220,7 @@ impl_saadc_input!(P0_31, ANALOGINPUT7); | |||
| 220 | 220 | ||
| 221 | pub mod irqs { | 221 | pub mod irqs { |
| 222 | use crate::pac::Interrupt as InterruptEnum; | 222 | use crate::pac::Interrupt as InterruptEnum; |
| 223 | use embassy_macros::interrupt_declare as declare; | 223 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 224 | 224 | ||
| 225 | declare!(POWER_CLOCK); | 225 | declare!(POWER_CLOCK); |
| 226 | declare!(RADIO); | 226 | declare!(RADIO); |
diff --git a/embassy-nrf/src/chips/nrf52820.rs b/embassy-nrf/src/chips/nrf52820.rs index e94ddbb14..b4ad4c729 100644 --- a/embassy-nrf/src/chips/nrf52820.rs +++ b/embassy-nrf/src/chips/nrf52820.rs | |||
| @@ -212,7 +212,7 @@ impl_ppi_channel!(PPI_CH31, 31 => static); | |||
| 212 | 212 | ||
| 213 | pub mod irqs { | 213 | pub mod irqs { |
| 214 | use crate::pac::Interrupt as InterruptEnum; | 214 | use crate::pac::Interrupt as InterruptEnum; |
| 215 | use embassy_macros::interrupt_declare as declare; | 215 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 216 | 216 | ||
| 217 | declare!(POWER_CLOCK); | 217 | declare!(POWER_CLOCK); |
| 218 | declare!(RADIO); | 218 | declare!(RADIO); |
diff --git a/embassy-nrf/src/chips/nrf52832.rs b/embassy-nrf/src/chips/nrf52832.rs index fec7e10de..d578519ff 100644 --- a/embassy-nrf/src/chips/nrf52832.rs +++ b/embassy-nrf/src/chips/nrf52832.rs | |||
| @@ -236,7 +236,7 @@ impl_saadc_input!(P0_31, ANALOGINPUT7); | |||
| 236 | 236 | ||
| 237 | pub mod irqs { | 237 | pub mod irqs { |
| 238 | use crate::pac::Interrupt as InterruptEnum; | 238 | use crate::pac::Interrupt as InterruptEnum; |
| 239 | use embassy_macros::interrupt_declare as declare; | 239 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 240 | 240 | ||
| 241 | declare!(POWER_CLOCK); | 241 | declare!(POWER_CLOCK); |
| 242 | declare!(RADIO); | 242 | declare!(RADIO); |
diff --git a/embassy-nrf/src/chips/nrf52833.rs b/embassy-nrf/src/chips/nrf52833.rs index e09c77187..92f415a51 100644 --- a/embassy-nrf/src/chips/nrf52833.rs +++ b/embassy-nrf/src/chips/nrf52833.rs | |||
| @@ -279,7 +279,7 @@ impl_saadc_input!(P0_31, ANALOGINPUT7); | |||
| 279 | 279 | ||
| 280 | pub mod irqs { | 280 | pub mod irqs { |
| 281 | use crate::pac::Interrupt as InterruptEnum; | 281 | use crate::pac::Interrupt as InterruptEnum; |
| 282 | use embassy_macros::interrupt_declare as declare; | 282 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 283 | 283 | ||
| 284 | declare!(POWER_CLOCK); | 284 | declare!(POWER_CLOCK); |
| 285 | declare!(RADIO); | 285 | declare!(RADIO); |
diff --git a/embassy-nrf/src/chips/nrf52840.rs b/embassy-nrf/src/chips/nrf52840.rs index 2e71e04b0..e7a94b18f 100644 --- a/embassy-nrf/src/chips/nrf52840.rs +++ b/embassy-nrf/src/chips/nrf52840.rs | |||
| @@ -284,7 +284,7 @@ impl_saadc_input!(P0_31, ANALOGINPUT7); | |||
| 284 | 284 | ||
| 285 | pub mod irqs { | 285 | pub mod irqs { |
| 286 | use crate::pac::Interrupt as InterruptEnum; | 286 | use crate::pac::Interrupt as InterruptEnum; |
| 287 | use embassy_macros::interrupt_declare as declare; | 287 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 288 | 288 | ||
| 289 | declare!(POWER_CLOCK); | 289 | declare!(POWER_CLOCK); |
| 290 | declare!(RADIO); | 290 | declare!(RADIO); |
diff --git a/embassy-nrf/src/chips/nrf5340_app.rs b/embassy-nrf/src/chips/nrf5340_app.rs index 89579b69f..13ed23cd7 100644 --- a/embassy-nrf/src/chips/nrf5340_app.rs +++ b/embassy-nrf/src/chips/nrf5340_app.rs | |||
| @@ -469,7 +469,7 @@ impl_saadc_input!(P0_20, ANALOGINPUT7); | |||
| 469 | 469 | ||
| 470 | pub mod irqs { | 470 | pub mod irqs { |
| 471 | use crate::pac::Interrupt as InterruptEnum; | 471 | use crate::pac::Interrupt as InterruptEnum; |
| 472 | use embassy_macros::interrupt_declare as declare; | 472 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 473 | 473 | ||
| 474 | declare!(FPU); | 474 | declare!(FPU); |
| 475 | declare!(CACHE); | 475 | declare!(CACHE); |
diff --git a/embassy-nrf/src/chips/nrf5340_net.rs b/embassy-nrf/src/chips/nrf5340_net.rs index e2ae97a9d..a7e70cdc3 100644 --- a/embassy-nrf/src/chips/nrf5340_net.rs +++ b/embassy-nrf/src/chips/nrf5340_net.rs | |||
| @@ -329,7 +329,7 @@ impl_ppi_channel!(PPI_CH31, 31 => configurable); | |||
| 329 | 329 | ||
| 330 | pub mod irqs { | 330 | pub mod irqs { |
| 331 | use crate::pac::Interrupt as InterruptEnum; | 331 | use crate::pac::Interrupt as InterruptEnum; |
| 332 | use embassy_macros::interrupt_declare as declare; | 332 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 333 | 333 | ||
| 334 | declare!(CLOCK_POWER); | 334 | declare!(CLOCK_POWER); |
| 335 | declare!(RADIO); | 335 | declare!(RADIO); |
diff --git a/embassy-nrf/src/chips/nrf9160.rs b/embassy-nrf/src/chips/nrf9160.rs index b8caa1264..57ff39b7b 100644 --- a/embassy-nrf/src/chips/nrf9160.rs +++ b/embassy-nrf/src/chips/nrf9160.rs | |||
| @@ -347,7 +347,7 @@ impl_saadc_input!(P0_20, ANALOGINPUT7); | |||
| 347 | 347 | ||
| 348 | pub mod irqs { | 348 | pub mod irqs { |
| 349 | use crate::pac::Interrupt as InterruptEnum; | 349 | use crate::pac::Interrupt as InterruptEnum; |
| 350 | use embassy_macros::interrupt_declare as declare; | 350 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 351 | 351 | ||
| 352 | declare!(SPU); | 352 | declare!(SPU); |
| 353 | declare!(CLOCK_POWER); | 353 | declare!(CLOCK_POWER); |
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index f5212c6af..a6c846213 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs | |||
| @@ -4,8 +4,8 @@ use core::convert::Infallible; | |||
| 4 | use core::hint::unreachable_unchecked; | 4 | use core::hint::unreachable_unchecked; |
| 5 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 6 | 6 | ||
| 7 | use crate::Unborrow; | ||
| 7 | use cfg_if::cfg_if; | 8 | use cfg_if::cfg_if; |
| 8 | use embassy::util::Unborrow; | ||
| 9 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; | 9 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; |
| 10 | 10 | ||
| 11 | use crate::pac; | 11 | use crate::pac; |
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index c0bfd9d65..051546236 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 1 | use core::convert::Infallible; | 2 | use core::convert::Infallible; |
| 2 | use core::future::Future; | 3 | use core::future::Future; |
| 3 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
| 4 | use core::task::{Context, Poll}; | 5 | use core::task::{Context, Poll}; |
| 5 | use embassy::interrupt::{Interrupt, InterruptExt}; | ||
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::unsafe_impl_unborrow; | 7 | use embassy_hal_common::unsafe_impl_unborrow; |
| 8 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 9c298a8b0..6eaadfc63 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -114,23 +114,23 @@ mod chip; | |||
| 114 | 114 | ||
| 115 | pub use chip::EASY_DMA_SIZE; | 115 | pub use chip::EASY_DMA_SIZE; |
| 116 | 116 | ||
| 117 | pub mod interrupt { | ||
| 118 | pub use crate::chip::irqs::*; | ||
| 119 | pub use cortex_m::interrupt::{CriticalSection, Mutex}; | ||
| 120 | pub use embassy_cortex_m::interrupt::*; | ||
| 121 | } | ||
| 122 | |||
| 123 | // Reexports | ||
| 124 | |||
| 117 | #[cfg(feature = "unstable-pac")] | 125 | #[cfg(feature = "unstable-pac")] |
| 118 | pub use chip::pac; | 126 | pub use chip::pac; |
| 119 | #[cfg(not(feature = "unstable-pac"))] | 127 | #[cfg(not(feature = "unstable-pac"))] |
| 120 | pub(crate) use chip::pac; | 128 | pub(crate) use chip::pac; |
| 121 | 129 | ||
| 122 | pub use embassy::util::Unborrow; | ||
| 123 | pub use embassy_hal_common::unborrow; | ||
| 124 | |||
| 125 | pub use chip::{peripherals, Peripherals}; | 130 | pub use chip::{peripherals, Peripherals}; |
| 126 | 131 | pub use embassy_cortex_m::executor; | |
| 127 | pub mod interrupt { | 132 | pub use embassy_hal_common::{unborrow, Unborrow}; |
| 128 | pub use crate::chip::irqs::*; | 133 | pub use embassy_macros::cortex_m_interrupt as interrupt; |
| 129 | pub use cortex_m::interrupt::{CriticalSection, Mutex}; | ||
| 130 | pub use embassy::interrupt::{declare, take, Interrupt}; | ||
| 131 | pub use embassy_hal_common::interrupt::Priority3 as Priority; | ||
| 132 | } | ||
| 133 | pub use embassy_macros::interrupt; | ||
| 134 | 134 | ||
| 135 | pub mod config { | 135 | pub mod config { |
| 136 | pub enum HfclkSource { | 136 | pub enum HfclkSource { |
diff --git a/embassy-nrf/src/nvmc.rs b/embassy-nrf/src/nvmc.rs index 7d7b56841..108a71d5e 100644 --- a/embassy-nrf/src/nvmc.rs +++ b/embassy-nrf/src/nvmc.rs | |||
| @@ -3,10 +3,10 @@ | |||
| 3 | use crate::pac; | 3 | use crate::pac; |
| 4 | use crate::peripherals::NVMC; | 4 | use crate::peripherals::NVMC; |
| 5 | 5 | ||
| 6 | use crate::Unborrow; | ||
| 6 | use core::marker::PhantomData; | 7 | use core::marker::PhantomData; |
| 7 | use core::ptr; | 8 | use core::ptr; |
| 8 | use core::slice; | 9 | use core::slice; |
| 9 | use embassy::util::Unborrow; | ||
| 10 | use embassy_hal_common::unborrow; | 10 | use embassy_hal_common::unborrow; |
| 11 | use embedded_storage::nor_flash::{ | 11 | use embedded_storage::nor_flash::{ |
| 12 | ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, | 12 | ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, |
diff --git a/embassy-nrf/src/ppi/dppi.rs b/embassy-nrf/src/ppi/dppi.rs index 1842590b4..8609ef8d4 100644 --- a/embassy-nrf/src/ppi/dppi.rs +++ b/embassy-nrf/src/ppi/dppi.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy::util::Unborrow; | 3 | use crate::Unborrow; |
| 4 | use embassy_hal_common::unborrow; | 4 | use embassy_hal_common::unborrow; |
| 5 | 5 | ||
| 6 | use crate::pac; | 6 | use crate::pac; |
diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index aeccb154b..faabbf7ca 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs | |||
| @@ -16,9 +16,9 @@ | |||
| 16 | //! | 16 | //! |
| 17 | 17 | ||
| 18 | use crate::peripherals; | 18 | use crate::peripherals; |
| 19 | use crate::Unborrow; | ||
| 19 | use core::marker::PhantomData; | 20 | use core::marker::PhantomData; |
| 20 | use core::ptr::NonNull; | 21 | use core::ptr::NonNull; |
| 21 | use embassy::util::Unborrow; | ||
| 22 | use embassy_hal_common::unsafe_impl_unborrow; | 22 | use embassy_hal_common::unsafe_impl_unborrow; |
| 23 | 23 | ||
| 24 | #[cfg(feature = "_dppi")] | 24 | #[cfg(feature = "_dppi")] |
diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs index cdbe046f8..d832d69e7 100644 --- a/embassy-nrf/src/ppi/ppi.rs +++ b/embassy-nrf/src/ppi/ppi.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy::util::Unborrow; | 3 | use crate::Unborrow; |
| 4 | use embassy_hal_common::unborrow; | 4 | use embassy_hal_common::unborrow; |
| 5 | 5 | ||
| 6 | use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task}; | 6 | use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task}; |
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index 5ac52f172..3ed60ca05 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::Unborrow; | ||
| 3 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
| 4 | use core::sync::atomic::{compiler_fence, Ordering}; | 5 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 5 | use embassy::util::Unborrow; | ||
| 6 | use embassy_hal_common::unborrow; | 6 | use embassy_hal_common::unborrow; |
| 7 | 7 | ||
| 8 | use crate::gpio::sealed::Pin as _; | 8 | use crate::gpio::sealed::Pin as _; |
diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs index c26815389..b230043b4 100644 --- a/embassy-nrf/src/qdec.rs +++ b/embassy-nrf/src/qdec.rs | |||
| @@ -6,10 +6,10 @@ use crate::interrupt; | |||
| 6 | use crate::pac; | 6 | use crate::pac; |
| 7 | use crate::peripherals::QDEC; | 7 | use crate::peripherals::QDEC; |
| 8 | 8 | ||
| 9 | use crate::interrupt::InterruptExt; | ||
| 10 | use crate::Unborrow; | ||
| 9 | use core::marker::PhantomData; | 11 | use core::marker::PhantomData; |
| 10 | use core::task::Poll; | 12 | use core::task::Poll; |
| 11 | use embassy::interrupt::InterruptExt; | ||
| 12 | use embassy::util::Unborrow; | ||
| 13 | use embassy::waitqueue::AtomicWaker; | 13 | use embassy::waitqueue::AtomicWaker; |
| 14 | use embassy_hal_common::unborrow; | 14 | use embassy_hal_common::unborrow; |
| 15 | use futures::future::poll_fn; | 15 | use futures::future::poll_fn; |
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 8902879f8..adb0d8386 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 4 | use crate::Unborrow; | ||
| 3 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 4 | use core::ptr; | 6 | use core::ptr; |
| 5 | use core::task::Poll; | 7 | use core::task::Poll; |
| 6 | use embassy::interrupt::{Interrupt, InterruptExt}; | ||
| 7 | use embassy::util::Unborrow; | ||
| 8 | use embassy_hal_common::drop::DropBomb; | 8 | use embassy_hal_common::drop::DropBomb; |
| 9 | use embassy_hal_common::unborrow; | 9 | use embassy_hal_common::unborrow; |
| 10 | use futures::future::poll_fn; | 10 | use futures::future::poll_fn; |
diff --git a/embassy-nrf/src/rng.rs b/embassy-nrf/src/rng.rs index 98833c52b..43cf805fd 100644 --- a/embassy-nrf/src/rng.rs +++ b/embassy-nrf/src/rng.rs | |||
| @@ -4,8 +4,8 @@ use core::sync::atomic::AtomicPtr; | |||
| 4 | use core::sync::atomic::Ordering; | 4 | use core::sync::atomic::Ordering; |
| 5 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | 6 | ||
| 7 | use embassy::interrupt::InterruptExt; | 7 | use crate::interrupt::InterruptExt; |
| 8 | use embassy::util::Unborrow; | 8 | use crate::Unborrow; |
| 9 | use embassy::waitqueue::AtomicWaker; | 9 | use embassy::waitqueue::AtomicWaker; |
| 10 | use embassy_hal_common::drop::OnDrop; | 10 | use embassy_hal_common::drop::OnDrop; |
| 11 | use embassy_hal_common::unborrow; | 11 | use embassy_hal_common::unborrow; |
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 61bc1fbda..915115a12 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::interrupt::InterruptExt; | ||
| 4 | use crate::Unborrow; | ||
| 3 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 4 | use core::sync::atomic::{compiler_fence, Ordering}; | 6 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 5 | use core::task::Poll; | 7 | use core::task::Poll; |
| 6 | use embassy::interrupt::InterruptExt; | ||
| 7 | use embassy::util::Unborrow; | ||
| 8 | use embassy::waitqueue::AtomicWaker; | 8 | use embassy::waitqueue::AtomicWaker; |
| 9 | use embassy_hal_common::unborrow; | 9 | use embassy_hal_common::unborrow; |
| 10 | use futures::future::poll_fn; | 10 | use futures::future::poll_fn; |
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index f97a1c0fe..7b28373df 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::interrupt::InterruptExt; | ||
| 4 | use crate::Unborrow; | ||
| 3 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 4 | use core::sync::atomic::{compiler_fence, Ordering}; | 6 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 5 | use core::task::Poll; | 7 | use core::task::Poll; |
| 6 | use embassy::interrupt::InterruptExt; | ||
| 7 | use embassy::util::Unborrow; | ||
| 8 | use embassy_hal_common::unborrow; | 8 | use embassy_hal_common::unborrow; |
| 9 | use futures::future::poll_fn; | 9 | use futures::future::poll_fn; |
| 10 | 10 | ||
diff --git a/embassy-nrf/src/temp.rs b/embassy-nrf/src/temp.rs index f7c6e6609..e5e5f29ab 100644 --- a/embassy-nrf/src/temp.rs +++ b/embassy-nrf/src/temp.rs | |||
| @@ -4,10 +4,10 @@ use crate::interrupt; | |||
| 4 | use crate::pac; | 4 | use crate::pac; |
| 5 | use crate::peripherals::TEMP; | 5 | use crate::peripherals::TEMP; |
| 6 | 6 | ||
| 7 | use crate::interrupt::InterruptExt; | ||
| 8 | use crate::Unborrow; | ||
| 7 | use core::marker::PhantomData; | 9 | use core::marker::PhantomData; |
| 8 | use core::task::Poll; | 10 | use core::task::Poll; |
| 9 | use embassy::interrupt::InterruptExt; | ||
| 10 | use embassy::util::Unborrow; | ||
| 11 | use embassy::waitqueue::AtomicWaker; | 11 | use embassy::waitqueue::AtomicWaker; |
| 12 | use embassy_hal_common::{drop::OnDrop, unborrow}; | 12 | use embassy_hal_common::{drop::OnDrop, unborrow}; |
| 13 | use fixed::types::I30F2; | 13 | use fixed::types::I30F2; |
diff --git a/embassy-nrf/src/time_driver.rs b/embassy-nrf/src/time_driver.rs index a32a7bc7c..8f1758146 100644 --- a/embassy-nrf/src/time_driver.rs +++ b/embassy-nrf/src/time_driver.rs | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 1 | use core::cell::Cell; | 2 | use core::cell::Cell; |
| 2 | use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering}; | 3 | use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering}; |
| 3 | use core::{mem, ptr}; | 4 | use core::{mem, ptr}; |
| 4 | use critical_section::CriticalSection; | 5 | use critical_section::CriticalSection; |
| 5 | use embassy::blocking_mutex::raw::CriticalSectionRawMutex; | 6 | use embassy::blocking_mutex::raw::CriticalSectionRawMutex; |
| 6 | use embassy::blocking_mutex::CriticalSectionMutex as Mutex; | 7 | use embassy::blocking_mutex::CriticalSectionMutex as Mutex; |
| 7 | use embassy::interrupt::{Interrupt, InterruptExt}; | ||
| 8 | use embassy::time::driver::{AlarmHandle, Driver}; | 8 | use embassy::time::driver::{AlarmHandle, Driver}; |
| 9 | 9 | ||
| 10 | use crate::interrupt; | 10 | use crate::interrupt; |
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs index 9173338b6..588654f96 100644 --- a/embassy-nrf/src/timer.rs +++ b/embassy-nrf/src/timer.rs | |||
| @@ -3,9 +3,9 @@ | |||
| 3 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 4 | use core::task::Poll; | 4 | use core::task::Poll; |
| 5 | 5 | ||
| 6 | use embassy::interrupt::Interrupt; | 6 | use crate::interrupt::Interrupt; |
| 7 | use embassy::interrupt::InterruptExt; | 7 | use crate::interrupt::InterruptExt; |
| 8 | use embassy::util::Unborrow; | 8 | use crate::Unborrow; |
| 9 | use embassy::waitqueue::AtomicWaker; | 9 | use embassy::waitqueue::AtomicWaker; |
| 10 | use embassy_hal_common::drop::OnDrop; | 10 | use embassy_hal_common::drop::OnDrop; |
| 11 | use embassy_hal_common::unborrow; | 11 | use embassy_hal_common::unborrow; |
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index 510266c9a..2337ae219 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs | |||
| @@ -6,14 +6,14 @@ | |||
| 6 | //! | 6 | //! |
| 7 | //! - nRF52832: Section 33 | 7 | //! - nRF52832: Section 33 |
| 8 | //! - nRF52840: Section 6.31 | 8 | //! - nRF52840: Section 6.31 |
| 9 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 10 | use crate::Unborrow; | ||
| 9 | use core::future::Future; | 11 | use core::future::Future; |
| 10 | use core::marker::PhantomData; | 12 | use core::marker::PhantomData; |
| 11 | use core::sync::atomic::{compiler_fence, Ordering::SeqCst}; | 13 | use core::sync::atomic::{compiler_fence, Ordering::SeqCst}; |
| 12 | use core::task::Poll; | 14 | use core::task::Poll; |
| 13 | use embassy::interrupt::{Interrupt, InterruptExt}; | ||
| 14 | #[cfg(feature = "time")] | 15 | #[cfg(feature = "time")] |
| 15 | use embassy::time::{Duration, Instant}; | 16 | use embassy::time::{Duration, Instant}; |
| 16 | use embassy::util::Unborrow; | ||
| 17 | use embassy::waitqueue::AtomicWaker; | 17 | use embassy::waitqueue::AtomicWaker; |
| 18 | use embassy_hal_common::unborrow; | 18 | use embassy_hal_common::unborrow; |
| 19 | use futures::future::poll_fn; | 19 | use futures::future::poll_fn; |
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 8970b8a1e..70dbfb080 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -13,11 +13,11 @@ | |||
| 13 | //! memory may be used given that buffers are passed in directly to its read and write | 13 | //! memory may be used given that buffers are passed in directly to its read and write |
| 14 | //! methods. | 14 | //! methods. |
| 15 | 15 | ||
| 16 | use crate::interrupt::InterruptExt; | ||
| 17 | use crate::Unborrow; | ||
| 16 | use core::marker::PhantomData; | 18 | use core::marker::PhantomData; |
| 17 | use core::sync::atomic::{compiler_fence, Ordering}; | 19 | use core::sync::atomic::{compiler_fence, Ordering}; |
| 18 | use core::task::Poll; | 20 | use core::task::Poll; |
| 19 | use embassy::interrupt::InterruptExt; | ||
| 20 | use embassy::util::Unborrow; | ||
| 21 | use embassy_hal_common::drop::OnDrop; | 21 | use embassy_hal_common::drop::OnDrop; |
| 22 | use embassy_hal_common::unborrow; | 22 | use embassy_hal_common::unborrow; |
| 23 | use futures::future::poll_fn; | 23 | use futures::future::poll_fn; |
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index 842abf162..d0223c4c9 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::interrupt::InterruptExt; | ||
| 4 | use crate::Unborrow; | ||
| 3 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 4 | use core::mem::MaybeUninit; | 6 | use core::mem::MaybeUninit; |
| 5 | use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; | 7 | use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; |
| 6 | use core::task::Poll; | 8 | use core::task::Poll; |
| 7 | use cortex_m::peripheral::NVIC; | 9 | use cortex_m::peripheral::NVIC; |
| 8 | use embassy::interrupt::InterruptExt; | ||
| 9 | use embassy::util::Unborrow; | ||
| 10 | use embassy::waitqueue::AtomicWaker; | 10 | use embassy::waitqueue::AtomicWaker; |
| 11 | use embassy_hal_common::unborrow; | 11 | use embassy_hal_common::unborrow; |
| 12 | use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; | 12 | use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; |
diff --git a/embassy-rp/Cargo.toml b/embassy-rp/Cargo.toml index f2eed64df..4896647fb 100644 --- a/embassy-rp/Cargo.toml +++ b/embassy-rp/Cargo.toml | |||
| @@ -29,6 +29,7 @@ unstable-traits = ["embedded-hal-1"] | |||
| 29 | 29 | ||
| 30 | [dependencies] | 30 | [dependencies] |
| 31 | embassy = { version = "0.1.0", path = "../embassy", features = [ "time-tick-1mhz", "nightly"] } | 31 | embassy = { version = "0.1.0", path = "../embassy", features = [ "time-tick-1mhz", "nightly"] } |
| 32 | embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-3"]} | ||
| 32 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } | 33 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } |
| 33 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["rp"]} | 34 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["rp"]} |
| 34 | atomic-polyfill = "0.1.5" | 35 | atomic-polyfill = "0.1.5" |
diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index 12b9f6aca..a2e1b3d7b 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs | |||
| @@ -6,7 +6,7 @@ use crate::pac::common::{Reg, RW}; | |||
| 6 | use crate::pac::SIO; | 6 | use crate::pac::SIO; |
| 7 | use crate::peripherals; | 7 | use crate::peripherals; |
| 8 | 8 | ||
| 9 | use embassy::util::Unborrow; | 9 | use crate::Unborrow; |
| 10 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; | 10 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; |
| 11 | 11 | ||
| 12 | /// Represents a digital input or output level. | 12 | /// Represents a digital input or output level. |
diff --git a/embassy-rp/src/interrupt.rs b/embassy-rp/src/interrupt.rs index 109afcbc4..042882691 100644 --- a/embassy-rp/src/interrupt.rs +++ b/embassy-rp/src/interrupt.rs | |||
| @@ -4,39 +4,33 @@ | |||
| 4 | //! nrf_softdevice::interrupt. Intended for switching between the two at compile-time. | 4 | //! nrf_softdevice::interrupt. Intended for switching between the two at compile-time. |
| 5 | 5 | ||
| 6 | // Re-exports | 6 | // Re-exports |
| 7 | pub use embassy::interrupt::{declare, take, Interrupt}; | 7 | pub use embassy_cortex_m::interrupt::*; |
| 8 | pub use embassy_hal_common::interrupt::Priority3 as Priority; | ||
| 9 | 8 | ||
| 10 | mod irqs { | 9 | use crate::pac::Interrupt as InterruptEnum; |
| 11 | use super::*; | 10 | use embassy_macros::cortex_m_interrupt_declare as declare; |
| 12 | use crate::pac::Interrupt as InterruptEnum; | 11 | declare!(TIMER_IRQ_0); |
| 13 | 12 | declare!(TIMER_IRQ_1); | |
| 14 | declare!(TIMER_IRQ_0); | 13 | declare!(TIMER_IRQ_2); |
| 15 | declare!(TIMER_IRQ_1); | 14 | declare!(TIMER_IRQ_3); |
| 16 | declare!(TIMER_IRQ_2); | 15 | declare!(PWM_IRQ_WRAP); |
| 17 | declare!(TIMER_IRQ_3); | 16 | declare!(USBCTRL_IRQ); |
| 18 | declare!(PWM_IRQ_WRAP); | 17 | declare!(XIP_IRQ); |
| 19 | declare!(USBCTRL_IRQ); | 18 | declare!(PIO0_IRQ_0); |
| 20 | declare!(XIP_IRQ); | 19 | declare!(PIO0_IRQ_1); |
| 21 | declare!(PIO0_IRQ_0); | 20 | declare!(PIO1_IRQ_0); |
| 22 | declare!(PIO0_IRQ_1); | 21 | declare!(PIO1_IRQ_1); |
| 23 | declare!(PIO1_IRQ_0); | 22 | declare!(DMA_IRQ_0); |
| 24 | declare!(PIO1_IRQ_1); | 23 | declare!(DMA_IRQ_1); |
| 25 | declare!(DMA_IRQ_0); | 24 | declare!(IO_IRQ_BANK0); |
| 26 | declare!(DMA_IRQ_1); | 25 | declare!(IO_IRQ_QSPI); |
| 27 | declare!(IO_IRQ_BANK0); | 26 | declare!(SIO_IRQ_PROC0); |
| 28 | declare!(IO_IRQ_QSPI); | 27 | declare!(SIO_IRQ_PROC1); |
| 29 | declare!(SIO_IRQ_PROC0); | 28 | declare!(CLOCKS_IRQ); |
| 30 | declare!(SIO_IRQ_PROC1); | 29 | declare!(SPI0_IRQ); |
| 31 | declare!(CLOCKS_IRQ); | 30 | declare!(SPI1_IRQ); |
| 32 | declare!(SPI0_IRQ); | 31 | declare!(UART0_IRQ); |
| 33 | declare!(SPI1_IRQ); | 32 | declare!(UART1_IRQ); |
| 34 | declare!(UART0_IRQ); | 33 | declare!(ADC_IRQ_FIFO); |
| 35 | declare!(UART1_IRQ); | 34 | declare!(I2C0_IRQ); |
| 36 | declare!(ADC_IRQ_FIFO); | 35 | declare!(I2C1_IRQ); |
| 37 | declare!(I2C0_IRQ); | 36 | declare!(RTC_IRQ); |
| 38 | declare!(I2C1_IRQ); | ||
| 39 | declare!(RTC_IRQ); | ||
| 40 | } | ||
| 41 | |||
| 42 | pub use irqs::*; | ||
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 5de38af08..72fe864b5 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs | |||
| @@ -2,22 +2,12 @@ | |||
| 2 | #![feature(generic_associated_types)] | 2 | #![feature(generic_associated_types)] |
| 3 | #![feature(type_alias_impl_trait)] | 3 | #![feature(type_alias_impl_trait)] |
| 4 | 4 | ||
| 5 | #[cfg(feature = "unstable-pac")] | ||
| 6 | pub use rp2040_pac2 as pac; | ||
| 7 | #[cfg(not(feature = "unstable-pac"))] | ||
| 8 | pub(crate) use rp2040_pac2 as pac; | ||
| 9 | |||
| 10 | pub use embassy::util::Unborrow; | ||
| 11 | pub use embassy_hal_common::unborrow; | ||
| 12 | |||
| 13 | // This mod MUST go first, so that the others see its macros. | 5 | // This mod MUST go first, so that the others see its macros. |
| 14 | pub(crate) mod fmt; | 6 | pub(crate) mod fmt; |
| 15 | 7 | ||
| 16 | pub mod interrupt; | ||
| 17 | pub use embassy_macros::interrupt; | ||
| 18 | |||
| 19 | pub mod dma; | 8 | pub mod dma; |
| 20 | pub mod gpio; | 9 | pub mod gpio; |
| 10 | pub mod interrupt; | ||
| 21 | pub mod spi; | 11 | pub mod spi; |
| 22 | pub mod timer; | 12 | pub mod timer; |
| 23 | pub mod uart; | 13 | pub mod uart; |
| @@ -25,6 +15,17 @@ pub mod uart; | |||
| 25 | mod clocks; | 15 | mod clocks; |
| 26 | mod reset; | 16 | mod reset; |
| 27 | 17 | ||
| 18 | // Reexports | ||
| 19 | |||
| 20 | #[cfg(feature = "unstable-pac")] | ||
| 21 | pub use rp2040_pac2 as pac; | ||
| 22 | #[cfg(not(feature = "unstable-pac"))] | ||
| 23 | pub(crate) use rp2040_pac2 as pac; | ||
| 24 | |||
| 25 | pub use embassy_cortex_m::executor; | ||
| 26 | pub use embassy_hal_common::{unborrow, Unborrow}; | ||
| 27 | pub use embassy_macros::cortex_m_interrupt as interrupt; | ||
| 28 | |||
| 28 | embassy_hal_common::peripherals! { | 29 | embassy_hal_common::peripherals! { |
| 29 | PIN_0, | 30 | PIN_0, |
| 30 | PIN_1, | 31 | PIN_1, |
diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index 8b90ba285..726c20a83 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy::util::Unborrow; | 3 | use crate::Unborrow; |
| 4 | use embassy_hal_common::unborrow; | 4 | use embassy_hal_common::unborrow; |
| 5 | 5 | ||
| 6 | use crate::gpio::sealed::Pin as _; | 6 | use crate::gpio::sealed::Pin as _; |
diff --git a/embassy-rp/src/timer.rs b/embassy-rp/src/timer.rs index f449df000..c43e044f3 100644 --- a/embassy-rp/src/timer.rs +++ b/embassy-rp/src/timer.rs | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 1 | use atomic_polyfill::{AtomicU8, Ordering}; | 2 | use atomic_polyfill::{AtomicU8, Ordering}; |
| 2 | use core::cell::Cell; | 3 | use core::cell::Cell; |
| 3 | use critical_section::CriticalSection; | 4 | use critical_section::CriticalSection; |
| 4 | use embassy::blocking_mutex::raw::CriticalSectionRawMutex; | 5 | use embassy::blocking_mutex::raw::CriticalSectionRawMutex; |
| 5 | use embassy::blocking_mutex::Mutex; | 6 | use embassy::blocking_mutex::Mutex; |
| 6 | use embassy::interrupt::{Interrupt, InterruptExt}; | ||
| 7 | use embassy::time::driver::{AlarmHandle, Driver}; | 7 | use embassy::time::driver::{AlarmHandle, Driver}; |
| 8 | 8 | ||
| 9 | use crate::{interrupt, pac}; | 9 | use crate::{interrupt, pac}; |
diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs index 0d85be860..1aa3c5a84 100644 --- a/embassy-rp/src/uart.rs +++ b/embassy-rp/src/uart.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy::util::Unborrow; | 3 | use crate::Unborrow; |
| 4 | use embassy_hal_common::unborrow; | 4 | use embassy_hal_common::unborrow; |
| 5 | use gpio::Pin; | 5 | use gpio::Pin; |
| 6 | 6 | ||
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 01a96a5fb..4f83e4cd5 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -34,6 +34,7 @@ flavors = [ | |||
| 34 | 34 | ||
| 35 | [dependencies] | 35 | [dependencies] |
| 36 | embassy = { version = "0.1.0", path = "../embassy" } | 36 | embassy = { version = "0.1.0", path = "../embassy" } |
| 37 | embassy-cortex-m = { version = "0.1.0", path = "../embassy-cortex-m", features = ["prio-bits-4"]} | ||
| 37 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] } | 38 | embassy-macros = { version = "0.1.0", path = "../embassy-macros", features = ["stm32"] } |
| 38 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } | 39 | embassy-hal-common = {version = "0.1.0", path = "../embassy-hal-common" } |
| 39 | embassy-net = { version = "0.1.0", path = "../embassy-net", optional = true } | 40 | embassy-net = { version = "0.1.0", path = "../embassy-net", optional = true } |
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 7b1376f0b..42c88a269 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -96,8 +96,9 @@ fn main() { | |||
| 96 | g.extend(quote! { | 96 | g.extend(quote! { |
| 97 | pub mod interrupt { | 97 | pub mod interrupt { |
| 98 | use crate::pac::Interrupt as InterruptEnum; | 98 | use crate::pac::Interrupt as InterruptEnum; |
| 99 | use embassy_macros::cortex_m_interrupt_declare as declare; | ||
| 99 | #( | 100 | #( |
| 100 | embassy::interrupt::declare!(#irqs); | 101 | declare!(#irqs); |
| 101 | )* | 102 | )* |
| 102 | } | 103 | } |
| 103 | }); | 104 | }); |
diff --git a/embassy-stm32/src/adc/f1.rs b/embassy-stm32/src/adc/f1.rs index 6031883ec..ecb68b1a9 100644 --- a/embassy-stm32/src/adc/f1.rs +++ b/embassy-stm32/src/adc/f1.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use crate::adc::{AdcPin, Instance}; | 1 | use crate::adc::{AdcPin, Instance}; |
| 2 | use crate::rcc::get_freqs; | 2 | use crate::rcc::get_freqs; |
| 3 | use crate::time::Hertz; | 3 | use crate::time::Hertz; |
| 4 | use crate::Unborrow; | ||
| 4 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 5 | use embassy::util::Unborrow; | ||
| 6 | use embassy_hal_common::unborrow; | 6 | use embassy_hal_common::unborrow; |
| 7 | use embedded_hal_02::blocking::delay::DelayUs; | 7 | use embedded_hal_02::blocking::delay::DelayUs; |
| 8 | 8 | ||
diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs index ab71c0f52..cdb8dfe9e 100644 --- a/embassy-stm32/src/adc/v2.rs +++ b/embassy-stm32/src/adc/v2.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use crate::adc::{AdcPin, Instance}; | 1 | use crate::adc::{AdcPin, Instance}; |
| 2 | use crate::time::Hertz; | 2 | use crate::time::Hertz; |
| 3 | use crate::Unborrow; | ||
| 3 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
| 4 | use embassy::util::Unborrow; | ||
| 5 | use embassy_hal_common::unborrow; | 5 | use embassy_hal_common::unborrow; |
| 6 | use embedded_hal_02::blocking::delay::DelayUs; | 6 | use embedded_hal_02::blocking::delay::DelayUs; |
| 7 | 7 | ||
diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs index 68d941604..875510b7b 100644 --- a/embassy-stm32/src/adc/v3.rs +++ b/embassy-stm32/src/adc/v3.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use crate::adc::{AdcPin, Instance}; | 1 | use crate::adc::{AdcPin, Instance}; |
| 2 | use crate::Unborrow; | ||
| 2 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 3 | use embassy::util::Unborrow; | ||
| 4 | use embassy_hal_common::unborrow; | 4 | use embassy_hal_common::unborrow; |
| 5 | use embedded_hal_02::blocking::delay::DelayUs; | 5 | use embedded_hal_02::blocking::delay::DelayUs; |
| 6 | 6 | ||
diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs index 99326f38c..316e04e0c 100644 --- a/embassy-stm32/src/adc/v4.rs +++ b/embassy-stm32/src/adc/v4.rs | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use crate::time::{Hertz, U32Ext}; | 3 | use crate::time::{Hertz, U32Ext}; |
| 4 | use crate::Unborrow; | ||
| 4 | use atomic_polyfill::AtomicU8; | 5 | use atomic_polyfill::AtomicU8; |
| 5 | use atomic_polyfill::Ordering; | 6 | use atomic_polyfill::Ordering; |
| 6 | use embassy::util::Unborrow; | ||
| 7 | use embedded_hal_02::blocking::delay::DelayUs; | 7 | use embedded_hal_02::blocking::delay::DelayUs; |
| 8 | use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel}; | 8 | use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel}; |
| 9 | use pac::adccommon::vals::Presc; | 9 | use pac::adccommon::vals::Presc; |
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index c1de55393..0922d4d65 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | use core::ops::{Deref, DerefMut}; | 2 | use core::ops::{Deref, DerefMut}; |
| 3 | 3 | ||
| 4 | use embassy::util::Unborrow; | 4 | use crate::Unborrow; |
| 5 | use embassy_hal_common::unborrow; | 5 | use embassy_hal_common::unborrow; |
| 6 | 6 | ||
| 7 | use crate::gpio::sealed::AFType; | 7 | use crate::gpio::sealed::AFType; |
diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs index c657192e2..1ab4530b9 100644 --- a/embassy-stm32/src/crc/v1.rs +++ b/embassy-stm32/src/crc/v1.rs | |||
| @@ -3,7 +3,7 @@ use core::marker::PhantomData; | |||
| 3 | use crate::pac::CRC as PAC_CRC; | 3 | use crate::pac::CRC as PAC_CRC; |
| 4 | use crate::peripherals::CRC; | 4 | use crate::peripherals::CRC; |
| 5 | use crate::rcc::sealed::RccPeripheral; | 5 | use crate::rcc::sealed::RccPeripheral; |
| 6 | use embassy::util::Unborrow; | 6 | use crate::Unborrow; |
| 7 | use embassy_hal_common::unborrow; | 7 | use embassy_hal_common::unborrow; |
| 8 | 8 | ||
| 9 | pub struct Crc<'d> { | 9 | pub struct Crc<'d> { |
diff --git a/embassy-stm32/src/crc/v2v3.rs b/embassy-stm32/src/crc/v2v3.rs index 08e40a116..b6645c67f 100644 --- a/embassy-stm32/src/crc/v2v3.rs +++ b/embassy-stm32/src/crc/v2v3.rs | |||
| @@ -4,7 +4,7 @@ use crate::pac::crc::vals; | |||
| 4 | use crate::pac::CRC as PAC_CRC; | 4 | use crate::pac::CRC as PAC_CRC; |
| 5 | use crate::peripherals::CRC; | 5 | use crate::peripherals::CRC; |
| 6 | use crate::rcc::sealed::RccPeripheral; | 6 | use crate::rcc::sealed::RccPeripheral; |
| 7 | use embassy::util::Unborrow; | 7 | use crate::Unborrow; |
| 8 | use embassy_hal_common::unborrow; | 8 | use embassy_hal_common::unborrow; |
| 9 | 9 | ||
| 10 | pub struct Crc<'d> { | 10 | pub struct Crc<'d> { |
diff --git a/embassy-stm32/src/dac/v2.rs b/embassy-stm32/src/dac/v2.rs index ef64f60e9..0b421cc88 100644 --- a/embassy-stm32/src/dac/v2.rs +++ b/embassy-stm32/src/dac/v2.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use crate::dac::{DacPin, Instance}; | 1 | use crate::dac::{DacPin, Instance}; |
| 2 | use crate::pac::dac; | 2 | use crate::pac::dac; |
| 3 | use crate::Unborrow; | ||
| 3 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
| 4 | use embassy::util::Unborrow; | ||
| 5 | use embassy_hal_common::unborrow; | 5 | use embassy_hal_common::unborrow; |
| 6 | 6 | ||
| 7 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | 7 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs index e70db90c0..8a28ca4b2 100644 --- a/embassy-stm32/src/dcmi.rs +++ b/embassy-stm32/src/dcmi.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | use core::task::Poll; | 2 | use core::task::Poll; |
| 3 | 3 | ||
| 4 | use embassy::interrupt::{Interrupt, InterruptExt}; | 4 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 5 | use embassy::util::Unborrow; | 5 | use crate::Unborrow; |
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::unborrow; | 7 | use embassy_hal_common::unborrow; |
| 8 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index 413285320..b17d22953 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | use core::sync::atomic::{fence, Ordering}; | 3 | use core::sync::atomic::{fence, Ordering}; |
| 4 | use core::task::Waker; | 4 | use core::task::Waker; |
| 5 | 5 | ||
| 6 | use embassy::interrupt::{Interrupt, InterruptExt}; | 6 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 7 | use embassy::waitqueue::AtomicWaker; | 7 | use embassy::waitqueue::AtomicWaker; |
| 8 | 8 | ||
| 9 | use crate::_generated::BDMA_CHANNEL_COUNT; | 9 | use crate::_generated::BDMA_CHANNEL_COUNT; |
diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index bc796c541..04cde7b4b 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::sync::atomic::{fence, Ordering}; | 1 | use core::sync::atomic::{fence, Ordering}; |
| 2 | use core::task::Waker; | 2 | use core::task::Waker; |
| 3 | 3 | ||
| 4 | use embassy::interrupt::{Interrupt, InterruptExt}; | 4 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 5 | use embassy::waitqueue::AtomicWaker; | 5 | use embassy::waitqueue::AtomicWaker; |
| 6 | 6 | ||
| 7 | use crate::_generated::DMA_CHANNEL_COUNT; | 7 | use crate::_generated::DMA_CHANNEL_COUNT; |
diff --git a/embassy-stm32/src/dma/gpdma.rs b/embassy-stm32/src/dma/gpdma.rs index 0cb986b32..b054f95cc 100644 --- a/embassy-stm32/src/dma/gpdma.rs +++ b/embassy-stm32/src/dma/gpdma.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::sync::atomic::{fence, Ordering}; | 1 | use core::sync::atomic::{fence, Ordering}; |
| 2 | use core::task::Waker; | 2 | use core::task::Waker; |
| 3 | 3 | ||
| 4 | use embassy::interrupt::{Interrupt, InterruptExt}; | 4 | use crate::interrupt::{Interrupt, InterruptExt}; |
| 5 | use embassy::waitqueue::AtomicWaker; | 5 | use embassy::waitqueue::AtomicWaker; |
| 6 | 6 | ||
| 7 | use crate::_generated::GPDMA_CHANNEL_COUNT; | 7 | use crate::_generated::GPDMA_CHANNEL_COUNT; |
diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index c19f7b3c7..3a9097784 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs | |||
| @@ -10,13 +10,13 @@ mod gpdma; | |||
| 10 | #[cfg(dmamux)] | 10 | #[cfg(dmamux)] |
| 11 | pub use dmamux::*; | 11 | pub use dmamux::*; |
| 12 | 12 | ||
| 13 | use crate::Unborrow; | ||
| 13 | use core::future::Future; | 14 | use core::future::Future; |
| 14 | use core::marker::PhantomData; | 15 | use core::marker::PhantomData; |
| 15 | use core::mem; | 16 | use core::mem; |
| 16 | use core::pin::Pin; | 17 | use core::pin::Pin; |
| 17 | use core::task::Waker; | 18 | use core::task::Waker; |
| 18 | use core::task::{Context, Poll}; | 19 | use core::task::{Context, Poll}; |
| 19 | use embassy::util::Unborrow; | ||
| 20 | use embassy_hal_common::unborrow; | 20 | use embassy_hal_common::unborrow; |
| 21 | 21 | ||
| 22 | #[cfg(feature = "unstable-pac")] | 22 | #[cfg(feature = "unstable-pac")] |
diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index 327deea2a..d2cfb17c0 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs | |||
| @@ -4,9 +4,9 @@ use core::marker::PhantomData; | |||
| 4 | use core::sync::atomic::{fence, Ordering}; | 4 | use core::sync::atomic::{fence, Ordering}; |
| 5 | use core::task::Waker; | 5 | use core::task::Waker; |
| 6 | 6 | ||
| 7 | use embassy::util::Unborrow; | 7 | use crate::Unborrow; |
| 8 | use embassy::waitqueue::AtomicWaker; | 8 | use embassy::waitqueue::AtomicWaker; |
| 9 | use embassy_hal_common::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 9 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 10 | use embassy_hal_common::unborrow; | 10 | use embassy_hal_common::unborrow; |
| 11 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; | 11 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; |
| 12 | 12 | ||
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index 6a49904d1..e438a7b5e 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs | |||
| @@ -2,9 +2,9 @@ use core::marker::PhantomData; | |||
| 2 | use core::sync::atomic::{fence, Ordering}; | 2 | use core::sync::atomic::{fence, Ordering}; |
| 3 | use core::task::Waker; | 3 | use core::task::Waker; |
| 4 | 4 | ||
| 5 | use embassy::util::Unborrow; | 5 | use crate::Unborrow; |
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 7 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 8 | use embassy_hal_common::unborrow; | 8 | use embassy_hal_common::unborrow; |
| 9 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; | 9 | use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; |
| 10 | 10 | ||
diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index d065a5557..efe54e59a 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use crate::Unborrow; | ||
| 1 | use core::future::Future; | 2 | use core::future::Future; |
| 2 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 3 | use core::pin::Pin; | 4 | use core::pin::Pin; |
| 4 | use core::task::{Context, Poll}; | 5 | use core::task::{Context, Poll}; |
| 5 | use embassy::util::Unborrow; | ||
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::unsafe_impl_unborrow; | 7 | use embassy_hal_common::unsafe_impl_unborrow; |
| 8 | 8 | ||
| @@ -366,8 +366,8 @@ macro_rules! enable_irq { | |||
| 366 | 366 | ||
| 367 | /// safety: must be called only once | 367 | /// safety: must be called only once |
| 368 | pub(crate) unsafe fn init() { | 368 | pub(crate) unsafe fn init() { |
| 369 | use embassy::interrupt::Interrupt; | 369 | use crate::interrupt::Interrupt; |
| 370 | use embassy::interrupt::InterruptExt; | 370 | use crate::interrupt::InterruptExt; |
| 371 | 371 | ||
| 372 | foreach_exti_irq!(enable_irq); | 372 | foreach_exti_irq!(enable_irq); |
| 373 | 373 | ||
diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs index 4be611d2e..330e51421 100644 --- a/embassy-stm32/src/flash/mod.rs +++ b/embassy-stm32/src/flash/mod.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use crate::peripherals::FLASH; | 1 | use crate::peripherals::FLASH; |
| 2 | use crate::Unborrow; | ||
| 2 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 3 | use embassy::util::Unborrow; | ||
| 4 | use embassy_hal_common::unborrow; | 4 | use embassy_hal_common::unborrow; |
| 5 | 5 | ||
| 6 | use embedded_storage::nor_flash::{ | 6 | use embedded_storage::nor_flash::{ |
diff --git a/embassy-stm32/src/fmc/mod.rs b/embassy-stm32/src/fmc/mod.rs index 2a730f5f8..c227cfa17 100644 --- a/embassy-stm32/src/fmc/mod.rs +++ b/embassy-stm32/src/fmc/mod.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | use crate::Unborrow; | ||
| 1 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 2 | use embassy::util::Unborrow; | ||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 4 | 4 | ||
| 5 | use crate::gpio::sealed::AFType; | 5 | use crate::gpio::sealed::AFType; |
diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index f7a5da0a8..31f22e21b 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | use crate::Unborrow; | ||
| 2 | use core::convert::Infallible; | 3 | use core::convert::Infallible; |
| 3 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
| 4 | use embassy::util::Unborrow; | ||
| 5 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; | 5 | use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; |
| 6 | 6 | ||
| 7 | use crate::pac; | 7 | use crate::pac; |
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index c2a4c2546..54f8d1935 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use embassy::interrupt::Interrupt; | 3 | use crate::interrupt::Interrupt; |
| 4 | 4 | ||
| 5 | #[cfg_attr(i2c_v1, path = "v1.rs")] | 5 | #[cfg_attr(i2c_v1, path = "v1.rs")] |
| 6 | #[cfg_attr(i2c_v2, path = "v2.rs")] | 6 | #[cfg_attr(i2c_v2, path = "v2.rs")] |
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index e0b151142..77acc3870 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | use crate::Unborrow; | ||
| 1 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 2 | use embassy::util::Unborrow; | ||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 4 | 4 | ||
| 5 | use crate::gpio::sealed::AFType; | 5 | use crate::gpio::sealed::AFType; |
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index f3714cbcb..4d4840a0d 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs | |||
| @@ -2,9 +2,9 @@ use core::cmp; | |||
| 2 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 3 | use core::task::Poll; | 3 | use core::task::Poll; |
| 4 | 4 | ||
| 5 | use crate::interrupt::InterruptExt; | ||
| 6 | use crate::Unborrow; | ||
| 5 | use atomic_polyfill::{AtomicUsize, Ordering}; | 7 | use atomic_polyfill::{AtomicUsize, Ordering}; |
| 6 | use embassy::interrupt::InterruptExt; | ||
| 7 | use embassy::util::Unborrow; | ||
| 8 | use embassy::waitqueue::AtomicWaker; | 8 | use embassy::waitqueue::AtomicWaker; |
| 9 | use embassy_hal_common::drop::OnDrop; | 9 | use embassy_hal_common::drop::OnDrop; |
| 10 | use embassy_hal_common::unborrow; | 10 | use embassy_hal_common::unborrow; |
diff --git a/embassy-stm32/src/interrupt.rs b/embassy-stm32/src/interrupt.rs index 714dcc4ca..9dc1f2044 100644 --- a/embassy-stm32/src/interrupt.rs +++ b/embassy-stm32/src/interrupt.rs | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | pub use bare_metal::Mutex; | 1 | pub use bare_metal::Mutex; |
| 2 | pub use critical_section::CriticalSection; | 2 | pub use critical_section::CriticalSection; |
| 3 | pub use embassy::interrupt::{take, Interrupt}; | 3 | pub use embassy_cortex_m::interrupt::*; |
| 4 | pub use embassy_hal_common::interrupt::Priority4 as Priority; | ||
| 5 | 4 | ||
| 6 | pub use crate::_generated::interrupt::*; | 5 | pub use crate::_generated::interrupt::*; |
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index bb70faab1..b795352c1 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -4,14 +4,6 @@ | |||
| 4 | feature(generic_associated_types, type_alias_impl_trait) | 4 | feature(generic_associated_types, type_alias_impl_trait) |
| 5 | )] | 5 | )] |
| 6 | 6 | ||
| 7 | #[cfg(feature = "unstable-pac")] | ||
| 8 | pub use stm32_metapac as pac; | ||
| 9 | #[cfg(not(feature = "unstable-pac"))] | ||
| 10 | pub(crate) use stm32_metapac as pac; | ||
| 11 | |||
| 12 | pub use embassy::util::Unborrow; | ||
| 13 | pub use embassy_hal_common::unborrow; | ||
| 14 | |||
| 15 | // This must go FIRST so that all the other modules see its macros. | 7 | // This must go FIRST so that all the other modules see its macros. |
| 16 | pub mod fmt; | 8 | pub mod fmt; |
| 17 | include!(concat!(env!("OUT_DIR"), "/_macros.rs")); | 9 | include!(concat!(env!("OUT_DIR"), "/_macros.rs")); |
| @@ -79,8 +71,17 @@ pub(crate) mod _generated { | |||
| 79 | 71 | ||
| 80 | include!(concat!(env!("OUT_DIR"), "/_generated.rs")); | 72 | include!(concat!(env!("OUT_DIR"), "/_generated.rs")); |
| 81 | } | 73 | } |
| 74 | |||
| 75 | // Reexports | ||
| 82 | pub use _generated::{peripherals, Peripherals}; | 76 | pub use _generated::{peripherals, Peripherals}; |
| 83 | pub use embassy_macros::interrupt; | 77 | pub use embassy_cortex_m::executor; |
| 78 | pub use embassy_hal_common::{unborrow, Unborrow}; | ||
| 79 | pub use embassy_macros::cortex_m_interrupt as interrupt; | ||
| 80 | |||
| 81 | #[cfg(feature = "unstable-pac")] | ||
| 82 | pub use stm32_metapac as pac; | ||
| 83 | #[cfg(not(feature = "unstable-pac"))] | ||
| 84 | pub(crate) use stm32_metapac as pac; | ||
| 84 | 85 | ||
| 85 | #[non_exhaustive] | 86 | #[non_exhaustive] |
| 86 | pub struct Config { | 87 | pub struct Config { |
diff --git a/embassy-stm32/src/pwm/simple_pwm.rs b/embassy-stm32/src/pwm/simple_pwm.rs index 3706cc5ba..990f5bda7 100644 --- a/embassy-stm32/src/pwm/simple_pwm.rs +++ b/embassy-stm32/src/pwm/simple_pwm.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | use crate::Unborrow; | ||
| 1 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 2 | use embassy::util::Unborrow; | ||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 4 | 4 | ||
| 5 | use super::*; | 5 | use super::*; |
diff --git a/embassy-stm32/src/rcc/h7.rs b/embassy-stm32/src/rcc/h7.rs index 6c81d3dbd..0cd89645f 100644 --- a/embassy-stm32/src/rcc/h7.rs +++ b/embassy-stm32/src/rcc/h7.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | 2 | ||
| 3 | use embassy::util::Unborrow; | 3 | use crate::Unborrow; |
| 4 | use embassy_hal_common::unborrow; | 4 | use embassy_hal_common::unborrow; |
| 5 | use stm32_metapac::rcc::vals::{Mco1, Mco2}; | 5 | use stm32_metapac::rcc::vals::{Mco1, Mco2}; |
| 6 | 6 | ||
diff --git a/embassy-stm32/src/rcc/l5.rs b/embassy-stm32/src/rcc/l5.rs index dba5ec3b7..4419f3d31 100644 --- a/embassy-stm32/src/rcc/l5.rs +++ b/embassy-stm32/src/rcc/l5.rs | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | use stm32_metapac::PWR; | ||
| 2 | |||
| 1 | use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; | 3 | use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; |
| 2 | use crate::pac::{FLASH, RCC}; | 4 | use crate::pac::{FLASH, RCC}; |
| 3 | use crate::rcc::{set_freqs, Clocks}; | 5 | use crate::rcc::{set_freqs, Clocks}; |
| @@ -295,6 +297,8 @@ impl Default for Config { | |||
| 295 | } | 297 | } |
| 296 | 298 | ||
| 297 | pub(crate) unsafe fn init(config: Config) { | 299 | pub(crate) unsafe fn init(config: Config) { |
| 300 | PWR.cr1() | ||
| 301 | .modify(|w| w.set_vos(stm32_metapac::pwr::vals::Vos::RANGE0)); | ||
| 298 | let (sys_clk, sw) = match config.mux { | 302 | let (sys_clk, sw) = match config.mux { |
| 299 | ClockSrc::MSI(range) => { | 303 | ClockSrc::MSI(range) => { |
| 300 | // Enable MSI | 304 | // Enable MSI |
diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index 0a93951bf..e74b66237 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::Unborrow; | ||
| 3 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
| 4 | use core::task::Poll; | 5 | use core::task::Poll; |
| 5 | use embassy::util::Unborrow; | ||
| 6 | use embassy::waitqueue::AtomicWaker; | 6 | use embassy::waitqueue::AtomicWaker; |
| 7 | use embassy_hal_common::unborrow; | 7 | use embassy_hal_common::unborrow; |
| 8 | use futures::future::poll_fn; | 8 | use futures::future::poll_fn; |
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index f983c6759..a7290e74c 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs | |||
| @@ -4,8 +4,8 @@ use core::default::Default; | |||
| 4 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
| 5 | use core::task::Poll; | 5 | use core::task::Poll; |
| 6 | 6 | ||
| 7 | use embassy::interrupt::InterruptExt; | 7 | use crate::interrupt::InterruptExt; |
| 8 | use embassy::util::Unborrow; | 8 | use crate::Unborrow; |
| 9 | use embassy::waitqueue::AtomicWaker; | 9 | use embassy::waitqueue::AtomicWaker; |
| 10 | use embassy_hal_common::drop::OnDrop; | 10 | use embassy_hal_common::drop::OnDrop; |
| 11 | use embassy_hal_common::unborrow; | 11 | use embassy_hal_common::unborrow; |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 23240ad82..3cdc87c70 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::Unborrow; | ||
| 3 | use core::marker::PhantomData; | 4 | use core::marker::PhantomData; |
| 4 | use core::ptr; | 5 | use core::ptr; |
| 5 | use embassy::util::Unborrow; | ||
| 6 | use embassy_hal_common::unborrow; | 6 | use embassy_hal_common::unborrow; |
| 7 | use futures::future::join; | 7 | use futures::future::join; |
| 8 | 8 | ||
diff --git a/embassy-stm32/src/subghz/mod.rs b/embassy-stm32/src/subghz/mod.rs index 9c8b7f7ec..6736324ce 100644 --- a/embassy-stm32/src/subghz/mod.rs +++ b/embassy-stm32/src/subghz/mod.rs | |||
| @@ -77,6 +77,7 @@ pub use value_error::ValueError; | |||
| 77 | 77 | ||
| 78 | use embassy_hal_common::ratio::Ratio; | 78 | use embassy_hal_common::ratio::Ratio; |
| 79 | 79 | ||
| 80 | use crate::Unborrow; | ||
| 80 | use crate::{ | 81 | use crate::{ |
| 81 | dma::NoDma, | 82 | dma::NoDma, |
| 82 | pac, | 83 | pac, |
| @@ -85,7 +86,6 @@ use crate::{ | |||
| 85 | spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0}, | 86 | spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0}, |
| 86 | time::Hertz, | 87 | time::Hertz, |
| 87 | }; | 88 | }; |
| 88 | use embassy::util::Unborrow; | ||
| 89 | 89 | ||
| 90 | /// Passthrough for SPI errors (for now) | 90 | /// Passthrough for SPI errors (for now) |
| 91 | pub type Error = crate::spi::Error; | 91 | pub type Error = crate::spi::Error; |
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index d936a11a2..b63ed5bd4 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | use crate::interrupt::InterruptExt; | ||
| 1 | use atomic_polyfill::{AtomicU32, AtomicU8}; | 2 | use atomic_polyfill::{AtomicU32, AtomicU8}; |
| 2 | use core::cell::Cell; | 3 | use core::cell::Cell; |
| 3 | use core::convert::TryInto; | 4 | use core::convert::TryInto; |
| @@ -5,7 +6,6 @@ use core::sync::atomic::{compiler_fence, Ordering}; | |||
| 5 | use core::{mem, ptr}; | 6 | use core::{mem, ptr}; |
| 6 | use embassy::blocking_mutex::raw::CriticalSectionRawMutex; | 7 | use embassy::blocking_mutex::raw::CriticalSectionRawMutex; |
| 7 | use embassy::blocking_mutex::Mutex; | 8 | use embassy::blocking_mutex::Mutex; |
| 8 | use embassy::interrupt::InterruptExt; | ||
| 9 | use embassy::time::driver::{AlarmHandle, Driver}; | 9 | use embassy::time::driver::{AlarmHandle, Driver}; |
| 10 | use embassy::time::TICKS_PER_SECOND; | 10 | use embassy::time::TICKS_PER_SECOND; |
| 11 | use stm32_metapac::timer::regs; | 11 | use stm32_metapac::timer::regs; |
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index f9fefdf73..3cc6298be 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | use embassy::interrupt::Interrupt; | 1 | use crate::interrupt::Interrupt; |
| 2 | 2 | ||
| 3 | use crate::rcc::{sealed::RccPeripheral as __RccPeri, RccPeripheral}; | 3 | use crate::rcc::{sealed::RccPeripheral as __RccPeri, RccPeripheral}; |
| 4 | use crate::time::Hertz; | 4 | use crate::time::Hertz; |
diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index 36d176b91..e2c9f7802 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs | |||
| @@ -2,7 +2,7 @@ use atomic_polyfill::{compiler_fence, Ordering}; | |||
| 2 | use core::future::Future; | 2 | use core::future::Future; |
| 3 | use core::task::Poll; | 3 | use core::task::Poll; |
| 4 | use embassy::waitqueue::WakerRegistration; | 4 | use embassy::waitqueue::WakerRegistration; |
| 5 | use embassy_hal_common::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; | 5 | use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; |
| 6 | use embassy_hal_common::ring_buffer::RingBuffer; | 6 | use embassy_hal_common::ring_buffer::RingBuffer; |
| 7 | use futures::future::poll_fn; | 7 | use futures::future::poll_fn; |
| 8 | 8 | ||
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 472680113..2acec874f 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::interrupt::Interrupt; | ||
| 4 | use crate::Unborrow; | ||
| 3 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 4 | use embassy::interrupt::Interrupt; | ||
| 5 | use embassy::util::Unborrow; | ||
| 6 | use embassy_hal_common::unborrow; | 6 | use embassy_hal_common::unborrow; |
| 7 | 7 | ||
| 8 | use crate::dma::NoDma; | 8 | use crate::dma::NoDma; |
diff --git a/embassy-stm32/src/usb/mod.rs b/embassy-stm32/src/usb/mod.rs index 71b407cbd..65451917e 100644 --- a/embassy-stm32/src/usb/mod.rs +++ b/embassy-stm32/src/usb/mod.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | use embassy::interrupt::Interrupt; | 1 | use crate::interrupt::Interrupt; |
| 2 | 2 | ||
| 3 | use crate::rcc::RccPeripheral; | 3 | use crate::rcc::RccPeripheral; |
| 4 | 4 | ||
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index 113b20262..eaf24f8ae 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use crate::interrupt::InterruptExt; | ||
| 4 | use crate::Unborrow; | ||
| 3 | use atomic_polyfill::{AtomicBool, AtomicU8}; | 5 | use atomic_polyfill::{AtomicBool, AtomicU8}; |
| 4 | use core::marker::PhantomData; | 6 | use core::marker::PhantomData; |
| 5 | use core::sync::atomic::Ordering; | 7 | use core::sync::atomic::Ordering; |
| 6 | use core::task::Poll; | 8 | use core::task::Poll; |
| 7 | use embassy::interrupt::InterruptExt; | ||
| 8 | use embassy::time::{block_for, Duration}; | 9 | use embassy::time::{block_for, Duration}; |
| 9 | use embassy::util::Unborrow; | ||
| 10 | use embassy::waitqueue::AtomicWaker; | 10 | use embassy::waitqueue::AtomicWaker; |
| 11 | use embassy_hal_common::unborrow; | 11 | use embassy_hal_common::unborrow; |
| 12 | use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported}; | 12 | use embassy_usb::driver::{self, EndpointAllocError, EndpointError, Event, Unsupported}; |
diff --git a/embassy-stm32/src/usb_otg.rs b/embassy-stm32/src/usb_otg.rs index c3cd776ca..0f732965c 100644 --- a/embassy-stm32/src/usb_otg.rs +++ b/embassy-stm32/src/usb_otg.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | use crate::Unborrow; | ||
| 1 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 2 | use embassy::util::Unborrow; | ||
| 3 | use embassy_hal_common::unborrow; | 3 | use embassy_hal_common::unborrow; |
| 4 | 4 | ||
| 5 | use crate::gpio::sealed::AFType; | 5 | use crate::gpio::sealed::AFType; |
diff --git a/embassy/src/executor/arch/cortex_m.rs b/embassy/src/executor/arch/cortex_m.rs index 16f290083..cf80389b6 100644 --- a/embassy/src/executor/arch/cortex_m.rs +++ b/embassy/src/executor/arch/cortex_m.rs | |||
| @@ -1,8 +1,7 @@ | |||
| 1 | use core::marker::PhantomData; | 1 | use core::marker::PhantomData; |
| 2 | use core::ptr; | 2 | use core::ptr; |
| 3 | 3 | ||
| 4 | use super::{raw, SendSpawner, Spawner}; | 4 | use super::{raw, Spawner}; |
| 5 | use crate::interrupt::{Interrupt, InterruptExt}; | ||
| 6 | 5 | ||
| 7 | /// Thread mode executor, using WFE/SEV. | 6 | /// Thread mode executor, using WFE/SEV. |
| 8 | /// | 7 | /// |
| @@ -55,86 +54,3 @@ impl Executor { | |||
| 55 | } | 54 | } |
| 56 | } | 55 | } |
| 57 | } | 56 | } |
| 58 | |||
| 59 | fn pend_by_number(n: u16) { | ||
| 60 | #[derive(Clone, Copy)] | ||
| 61 | struct N(u16); | ||
| 62 | unsafe impl cortex_m::interrupt::InterruptNumber for N { | ||
| 63 | fn number(self) -> u16 { | ||
| 64 | self.0 | ||
| 65 | } | ||
| 66 | } | ||
| 67 | cortex_m::peripheral::NVIC::pend(N(n)) | ||
| 68 | } | ||
| 69 | |||
| 70 | /// Interrupt mode executor. | ||
| 71 | /// | ||
| 72 | /// This executor runs tasks in interrupt mode. The interrupt handler is set up | ||
| 73 | /// to poll tasks, and when a task is woken the interrupt is pended from software. | ||
| 74 | /// | ||
| 75 | /// This allows running async tasks at a priority higher than thread mode. One | ||
| 76 | /// use case is to leave thread mode free for non-async tasks. Another use case is | ||
| 77 | /// to run multiple executors: one in thread mode for low priority tasks and another in | ||
| 78 | /// interrupt mode for higher priority tasks. Higher priority tasks will preempt lower | ||
| 79 | /// priority ones. | ||
| 80 | /// | ||
| 81 | /// It is even possible to run multiple interrupt mode executors at different priorities, | ||
| 82 | /// by assigning different priorities to the interrupts. For an example on how to do this, | ||
| 83 | /// See the 'multiprio' example for 'embassy-nrf'. | ||
| 84 | /// | ||
| 85 | /// To use it, you have to pick an interrupt that won't be used by the hardware. | ||
| 86 | /// Some chips reserve some interrupts for this purpose, sometimes named "software interrupts" (SWI). | ||
| 87 | /// If this is not the case, you may use an interrupt from any unused peripheral. | ||
| 88 | /// | ||
| 89 | /// It is somewhat more complex to use, it's recommended to use the thread-mode | ||
| 90 | /// [`Executor`] instead, if it works for your use case. | ||
| 91 | pub struct InterruptExecutor<I: Interrupt> { | ||
| 92 | irq: I, | ||
| 93 | inner: raw::Executor, | ||
| 94 | not_send: PhantomData<*mut ()>, | ||
| 95 | } | ||
| 96 | |||
| 97 | impl<I: Interrupt> InterruptExecutor<I> { | ||
| 98 | /// Create a new Executor. | ||
| 99 | pub fn new(irq: I) -> Self { | ||
| 100 | let ctx = irq.number() as *mut (); | ||
| 101 | Self { | ||
| 102 | irq, | ||
| 103 | inner: raw::Executor::new(|ctx| pend_by_number(ctx as u16), ctx), | ||
| 104 | not_send: PhantomData, | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | /// Start the executor. | ||
| 109 | /// | ||
| 110 | /// This initializes the executor, configures and enables the interrupt, and returns. | ||
| 111 | /// The executor keeps running in the background through the interrupt. | ||
| 112 | /// | ||
| 113 | /// This returns a [`SendSpawner`] you can use to spawn tasks on it. A [`SendSpawner`] | ||
| 114 | /// is returned instead of a [`Spawner`] because the executor effectively runs in a | ||
| 115 | /// different "thread" (the interrupt), so spawning tasks on it is effectively | ||
| 116 | /// sending them. | ||
| 117 | /// | ||
| 118 | /// To obtain a [`Spawner`] for this executor, use [`Spawner::for_current_executor`] from | ||
| 119 | /// a task running in it. | ||
| 120 | /// | ||
| 121 | /// This function requires `&'static mut self`. This means you have to store the | ||
| 122 | /// Executor instance in a place where it'll live forever and grants you mutable | ||
| 123 | /// access. There's a few ways to do this: | ||
| 124 | /// | ||
| 125 | /// - a [Forever](crate::util::Forever) (safe) | ||
| 126 | /// - a `static mut` (unsafe) | ||
| 127 | /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe) | ||
| 128 | pub fn start(&'static mut self) -> SendSpawner { | ||
| 129 | self.irq.disable(); | ||
| 130 | |||
| 131 | self.irq.set_handler(|ctx| unsafe { | ||
| 132 | let executor = &*(ctx as *const raw::Executor); | ||
| 133 | executor.poll(); | ||
| 134 | }); | ||
| 135 | self.irq.set_handler_context(&self.inner as *const _ as _); | ||
| 136 | self.irq.enable(); | ||
| 137 | |||
| 138 | self.inner.spawner().make_send() | ||
| 139 | } | ||
| 140 | } | ||
diff --git a/embassy/src/interrupt.rs b/embassy/src/interrupt.rs deleted file mode 100644 index 7848ee698..000000000 --- a/embassy/src/interrupt.rs +++ /dev/null | |||
| @@ -1,131 +0,0 @@ | |||
| 1 | use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; | ||
| 2 | use core::mem; | ||
| 3 | use core::ptr; | ||
| 4 | use cortex_m::peripheral::NVIC; | ||
| 5 | |||
| 6 | pub use embassy_macros::interrupt_declare as declare; | ||
| 7 | pub use embassy_macros::interrupt_take as take; | ||
| 8 | |||
| 9 | /// Implementation detail, do not use outside embassy crates. | ||
| 10 | #[doc(hidden)] | ||
| 11 | pub struct Handler { | ||
| 12 | pub func: AtomicPtr<()>, | ||
| 13 | pub ctx: AtomicPtr<()>, | ||
| 14 | } | ||
| 15 | |||
| 16 | impl Handler { | ||
| 17 | pub const fn new() -> Self { | ||
| 18 | Self { | ||
| 19 | func: AtomicPtr::new(ptr::null_mut()), | ||
| 20 | ctx: AtomicPtr::new(ptr::null_mut()), | ||
| 21 | } | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | #[derive(Clone, Copy)] | ||
| 26 | pub(crate) struct NrWrap(pub(crate) u16); | ||
| 27 | unsafe impl cortex_m::interrupt::InterruptNumber for NrWrap { | ||
| 28 | fn number(self) -> u16 { | ||
| 29 | self.0 | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | pub unsafe trait Interrupt: crate::util::Unborrow<Target = Self> { | ||
| 34 | type Priority: From<u8> + Into<u8> + Copy; | ||
| 35 | fn number(&self) -> u16; | ||
| 36 | unsafe fn steal() -> Self; | ||
| 37 | |||
| 38 | /// Implementation detail, do not use outside embassy crates. | ||
| 39 | #[doc(hidden)] | ||
| 40 | unsafe fn __handler(&self) -> &'static Handler; | ||
| 41 | } | ||
| 42 | |||
| 43 | pub trait InterruptExt: Interrupt { | ||
| 44 | fn set_handler(&self, func: unsafe fn(*mut ())); | ||
| 45 | fn remove_handler(&self); | ||
| 46 | fn set_handler_context(&self, ctx: *mut ()); | ||
| 47 | fn enable(&self); | ||
| 48 | fn disable(&self); | ||
| 49 | #[cfg(not(armv6m))] | ||
| 50 | fn is_active(&self) -> bool; | ||
| 51 | fn is_enabled(&self) -> bool; | ||
| 52 | fn is_pending(&self) -> bool; | ||
| 53 | fn pend(&self); | ||
| 54 | fn unpend(&self); | ||
| 55 | fn get_priority(&self) -> Self::Priority; | ||
| 56 | fn set_priority(&self, prio: Self::Priority); | ||
| 57 | } | ||
| 58 | |||
| 59 | impl<T: Interrupt + ?Sized> InterruptExt for T { | ||
| 60 | fn set_handler(&self, func: unsafe fn(*mut ())) { | ||
| 61 | compiler_fence(Ordering::SeqCst); | ||
| 62 | let handler = unsafe { self.__handler() }; | ||
| 63 | handler.func.store(func as *mut (), Ordering::Relaxed); | ||
| 64 | compiler_fence(Ordering::SeqCst); | ||
| 65 | } | ||
| 66 | |||
| 67 | fn remove_handler(&self) { | ||
| 68 | compiler_fence(Ordering::SeqCst); | ||
| 69 | let handler = unsafe { self.__handler() }; | ||
| 70 | handler.func.store(ptr::null_mut(), Ordering::Relaxed); | ||
| 71 | compiler_fence(Ordering::SeqCst); | ||
| 72 | } | ||
| 73 | |||
| 74 | fn set_handler_context(&self, ctx: *mut ()) { | ||
| 75 | let handler = unsafe { self.__handler() }; | ||
| 76 | handler.ctx.store(ctx, Ordering::Relaxed); | ||
| 77 | } | ||
| 78 | |||
| 79 | #[inline] | ||
| 80 | fn enable(&self) { | ||
| 81 | compiler_fence(Ordering::SeqCst); | ||
| 82 | unsafe { | ||
| 83 | NVIC::unmask(NrWrap(self.number())); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | #[inline] | ||
| 88 | fn disable(&self) { | ||
| 89 | NVIC::mask(NrWrap(self.number())); | ||
| 90 | compiler_fence(Ordering::SeqCst); | ||
| 91 | } | ||
| 92 | |||
| 93 | #[inline] | ||
| 94 | #[cfg(not(armv6m))] | ||
| 95 | fn is_active(&self) -> bool { | ||
| 96 | NVIC::is_active(NrWrap(self.number())) | ||
| 97 | } | ||
| 98 | |||
| 99 | #[inline] | ||
| 100 | fn is_enabled(&self) -> bool { | ||
| 101 | NVIC::is_enabled(NrWrap(self.number())) | ||
| 102 | } | ||
| 103 | |||
| 104 | #[inline] | ||
| 105 | fn is_pending(&self) -> bool { | ||
| 106 | NVIC::is_pending(NrWrap(self.number())) | ||
| 107 | } | ||
| 108 | |||
| 109 | #[inline] | ||
| 110 | fn pend(&self) { | ||
| 111 | NVIC::pend(NrWrap(self.number())) | ||
| 112 | } | ||
| 113 | |||
| 114 | #[inline] | ||
| 115 | fn unpend(&self) { | ||
| 116 | NVIC::unpend(NrWrap(self.number())) | ||
| 117 | } | ||
| 118 | |||
| 119 | #[inline] | ||
| 120 | fn get_priority(&self) -> Self::Priority { | ||
| 121 | Self::Priority::from(NVIC::get_priority(NrWrap(self.number()))) | ||
| 122 | } | ||
| 123 | |||
| 124 | #[inline] | ||
| 125 | fn set_priority(&self, prio: Self::Priority) { | ||
| 126 | unsafe { | ||
| 127 | let mut nvic: cortex_m::peripheral::NVIC = mem::transmute(()); | ||
| 128 | nvic.set_priority(NrWrap(self.number()), prio.into()) | ||
| 129 | } | ||
| 130 | } | ||
| 131 | } | ||
diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs index 087bd357a..5cfd18db7 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs | |||
| @@ -11,8 +11,6 @@ pub(crate) mod fmt; | |||
| 11 | pub mod blocking_mutex; | 11 | pub mod blocking_mutex; |
| 12 | pub mod channel; | 12 | pub mod channel; |
| 13 | pub mod executor; | 13 | pub mod executor; |
| 14 | #[cfg(cortex_m)] | ||
| 15 | pub mod interrupt; | ||
| 16 | pub mod mutex; | 14 | pub mod mutex; |
| 17 | #[cfg(feature = "time")] | 15 | #[cfg(feature = "time")] |
| 18 | pub mod time; | 16 | pub mod time; |
diff --git a/embassy/src/util/mod.rs b/embassy/src/util/mod.rs index 928edf0e2..4d59147c1 100644 --- a/embassy/src/util/mod.rs +++ b/embassy/src/util/mod.rs | |||
| @@ -3,11 +3,9 @@ | |||
| 3 | mod forever; | 3 | mod forever; |
| 4 | mod select; | 4 | mod select; |
| 5 | mod steal; | 5 | mod steal; |
| 6 | mod unborrow; | ||
| 7 | mod yield_now; | 6 | mod yield_now; |
| 8 | 7 | ||
| 9 | pub use forever::*; | 8 | pub use forever::*; |
| 10 | pub use select::*; | 9 | pub use select::*; |
| 11 | pub use steal::*; | 10 | pub use steal::*; |
| 12 | pub use unborrow::*; | ||
| 13 | pub use yield_now::*; | 11 | pub use yield_now::*; |
diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs index 54f6606a9..abda18aa5 100644 --- a/examples/nrf/src/bin/multiprio.rs +++ b/examples/nrf/src/bin/multiprio.rs | |||
| @@ -59,11 +59,11 @@ | |||
| 59 | 59 | ||
| 60 | use cortex_m_rt::entry; | 60 | use cortex_m_rt::entry; |
| 61 | use defmt::{info, unwrap}; | 61 | use defmt::{info, unwrap}; |
| 62 | use embassy::executor::{Executor, InterruptExecutor}; | ||
| 63 | use embassy::interrupt::InterruptExt; | ||
| 64 | use embassy::time::{Duration, Instant, Timer}; | 62 | use embassy::time::{Duration, Instant, Timer}; |
| 65 | use embassy::util::Forever; | 63 | use embassy::util::Forever; |
| 64 | use embassy_nrf::executor::{Executor, InterruptExecutor}; | ||
| 66 | use embassy_nrf::interrupt; | 65 | use embassy_nrf::interrupt; |
| 66 | use embassy_nrf::interrupt::InterruptExt; | ||
| 67 | 67 | ||
| 68 | use defmt_rtt as _; // global logger | 68 | use defmt_rtt as _; // global logger |
| 69 | use panic_probe as _; | 69 | use panic_probe as _; |
diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs index d855a3a57..8aa08fe3d 100644 --- a/examples/nrf/src/bin/usb_hid_keyboard.rs +++ b/examples/nrf/src/bin/usb_hid_keyboard.rs | |||
| @@ -8,11 +8,11 @@ use core::sync::atomic::{AtomicBool, Ordering}; | |||
| 8 | use defmt::*; | 8 | use defmt::*; |
| 9 | use embassy::channel::Signal; | 9 | use embassy::channel::Signal; |
| 10 | use embassy::executor::Spawner; | 10 | use embassy::executor::Spawner; |
| 11 | use embassy::interrupt::InterruptExt; | ||
| 12 | use embassy::time::Duration; | 11 | use embassy::time::Duration; |
| 13 | use embassy::util::{select, select3, Either, Either3}; | 12 | use embassy::util::{select, select3, Either, Either3}; |
| 14 | use embassy_nrf::gpio::{Input, Pin, Pull}; | 13 | use embassy_nrf::gpio::{Input, Pin, Pull}; |
| 15 | use embassy_nrf::interrupt; | 14 | use embassy_nrf::interrupt; |
| 15 | use embassy_nrf::interrupt::InterruptExt; | ||
| 16 | use embassy_nrf::pac; | 16 | use embassy_nrf::pac; |
| 17 | use embassy_nrf::usb::Driver; | 17 | use embassy_nrf::usb::Driver; |
| 18 | use embassy_nrf::Peripherals; | 18 | use embassy_nrf::Peripherals; |
diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs index 02380de72..684295609 100644 --- a/examples/stm32f3/src/bin/multiprio.rs +++ b/examples/stm32f3/src/bin/multiprio.rs | |||
| @@ -62,11 +62,11 @@ use defmt_rtt as _; // global logger | |||
| 62 | use panic_probe as _; | 62 | use panic_probe as _; |
| 63 | 63 | ||
| 64 | use cortex_m_rt::entry; | 64 | use cortex_m_rt::entry; |
| 65 | use embassy::executor::{Executor, InterruptExecutor}; | ||
| 66 | use embassy::interrupt::InterruptExt; | ||
| 67 | use embassy::time::{Duration, Instant, Timer}; | 65 | use embassy::time::{Duration, Instant, Timer}; |
| 68 | use embassy::util::Forever; | 66 | use embassy::util::Forever; |
| 67 | use embassy_stm32::executor::{Executor, InterruptExecutor}; | ||
| 69 | use embassy_stm32::interrupt; | 68 | use embassy_stm32::interrupt; |
| 69 | use embassy_stm32::interrupt::InterruptExt; | ||
| 70 | 70 | ||
| 71 | #[embassy::task] | 71 | #[embassy::task] |
| 72 | async fn run_high() { | 72 | async fn run_high() { |
diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index 02380de72..684295609 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs | |||
| @@ -62,11 +62,11 @@ use defmt_rtt as _; // global logger | |||
| 62 | use panic_probe as _; | 62 | use panic_probe as _; |
| 63 | 63 | ||
| 64 | use cortex_m_rt::entry; | 64 | use cortex_m_rt::entry; |
| 65 | use embassy::executor::{Executor, InterruptExecutor}; | ||
| 66 | use embassy::interrupt::InterruptExt; | ||
| 67 | use embassy::time::{Duration, Instant, Timer}; | 65 | use embassy::time::{Duration, Instant, Timer}; |
| 68 | use embassy::util::Forever; | 66 | use embassy::util::Forever; |
| 67 | use embassy_stm32::executor::{Executor, InterruptExecutor}; | ||
| 69 | use embassy_stm32::interrupt; | 68 | use embassy_stm32::interrupt; |
| 69 | use embassy_stm32::interrupt::InterruptExt; | ||
| 70 | 70 | ||
| 71 | #[embassy::task] | 71 | #[embassy::task] |
| 72 | async fn run_high() { | 72 | async fn run_high() { |
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index 3b1b8044d..647c5a8fa 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs | |||
| @@ -9,12 +9,12 @@ use panic_probe as _; | |||
| 9 | use defmt::*; | 9 | use defmt::*; |
| 10 | use embassy::executor::Spawner; | 10 | use embassy::executor::Spawner; |
| 11 | use embassy::time::{Duration, Timer}; | 11 | use embassy::time::{Duration, Timer}; |
| 12 | use embassy::util::Unborrow; | ||
| 13 | use embassy_stm32::gpio::low_level::AFType; | 12 | use embassy_stm32::gpio::low_level::AFType; |
| 14 | use embassy_stm32::gpio::Speed; | 13 | use embassy_stm32::gpio::Speed; |
| 15 | use embassy_stm32::pwm::*; | 14 | use embassy_stm32::pwm::*; |
| 16 | use embassy_stm32::time::{Hertz, U32Ext}; | 15 | use embassy_stm32::time::{Hertz, U32Ext}; |
| 17 | use embassy_stm32::unborrow; | 16 | use embassy_stm32::unborrow; |
| 17 | use embassy_stm32::Unborrow; | ||
| 18 | use embassy_stm32::{Config, Peripherals}; | 18 | use embassy_stm32::{Config, Peripherals}; |
| 19 | 19 | ||
| 20 | pub fn config() -> Config { | 20 | pub fn config() -> Config { |
diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs index 562e25ac0..f5f9b6a32 100644 --- a/examples/stm32wl/src/bin/subghz.rs +++ b/examples/stm32wl/src/bin/subghz.rs | |||
| @@ -10,11 +10,11 @@ use panic_probe as _; | |||
| 10 | 10 | ||
| 11 | use defmt::*; | 11 | use defmt::*; |
| 12 | use embassy::channel::signal::Signal; | 12 | use embassy::channel::signal::Signal; |
| 13 | use embassy::interrupt::{Interrupt, InterruptExt}; | ||
| 14 | use embassy_stm32::dma::NoDma; | 13 | use embassy_stm32::dma::NoDma; |
| 15 | use embassy_stm32::exti::ExtiInput; | 14 | use embassy_stm32::exti::ExtiInput; |
| 16 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | 15 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; |
| 17 | use embassy_stm32::interrupt; | 16 | use embassy_stm32::interrupt; |
| 17 | use embassy_stm32::interrupt::{Interrupt, InterruptExt}; | ||
| 18 | use embassy_stm32::subghz::*; | 18 | use embassy_stm32::subghz::*; |
| 19 | use embassy_stm32::Peripherals; | 19 | use embassy_stm32::Peripherals; |
| 20 | 20 | ||
