aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsodo <[email protected]>2023-12-10 01:45:24 +0900
committersodo <[email protected]>2023-12-10 01:45:24 +0900
commit58d503a77da73204f097fae1f1a2a1ce2cf90600 (patch)
treec7739f0342e2e0d243cf9bb652c2246b2499cb23
parent83138ce68e506692aabd825eae39016ddb8fd2c4 (diff)
add avr support
-rw-r--r--embassy-executor-macros/src/lib.rs7
-rw-r--r--embassy-executor-macros/src/macros/main.rs14
-rw-r--r--embassy-executor/Cargo.toml1
-rw-r--r--embassy-executor/src/arch/avr.rs60
-rw-r--r--embassy-executor/src/lib.rs3
5 files changed, 84 insertions, 1 deletions
diff --git a/embassy-executor-macros/src/lib.rs b/embassy-executor-macros/src/lib.rs
index c9d58746a..5461fe04c 100644
--- a/embassy-executor-macros/src/lib.rs
+++ b/embassy-executor-macros/src/lib.rs
@@ -62,6 +62,13 @@ pub fn task(args: TokenStream, item: TokenStream) -> TokenStream {
62 task::run(&args.meta, f).unwrap_or_else(|x| x).into() 62 task::run(&args.meta, f).unwrap_or_else(|x| x).into()
63} 63}
64 64
65#[proc_macro_attribute]
66pub fn main_avr(args: TokenStream, item: TokenStream) -> TokenStream {
67 let args = syn::parse_macro_input!(args as Args);
68 let f = syn::parse_macro_input!(item as syn::ItemFn);
69 main::run(&args.meta, f, main::avr()).unwrap_or_else(|x| x).into()
70}
71
65/// Creates a new `executor` instance and declares an application entry point for Cortex-M spawning the corresponding function body as an async task. 72/// Creates a new `executor` instance and declares an application entry point for Cortex-M spawning the corresponding function body as an async task.
66/// 73///
67/// The following restrictions apply: 74/// The following restrictions apply:
diff --git a/embassy-executor-macros/src/macros/main.rs b/embassy-executor-macros/src/macros/main.rs
index 3c0d58567..088e64d1c 100644
--- a/embassy-executor-macros/src/macros/main.rs
+++ b/embassy-executor-macros/src/macros/main.rs
@@ -12,6 +12,20 @@ struct Args {
12 entry: Option<String>, 12 entry: Option<String>,
13} 13}
14 14
15pub fn avr() -> TokenStream {
16 quote! {
17 #[avr_device::entry]
18 fn main() -> ! {
19 let mut executor = ::embassy_executor::Executor::new();
20 let executor = unsafe { __make_static(&mut executor) };
21
22 executor.run(|spawner| {
23 spawner.must_spawn(__embassy_main(spawner));
24 })
25 }
26 }
27}
28
15pub fn riscv(args: &[NestedMeta]) -> TokenStream { 29pub fn riscv(args: &[NestedMeta]) -> TokenStream {
16 let maybe_entry = match Args::from_list(args) { 30 let maybe_entry = match Args::from_list(args) {
17 Ok(args) => args.entry, 31 Ok(args) => args.entry,
diff --git a/embassy-executor/Cargo.toml b/embassy-executor/Cargo.toml
index ec5aca46d..ade37913b 100644
--- a/embassy-executor/Cargo.toml
+++ b/embassy-executor/Cargo.toml
@@ -55,6 +55,7 @@ critical-section = { version = "1.1", features = ["std"] }
55 55
56# Architecture 56# Architecture
57_arch = [] # some arch was picked 57_arch = [] # some arch was picked
58arch-avr = ["_arch", "dep:portable-atomic"]
58arch-std = ["_arch", "critical-section/std"] 59arch-std = ["_arch", "critical-section/std"]
59arch-cortex-m = ["_arch", "dep:cortex-m"] 60arch-cortex-m = ["_arch", "dep:cortex-m"]
60arch-riscv32 = ["_arch", "dep:portable-atomic"] 61arch-riscv32 = ["_arch", "dep:portable-atomic"]
diff --git a/embassy-executor/src/arch/avr.rs b/embassy-executor/src/arch/avr.rs
new file mode 100644
index 000000000..2c715f297
--- /dev/null
+++ b/embassy-executor/src/arch/avr.rs
@@ -0,0 +1,60 @@
1#[cfg(feature = "executor-interrupt")]
2compile_error!("`executor-interrupt` is not supported with `arch-avr`.");
3
4#[cfg(feature = "executor-thread")]
5pub use thread::*;
6#[cfg(feature = "executor-thread")]
7mod thread {
8 use core::marker::PhantomData;
9
10 pub use embassy_executor_macros::main_avr as main;
11
12 use crate::{raw, Spawner};
13
14 #[export_name = "__pender"]
15 fn __pender(_context: *mut ()) {}
16
17 /// avr Executor
18 pub struct Executor {
19 inner: raw::Executor,
20 not_send: PhantomData<*mut ()>,
21 }
22
23 impl Executor {
24 /// Create a new Executor.
25 pub fn new() -> Self {
26 Self {
27 inner: raw::Executor::new(core::ptr::null_mut()),
28 not_send: PhantomData,
29 }
30 }
31
32 /// Run the executor.
33 ///
34 /// The `init` closure is called with a [`Spawner`] that spawns tasks on
35 /// this executor. Use it to spawn the initial task(s). After `init` returns,
36 /// the executor starts running the tasks.
37 ///
38 /// To spawn more tasks later, you may keep copies of the [`Spawner`] (it is `Copy`),
39 /// for example by passing it as an argument to the initial tasks.
40 ///
41 /// This function requires `&'static mut self`. This means you have to store the
42 /// Executor instance in a place where it'll live forever and grants you mutable
43 /// access. There's a few ways to do this:
44 ///
45 /// - a [StaticCell](https://docs.rs/static_cell/latest/static_cell/) (safe)
46 /// - a `static mut` (unsafe)
47 /// - a local variable in a function you know never returns (like `fn main() -> !`), upgrading its lifetime with `transmute`. (unsafe)
48 ///
49 /// This function never returns.
50 pub fn run(&'static mut self, init: impl FnOnce(Spawner)) -> ! {
51 init(self.inner.spawner());
52
53 loop {
54 unsafe {
55 self.inner.poll();
56 }
57 }
58 }
59 }
60}
diff --git a/embassy-executor/src/lib.rs b/embassy-executor/src/lib.rs
index 4c6900a6d..834ebf16a 100644
--- a/embassy-executor/src/lib.rs
+++ b/embassy-executor/src/lib.rs
@@ -20,9 +20,10 @@ macro_rules! check_at_most_one {
20 check_at_most_one!(@amo [$($f)*] [$($f)*] []); 20 check_at_most_one!(@amo [$($f)*] [$($f)*] []);
21 }; 21 };
22} 22}
23check_at_most_one!("arch-cortex-m", "arch-riscv32", "arch-std", "arch-wasm",); 23check_at_most_one!("arch-avr", "arch-cortex-m", "arch-riscv32", "arch-std", "arch-wasm",);
24 24
25#[cfg(feature = "_arch")] 25#[cfg(feature = "_arch")]
26#[cfg_attr(feature = "arch-avr", path = "arch/avr.rs")]
26#[cfg_attr(feature = "arch-cortex-m", path = "arch/cortex_m.rs")] 27#[cfg_attr(feature = "arch-cortex-m", path = "arch/cortex_m.rs")]
27#[cfg_attr(feature = "arch-riscv32", path = "arch/riscv32.rs")] 28#[cfg_attr(feature = "arch-riscv32", path = "arch/riscv32.rs")]
28#[cfg_attr(feature = "arch-std", path = "arch/std.rs")] 29#[cfg_attr(feature = "arch-std", path = "arch/std.rs")]