diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-04-04 20:03:58 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-04 20:03:58 +0000 |
| commit | 72ae46083e64acc012c6b85d3ef7a115657a01e3 (patch) | |
| tree | 024dbdb94cb5537312c5c34f121257265c165bea /rtic-monotonics/src/lib.rs | |
| parent | 064cf19265f72d7f01e0847c545e6250391a2172 (diff) | |
| parent | aeec8bd41bdf3d57098902407ec320f59365641a (diff) | |
Merge #721
721: Added nRF monotonics r=perlindgren a=korken89
Testing completed
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Diffstat (limited to 'rtic-monotonics/src/lib.rs')
| -rw-r--r-- | rtic-monotonics/src/lib.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/rtic-monotonics/src/lib.rs b/rtic-monotonics/src/lib.rs index 6143fd0..04ce4e2 100644 --- a/rtic-monotonics/src/lib.rs +++ b/rtic-monotonics/src/lib.rs @@ -14,6 +14,54 @@ pub mod systick; #[cfg(feature = "rp2040")] pub mod rp2040; +#[cfg(any( + feature = "nrf52810", + feature = "nrf52811", + feature = "nrf52832", + feature = "nrf52833", + feature = "nrf52840", + feature = "nrf5340-app", + feature = "nrf5340-net", + feature = "nrf9160", +))] +pub mod nrf; + +#[allow(dead_code)] +pub(crate) const fn cortex_logical2hw(logical: u8, nvic_prio_bits: u8) -> u8 { + ((1 << nvic_prio_bits) - logical) << (8 - nvic_prio_bits) +} + +#[cfg(any( + feature = "rp2040", + feature = "nrf52810", + feature = "nrf52811", + feature = "nrf52832", + feature = "nrf52833", + feature = "nrf52840", + feature = "nrf5340-app", + feature = "nrf5340-net", + feature = "nrf9160", +))] +pub(crate) unsafe fn set_monotonic_prio( + prio_bits: u8, + interrupt: impl cortex_m::interrupt::InterruptNumber, +) { + extern "C" { + static RTIC_ASYNC_MAX_LOGICAL_PRIO: u8; + } + + let max_prio = RTIC_ASYNC_MAX_LOGICAL_PRIO.max(1).min(1 << prio_bits); + + let hw_prio = crate::cortex_logical2hw(max_prio, prio_bits); + + // We take ownership of the entire IRQ and all settings to it, we only change settings + // for the IRQ we control. + // This will also compile-error in case the NVIC changes in size. + let mut nvic: cortex_m::peripheral::NVIC = core::mem::transmute(()); + + nvic.set_priority(interrupt, hw_prio); +} + /// This marker is implemented on an interrupt token to enforce that the right tokens /// are given to the correct monotonic implementation. /// |
