diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-02-27 01:08:16 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-02-28 23:07:20 +0100 |
| commit | 4dfa32b1e0572c03a5f97f0ed4a4a0acd6f12cca (patch) | |
| tree | 377c51d177d5b4edf235da7fa5099bf42aebaf17 /examples | |
| parent | 711ce1014552b715190b1ee6780cafc92fe54240 (diff) | |
cortex-m/executor: don't use the owned interrupts system.
Preparation for #1224.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nrf52840/src/bin/multiprio.rs | 32 | ||||
| -rw-r--r-- | examples/stm32f0/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32f0/src/bin/multiprio.rs (renamed from examples/stm32f0/src/bin/priority.rs) | 32 | ||||
| -rw-r--r-- | examples/stm32f3/src/bin/multiprio.rs | 36 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/multiprio.rs | 36 |
5 files changed, 89 insertions, 49 deletions
diff --git a/examples/nrf52840/src/bin/multiprio.rs b/examples/nrf52840/src/bin/multiprio.rs index 25806ae48..851e189ea 100644 --- a/examples/nrf52840/src/bin/multiprio.rs +++ b/examples/nrf52840/src/bin/multiprio.rs | |||
| @@ -57,11 +57,14 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 60 | use cortex_m_rt::entry; | 63 | use cortex_m_rt::entry; |
| 61 | use defmt::{info, unwrap}; | 64 | use defmt::{info, unwrap}; |
| 62 | use embassy_nrf::executor::{Executor, InterruptExecutor}; | 65 | use embassy_nrf::executor::{Executor, InterruptExecutor}; |
| 63 | use embassy_nrf::interrupt; | 66 | use embassy_nrf::interrupt; |
| 64 | use embassy_nrf::interrupt::InterruptExt; | 67 | use embassy_nrf::pac::Interrupt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 68 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use static_cell::StaticCell; | 69 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 70 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -108,28 +111,35 @@ async fn run_low() { | |||
| 108 | } | 111 | } |
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::SWI1_EGU1>> = StaticCell::new(); | 114 | static EXECUTOR_HIGH: InterruptExecutor = InterruptExecutor::new(); |
| 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::SWI0_EGU0>> = StaticCell::new(); | 115 | static EXECUTOR_MED: InterruptExecutor = InterruptExecutor::new(); |
| 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); | 116 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 117 | ||
| 118 | #[interrupt] | ||
| 119 | unsafe fn SWI1_EGU1() { | ||
| 120 | EXECUTOR_HIGH.on_interrupt() | ||
| 121 | } | ||
| 122 | |||
| 123 | #[interrupt] | ||
| 124 | unsafe fn SWI0_EGU0() { | ||
| 125 | EXECUTOR_MED.on_interrupt() | ||
| 126 | } | ||
| 127 | |||
| 115 | #[entry] | 128 | #[entry] |
| 116 | fn main() -> ! { | 129 | fn main() -> ! { |
| 117 | info!("Hello World!"); | 130 | info!("Hello World!"); |
| 118 | 131 | ||
| 119 | let _p = embassy_nrf::init(Default::default()); | 132 | let _p = embassy_nrf::init(Default::default()); |
| 133 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 120 | 134 | ||
| 121 | // High-priority executor: SWI1_EGU1, priority level 6 | 135 | // High-priority executor: SWI1_EGU1, priority level 6 |
| 122 | let irq = interrupt::take!(SWI1_EGU1); | 136 | unsafe { nvic.set_priority(Interrupt::SWI1_EGU1, 6 << 5) }; |
| 123 | irq.set_priority(interrupt::Priority::P6); | 137 | let spawner = EXECUTOR_HIGH.start(Interrupt::SWI1_EGU1); |
| 124 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); | ||
| 125 | let spawner = executor.start(); | ||
| 126 | unwrap!(spawner.spawn(run_high())); | 138 | unwrap!(spawner.spawn(run_high())); |
| 127 | 139 | ||
| 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 140 | // Medium-priority executor: SWI0_EGU0, priority level 7 |
| 129 | let irq = interrupt::take!(SWI0_EGU0); | 141 | unsafe { nvic.set_priority(Interrupt::SWI0_EGU0, 7 << 5) }; |
| 130 | irq.set_priority(interrupt::Priority::P7); | 142 | let spawner = EXECUTOR_MED.start(Interrupt::SWI0_EGU0); |
| 131 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); | ||
| 132 | let spawner = executor.start(); | ||
| 133 | unwrap!(spawner.spawn(run_med())); | 143 | unwrap!(spawner.spawn(run_med())); |
| 134 | 144 | ||
| 135 | // Low priority executor: runs in thread mode, using WFE/SEV | 145 | // Low priority executor: runs in thread mode, using WFE/SEV |
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml index d4afbb8f8..89d99b6d3 100644 --- a/examples/stm32f0/Cargo.toml +++ b/examples/stm32f0/Cargo.toml | |||
| @@ -15,5 +15,5 @@ panic-probe = "0.3" | |||
| 15 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } | 15 | embassy-sync = { version = "0.1.0", path = "../../embassy-sync", features = ["defmt"] } |
| 16 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } | 16 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["defmt", "integrated-timers"] } |
| 17 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 17 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 18 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti"] } | 18 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "memory-x", "stm32f091rc", "time-driver-any", "exti", "unstable-pac"] } |
| 19 | static_cell = "1.0" | 19 | static_cell = "1.0" |
diff --git a/examples/stm32f0/src/bin/priority.rs b/examples/stm32f0/src/bin/multiprio.rs index 7fed6a773..e0dc8c989 100644 --- a/examples/stm32f0/src/bin/priority.rs +++ b/examples/stm32f0/src/bin/multiprio.rs | |||
| @@ -57,11 +57,14 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 60 | use cortex_m_rt::entry; | 63 | use cortex_m_rt::entry; |
| 61 | use defmt::*; | 64 | use defmt::*; |
| 62 | use embassy_stm32::executor::{Executor, InterruptExecutor}; | 65 | use embassy_stm32::executor::{Executor, InterruptExecutor}; |
| 63 | use embassy_stm32::interrupt; | 66 | use embassy_stm32::interrupt; |
| 64 | use embassy_stm32::interrupt::InterruptExt; | 67 | use embassy_stm32::pac::Interrupt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 68 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use static_cell::StaticCell; | 69 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 70 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -108,27 +111,34 @@ async fn run_low() { | |||
| 108 | } | 111 | } |
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::USART1>> = StaticCell::new(); | 114 | static EXECUTOR_HIGH: InterruptExecutor = InterruptExecutor::new(); |
| 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::USART2>> = StaticCell::new(); | 115 | static EXECUTOR_MED: InterruptExecutor = InterruptExecutor::new(); |
| 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); | 116 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 117 | ||
| 118 | #[interrupt] | ||
| 119 | unsafe fn USART1() { | ||
| 120 | EXECUTOR_HIGH.on_interrupt() | ||
| 121 | } | ||
| 122 | |||
| 123 | #[interrupt] | ||
| 124 | unsafe fn USART2() { | ||
| 125 | EXECUTOR_MED.on_interrupt() | ||
| 126 | } | ||
| 127 | |||
| 115 | #[entry] | 128 | #[entry] |
| 116 | fn main() -> ! { | 129 | fn main() -> ! { |
| 117 | // Initialize and create handle for devicer peripherals | 130 | // Initialize and create handle for devicer peripherals |
| 118 | let _p = embassy_stm32::init(Default::default()); | 131 | let _p = embassy_stm32::init(Default::default()); |
| 132 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 119 | 133 | ||
| 120 | // High-priority executor: USART1, priority level 6 | 134 | // High-priority executor: USART1, priority level 6 |
| 121 | let irq = interrupt::take!(USART1); | 135 | unsafe { nvic.set_priority(Interrupt::USART1, 6 << 4) }; |
| 122 | irq.set_priority(interrupt::Priority::P6); | 136 | let spawner = EXECUTOR_HIGH.start(Interrupt::USART1); |
| 123 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); | ||
| 124 | let spawner = executor.start(); | ||
| 125 | unwrap!(spawner.spawn(run_high())); | 137 | unwrap!(spawner.spawn(run_high())); |
| 126 | 138 | ||
| 127 | // Medium-priority executor: USART2, priority level 7 | 139 | // Medium-priority executor: USART2, priority level 7 |
| 128 | let irq = interrupt::take!(USART2); | 140 | unsafe { nvic.set_priority(Interrupt::USART2, 7 << 4) }; |
| 129 | irq.set_priority(interrupt::Priority::P7); | 141 | let spawner = EXECUTOR_MED.start(Interrupt::USART2); |
| 130 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); | ||
| 131 | let spawner = executor.start(); | ||
| 132 | unwrap!(spawner.spawn(run_med())); | 142 | unwrap!(spawner.spawn(run_med())); |
| 133 | 143 | ||
| 134 | // Low priority executor: runs in thread mode, using WFE/SEV | 144 | // Low priority executor: runs in thread mode, using WFE/SEV |
diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs index 9e8228a4b..77df51ac7 100644 --- a/examples/stm32f3/src/bin/multiprio.rs +++ b/examples/stm32f3/src/bin/multiprio.rs | |||
| @@ -57,11 +57,14 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 60 | use cortex_m_rt::entry; | 63 | use cortex_m_rt::entry; |
| 61 | use defmt::*; | 64 | use defmt::*; |
| 62 | use embassy_stm32::executor::{Executor, InterruptExecutor}; | 65 | use embassy_stm32::executor::{Executor, InterruptExecutor}; |
| 63 | use embassy_stm32::interrupt; | 66 | use embassy_stm32::interrupt; |
| 64 | use embassy_stm32::interrupt::InterruptExt; | 67 | use embassy_stm32::pac::Interrupt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 68 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use static_cell::StaticCell; | 69 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 70 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -108,28 +111,35 @@ async fn run_low() { | |||
| 108 | } | 111 | } |
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::UART4>> = StaticCell::new(); | 114 | static EXECUTOR_HIGH: InterruptExecutor = InterruptExecutor::new(); |
| 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::UART5>> = StaticCell::new(); | 115 | static EXECUTOR_MED: InterruptExecutor = InterruptExecutor::new(); |
| 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); | 116 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 117 | ||
| 118 | #[interrupt] | ||
| 119 | unsafe fn UART4() { | ||
| 120 | EXECUTOR_HIGH.on_interrupt() | ||
| 121 | } | ||
| 122 | |||
| 123 | #[interrupt] | ||
| 124 | unsafe fn UART5() { | ||
| 125 | EXECUTOR_MED.on_interrupt() | ||
| 126 | } | ||
| 127 | |||
| 115 | #[entry] | 128 | #[entry] |
| 116 | fn main() -> ! { | 129 | fn main() -> ! { |
| 117 | info!("Hello World!"); | 130 | info!("Hello World!"); |
| 118 | 131 | ||
| 119 | let _p = embassy_stm32::init(Default::default()); | 132 | let _p = embassy_stm32::init(Default::default()); |
| 133 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 120 | 134 | ||
| 121 | // High-priority executor: SWI1_EGU1, priority level 6 | 135 | // High-priority executor: UART4, priority level 6 |
| 122 | let irq = interrupt::take!(UART4); | 136 | unsafe { nvic.set_priority(Interrupt::UART4, 6 << 4) }; |
| 123 | irq.set_priority(interrupt::Priority::P6); | 137 | let spawner = EXECUTOR_HIGH.start(Interrupt::UART4); |
| 124 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); | ||
| 125 | let spawner = executor.start(); | ||
| 126 | unwrap!(spawner.spawn(run_high())); | 138 | unwrap!(spawner.spawn(run_high())); |
| 127 | 139 | ||
| 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 140 | // Medium-priority executor: UART5, priority level 7 |
| 129 | let irq = interrupt::take!(UART5); | 141 | unsafe { nvic.set_priority(Interrupt::UART5, 7 << 4) }; |
| 130 | irq.set_priority(interrupt::Priority::P7); | 142 | let spawner = EXECUTOR_MED.start(Interrupt::UART5); |
| 131 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); | ||
| 132 | let spawner = executor.start(); | ||
| 133 | unwrap!(spawner.spawn(run_med())); | 143 | unwrap!(spawner.spawn(run_med())); |
| 134 | 144 | ||
| 135 | // Low priority executor: runs in thread mode, using WFE/SEV | 145 | // Low priority executor: runs in thread mode, using WFE/SEV |
diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index 9e8228a4b..77df51ac7 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs | |||
| @@ -57,11 +57,14 @@ | |||
| 57 | #![no_main] | 57 | #![no_main] |
| 58 | #![feature(type_alias_impl_trait)] | 58 | #![feature(type_alias_impl_trait)] |
| 59 | 59 | ||
| 60 | use core::mem; | ||
| 61 | |||
| 62 | use cortex_m::peripheral::NVIC; | ||
| 60 | use cortex_m_rt::entry; | 63 | use cortex_m_rt::entry; |
| 61 | use defmt::*; | 64 | use defmt::*; |
| 62 | use embassy_stm32::executor::{Executor, InterruptExecutor}; | 65 | use embassy_stm32::executor::{Executor, InterruptExecutor}; |
| 63 | use embassy_stm32::interrupt; | 66 | use embassy_stm32::interrupt; |
| 64 | use embassy_stm32::interrupt::InterruptExt; | 67 | use embassy_stm32::pac::Interrupt; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 68 | use embassy_time::{Duration, Instant, Timer}; |
| 66 | use static_cell::StaticCell; | 69 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 70 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -108,28 +111,35 @@ async fn run_low() { | |||
| 108 | } | 111 | } |
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | static EXECUTOR_HIGH: StaticCell<InterruptExecutor<interrupt::UART4>> = StaticCell::new(); | 114 | static EXECUTOR_HIGH: InterruptExecutor = InterruptExecutor::new(); |
| 112 | static EXECUTOR_MED: StaticCell<InterruptExecutor<interrupt::UART5>> = StaticCell::new(); | 115 | static EXECUTOR_MED: InterruptExecutor = InterruptExecutor::new(); |
| 113 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); | 116 | static EXECUTOR_LOW: StaticCell<Executor> = StaticCell::new(); |
| 114 | 117 | ||
| 118 | #[interrupt] | ||
| 119 | unsafe fn UART4() { | ||
| 120 | EXECUTOR_HIGH.on_interrupt() | ||
| 121 | } | ||
| 122 | |||
| 123 | #[interrupt] | ||
| 124 | unsafe fn UART5() { | ||
| 125 | EXECUTOR_MED.on_interrupt() | ||
| 126 | } | ||
| 127 | |||
| 115 | #[entry] | 128 | #[entry] |
| 116 | fn main() -> ! { | 129 | fn main() -> ! { |
| 117 | info!("Hello World!"); | 130 | info!("Hello World!"); |
| 118 | 131 | ||
| 119 | let _p = embassy_stm32::init(Default::default()); | 132 | let _p = embassy_stm32::init(Default::default()); |
| 133 | let mut nvic: NVIC = unsafe { mem::transmute(()) }; | ||
| 120 | 134 | ||
| 121 | // High-priority executor: SWI1_EGU1, priority level 6 | 135 | // High-priority executor: UART4, priority level 6 |
| 122 | let irq = interrupt::take!(UART4); | 136 | unsafe { nvic.set_priority(Interrupt::UART4, 6 << 4) }; |
| 123 | irq.set_priority(interrupt::Priority::P6); | 137 | let spawner = EXECUTOR_HIGH.start(Interrupt::UART4); |
| 124 | let executor = EXECUTOR_HIGH.init(InterruptExecutor::new(irq)); | ||
| 125 | let spawner = executor.start(); | ||
| 126 | unwrap!(spawner.spawn(run_high())); | 138 | unwrap!(spawner.spawn(run_high())); |
| 127 | 139 | ||
| 128 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 140 | // Medium-priority executor: UART5, priority level 7 |
| 129 | let irq = interrupt::take!(UART5); | 141 | unsafe { nvic.set_priority(Interrupt::UART5, 7 << 4) }; |
| 130 | irq.set_priority(interrupt::Priority::P7); | 142 | let spawner = EXECUTOR_MED.start(Interrupt::UART5); |
| 131 | let executor = EXECUTOR_MED.init(InterruptExecutor::new(irq)); | ||
| 132 | let spawner = executor.start(); | ||
| 133 | unwrap!(spawner.spawn(run_med())); | 143 | unwrap!(spawner.spawn(run_med())); |
| 134 | 144 | ||
| 135 | // Low priority executor: runs in thread mode, using WFE/SEV | 145 | // Low priority executor: runs in thread mode, using WFE/SEV |
