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 /embassy-macros | |
| 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`.
Diffstat (limited to 'embassy-macros')
| -rw-r--r-- | embassy-macros/src/lib.rs | 18 | ||||
| -rw-r--r-- | embassy-macros/src/macros/cortex_m_interrupt.rs (renamed from embassy-macros/src/macros/interrupt.rs) | 0 | ||||
| -rw-r--r-- | embassy-macros/src/macros/cortex_m_interrupt_declare.rs (renamed from embassy-macros/src/macros/interrupt_declare.rs) | 9 | ||||
| -rw-r--r-- | embassy-macros/src/macros/cortex_m_interrupt_take.rs (renamed from embassy-macros/src/macros/interrupt_take.rs) | 2 | ||||
| -rw-r--r-- | embassy-macros/src/macros/mod.rs | 6 |
5 files changed, 20 insertions, 15 deletions
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; |
