diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-05-11 01:27:46 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-05-11 01:34:24 +0200 |
| commit | e0809ab0fb64ff71be23e2d041d4fbae67dca234 (patch) | |
| tree | 3ac40e1f52a0ed3981d2983074fafe70563548e6 | |
| parent | e6a8c8bfcce1e882d4cd6b37c83eb6662762810b (diff) | |
Switch to use PrioritX enums.
| -rw-r--r-- | embassy-nrf-examples/src/bin/multiprio.rs | 4 | ||||
| -rw-r--r-- | embassy-nrf/src/interrupt.rs | 41 | ||||
| -rw-r--r-- | embassy-rp/src/interrupt.rs | 41 | ||||
| -rw-r--r-- | embassy-stm32-examples/src/bin/usb_serial.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/interrupt.rs | 57 |
5 files changed, 6 insertions, 139 deletions
diff --git a/embassy-nrf-examples/src/bin/multiprio.rs b/embassy-nrf-examples/src/bin/multiprio.rs index c6228a1ea..9ed5c1368 100644 --- a/embassy-nrf-examples/src/bin/multiprio.rs +++ b/embassy-nrf-examples/src/bin/multiprio.rs | |||
| @@ -135,7 +135,7 @@ fn main() -> ! { | |||
| 135 | 135 | ||
| 136 | // High-priority executor: SWI1_EGU1, priority level 6 | 136 | // High-priority executor: SWI1_EGU1, priority level 6 |
| 137 | let irq = interrupt::take!(SWI1_EGU1); | 137 | let irq = interrupt::take!(SWI1_EGU1); |
| 138 | irq.set_priority(interrupt::Priority::Level6); | 138 | irq.set_priority(interrupt::Priority::P6); |
| 139 | let alarm = ALARM_HIGH.put(rtc.alarm2()); | 139 | let alarm = ALARM_HIGH.put(rtc.alarm2()); |
| 140 | let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); | 140 | let executor = EXECUTOR_HIGH.put(InterruptExecutor::new(irq)); |
| 141 | executor.set_alarm(alarm); | 141 | executor.set_alarm(alarm); |
| @@ -145,7 +145,7 @@ fn main() -> ! { | |||
| 145 | 145 | ||
| 146 | // Medium-priority executor: SWI0_EGU0, priority level 7 | 146 | // Medium-priority executor: SWI0_EGU0, priority level 7 |
| 147 | let irq = interrupt::take!(SWI0_EGU0); | 147 | let irq = interrupt::take!(SWI0_EGU0); |
| 148 | irq.set_priority(interrupt::Priority::Level7); | 148 | irq.set_priority(interrupt::Priority::P7); |
| 149 | let alarm = ALARM_MED.put(rtc.alarm1()); | 149 | let alarm = ALARM_MED.put(rtc.alarm1()); |
| 150 | let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); | 150 | let executor = EXECUTOR_MED.put(InterruptExecutor::new(irq)); |
| 151 | executor.set_alarm(alarm); | 151 | executor.set_alarm(alarm); |
diff --git a/embassy-nrf/src/interrupt.rs b/embassy-nrf/src/interrupt.rs index 8d069e329..a29861977 100644 --- a/embassy-nrf/src/interrupt.rs +++ b/embassy-nrf/src/interrupt.rs | |||
| @@ -3,48 +3,9 @@ | |||
| 3 | //! This module implements an API for managing interrupts compatible with | 3 | //! This module implements an API for managing interrupts compatible with |
| 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 | use core::sync::atomic::{compiler_fence, Ordering}; | ||
| 7 | |||
| 8 | use crate::pac::NVIC_PRIO_BITS; | ||
| 9 | |||
| 10 | // Re-exports | 6 | // Re-exports |
| 11 | pub use embassy::interrupt::{declare, take, Interrupt}; | 7 | pub use embassy::interrupt::{declare, take, Interrupt}; |
| 12 | 8 | pub use embassy_extras::interrupt::Priority3 as Priority; | |
| 13 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] | ||
| 14 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 15 | #[repr(u8)] | ||
| 16 | pub enum Priority { | ||
| 17 | Level0 = 0, | ||
| 18 | Level1 = 1, | ||
| 19 | Level2 = 2, | ||
| 20 | Level3 = 3, | ||
| 21 | Level4 = 4, | ||
| 22 | Level5 = 5, | ||
| 23 | Level6 = 6, | ||
| 24 | Level7 = 7, | ||
| 25 | } | ||
| 26 | |||
| 27 | impl From<u8> for Priority { | ||
| 28 | fn from(priority: u8) -> Self { | ||
| 29 | match priority >> (8 - NVIC_PRIO_BITS) { | ||
| 30 | 0 => Self::Level0, | ||
| 31 | 1 => Self::Level1, | ||
| 32 | 2 => Self::Level2, | ||
| 33 | 3 => Self::Level3, | ||
| 34 | 4 => Self::Level4, | ||
| 35 | 5 => Self::Level5, | ||
| 36 | 6 => Self::Level6, | ||
| 37 | 7 => Self::Level7, | ||
| 38 | _ => unreachable!(), | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | impl From<Priority> for u8 { | ||
| 44 | fn from(p: Priority) -> Self { | ||
| 45 | (p as u8) << (8 - NVIC_PRIO_BITS) | ||
| 46 | } | ||
| 47 | } | ||
| 48 | 9 | ||
| 49 | #[cfg(feature = "52810")] | 10 | #[cfg(feature = "52810")] |
| 50 | mod irqs { | 11 | mod irqs { |
diff --git a/embassy-rp/src/interrupt.rs b/embassy-rp/src/interrupt.rs index cb9f36546..262f7f546 100644 --- a/embassy-rp/src/interrupt.rs +++ b/embassy-rp/src/interrupt.rs | |||
| @@ -3,48 +3,9 @@ | |||
| 3 | //! This module implements an API for managing interrupts compatible with | 3 | //! This module implements an API for managing interrupts compatible with |
| 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 | use core::sync::atomic::{compiler_fence, Ordering}; | ||
| 7 | |||
| 8 | use crate::pac::NVIC_PRIO_BITS; | ||
| 9 | |||
| 10 | // Re-exports | 6 | // Re-exports |
| 11 | pub use embassy::interrupt::{declare, take, Interrupt}; | 7 | pub use embassy::interrupt::{declare, take, Interrupt}; |
| 12 | 8 | pub use embassy_extras::interrupt::Priority3 as Priority; | |
| 13 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] | ||
| 14 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 15 | #[repr(u8)] | ||
| 16 | pub enum Priority { | ||
| 17 | Level0 = 0, | ||
| 18 | Level1 = 1, | ||
| 19 | Level2 = 2, | ||
| 20 | Level3 = 3, | ||
| 21 | Level4 = 4, | ||
| 22 | Level5 = 5, | ||
| 23 | Level6 = 6, | ||
| 24 | Level7 = 7, | ||
| 25 | } | ||
| 26 | |||
| 27 | impl From<u8> for Priority { | ||
| 28 | fn from(priority: u8) -> Self { | ||
| 29 | match priority >> (8 - NVIC_PRIO_BITS) { | ||
| 30 | 0 => Self::Level0, | ||
| 31 | 1 => Self::Level1, | ||
| 32 | 2 => Self::Level2, | ||
| 33 | 3 => Self::Level3, | ||
| 34 | 4 => Self::Level4, | ||
| 35 | 5 => Self::Level5, | ||
| 36 | 6 => Self::Level6, | ||
| 37 | 7 => Self::Level7, | ||
| 38 | _ => unreachable!(), | ||
| 39 | } | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | impl From<Priority> for u8 { | ||
| 44 | fn from(p: Priority) -> Self { | ||
| 45 | (p as u8) << (8 - NVIC_PRIO_BITS) | ||
| 46 | } | ||
| 47 | } | ||
| 48 | 9 | ||
| 49 | mod irqs { | 10 | mod irqs { |
| 50 | use super::*; | 11 | use super::*; |
diff --git a/embassy-stm32-examples/src/bin/usb_serial.rs b/embassy-stm32-examples/src/bin/usb_serial.rs index e13275dd3..38656b979 100644 --- a/embassy-stm32-examples/src/bin/usb_serial.rs +++ b/embassy-stm32-examples/src/bin/usb_serial.rs | |||
| @@ -41,7 +41,7 @@ async fn run1(bus: &'static mut UsbBusAllocator<UsbBus<USB>>) { | |||
| 41 | .build(); | 41 | .build(); |
| 42 | 42 | ||
| 43 | let irq = interrupt::take!(OTG_FS); | 43 | let irq = interrupt::take!(OTG_FS); |
| 44 | irq.set_priority(interrupt::Priority::Level3); | 44 | irq.set_priority(interrupt::Priority::P3); |
| 45 | 45 | ||
| 46 | let usb = Usb::new(device, serial, irq); | 46 | let usb = Usb::new(device, serial, irq); |
| 47 | pin_mut!(usb); | 47 | pin_mut!(usb); |
diff --git a/embassy-stm32/src/interrupt.rs b/embassy-stm32/src/interrupt.rs index 1d48dc584..76dea28f6 100644 --- a/embassy-stm32/src/interrupt.rs +++ b/embassy-stm32/src/interrupt.rs | |||
| @@ -3,64 +3,9 @@ | |||
| 3 | //! This module implements an API for managing interrupts compatible with | 3 | //! This module implements an API for managing interrupts compatible with |
| 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 | use core::sync::atomic::{compiler_fence, Ordering}; | ||
| 7 | |||
| 8 | use crate::pac::NVIC_PRIO_BITS; | ||
| 9 | |||
| 10 | // Re-exports | 6 | // Re-exports |
| 11 | pub use embassy::interrupt::{declare, take, Interrupt}; | 7 | pub use embassy::interrupt::{declare, take, Interrupt}; |
| 12 | 8 | pub use embassy_extras::interrupt::Priority4 as Priority; | |
| 13 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] | ||
| 14 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| 15 | #[repr(u8)] | ||
| 16 | pub enum Priority { | ||
| 17 | Level0 = 0, | ||
| 18 | Level1 = 1, | ||
| 19 | Level2 = 2, | ||
| 20 | Level3 = 3, | ||
| 21 | Level4 = 4, | ||
| 22 | Level5 = 5, | ||
| 23 | Level6 = 6, | ||
| 24 | Level7 = 7, | ||
| 25 | Level8 = 8, | ||
| 26 | Level9 = 9, | ||
| 27 | Level10 = 10, | ||
| 28 | Level11 = 11, | ||
| 29 | Level12 = 12, | ||
| 30 | Level13 = 13, | ||
| 31 | Level14 = 14, | ||
| 32 | Level15 = 15, | ||
| 33 | } | ||
| 34 | |||
| 35 | impl From<u8> for Priority { | ||
| 36 | fn from(priority: u8) -> Self { | ||
| 37 | match priority >> (8 - NVIC_PRIO_BITS) { | ||
| 38 | 0 => Self::Level0, | ||
| 39 | 1 => Self::Level1, | ||
| 40 | 2 => Self::Level2, | ||
| 41 | 3 => Self::Level3, | ||
| 42 | 4 => Self::Level4, | ||
| 43 | 5 => Self::Level5, | ||
| 44 | 6 => Self::Level6, | ||
| 45 | 7 => Self::Level7, | ||
| 46 | 8 => Self::Level8, | ||
| 47 | 9 => Self::Level9, | ||
| 48 | 10 => Self::Level10, | ||
| 49 | 11 => Self::Level11, | ||
| 50 | 12 => Self::Level12, | ||
| 51 | 13 => Self::Level13, | ||
| 52 | 14 => Self::Level14, | ||
| 53 | 15 => Self::Level15, | ||
| 54 | _ => unreachable!(), | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | impl From<Priority> for u8 { | ||
| 60 | fn from(p: Priority) -> Self { | ||
| 61 | (p as u8) << (8 - NVIC_PRIO_BITS) | ||
| 62 | } | ||
| 63 | } | ||
| 64 | 9 | ||
| 65 | #[cfg(feature = "stm32f401")] | 10 | #[cfg(feature = "stm32f401")] |
| 66 | mod irqs { | 11 | mod irqs { |
