diff options
| author | Jesse Braham <[email protected]> | 2023-05-16 09:34:38 -0700 |
|---|---|---|
| committer | Jesse Braham <[email protected]> | 2023-05-16 09:37:25 -0700 |
| commit | 4e9ed223a9c489ec75d2d928e26d5a83c2cdf5d4 (patch) | |
| tree | ed26a470a327b98fbf4a4b56df9803f7ccc0d784 /embassy-macros/src/lib.rs | |
| parent | 56f2e0c9a02f6db9fe4e3a72a9b7fdd160a90aa8 (diff) | |
Allow for an optional user-defined entry macro when targeting RISC-V
Diffstat (limited to 'embassy-macros/src/lib.rs')
| -rw-r--r-- | embassy-macros/src/lib.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index d2c696c72..dc5b519ff 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs | |||
| @@ -79,6 +79,8 @@ pub fn main_cortex_m(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 79 | /// * The function must not use generics. | 79 | /// * The function must not use generics. |
| 80 | /// * Only a single `main` task may be declared. | 80 | /// * Only a single `main` task may be declared. |
| 81 | /// | 81 | /// |
| 82 | /// A user-defined entry macro can be optionally provided via the `entry` argument to override the default of `riscv_rt::entry`. | ||
| 83 | /// | ||
| 82 | /// ## Examples | 84 | /// ## Examples |
| 83 | /// Spawning a task: | 85 | /// Spawning a task: |
| 84 | /// | 86 | /// |
| @@ -88,11 +90,21 @@ pub fn main_cortex_m(args: TokenStream, item: TokenStream) -> TokenStream { | |||
| 88 | /// // Function body | 90 | /// // Function body |
| 89 | /// } | 91 | /// } |
| 90 | /// ``` | 92 | /// ``` |
| 93 | /// | ||
| 94 | /// Spawning a task using a custom entry macro: | ||
| 95 | /// ``` rust | ||
| 96 | /// #[embassy_executor::main(entry = "esp_riscv_rt::entry")] | ||
| 97 | /// async fn main(_s: embassy_executor::Spawner) { | ||
| 98 | /// // Function body | ||
| 99 | /// } | ||
| 100 | /// ``` | ||
| 91 | #[proc_macro_attribute] | 101 | #[proc_macro_attribute] |
| 92 | pub fn main_riscv(args: TokenStream, item: TokenStream) -> TokenStream { | 102 | pub fn main_riscv(args: TokenStream, item: TokenStream) -> TokenStream { |
| 93 | let args = syn::parse_macro_input!(args as syn::AttributeArgs); | 103 | let args = syn::parse_macro_input!(args as syn::AttributeArgs); |
| 94 | let f = syn::parse_macro_input!(item as syn::ItemFn); | 104 | let f = syn::parse_macro_input!(item as syn::ItemFn); |
| 95 | main::run(args, f, main::riscv()).unwrap_or_else(|x| x).into() | 105 | main::run(args.clone(), f, main::riscv(args)) |
| 106 | .unwrap_or_else(|x| x) | ||
| 107 | .into() | ||
| 96 | } | 108 | } |
| 97 | 109 | ||
| 98 | /// Creates a new `executor` instance and declares an application entry point for STD spawning the corresponding function body as an async task. | 110 | /// Creates a new `executor` instance and declares an application entry point for STD spawning the corresponding function body as an async task. |
