From 9f38a39377a7ff03d0f4371feda083ba09064f5e Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 20 Apr 2022 10:46:03 +0200 Subject: Masks take 3 --- src/export.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/export.rs b/src/export.rs index ed51a9e..0358991 100644 --- a/src/export.rs +++ b/src/export.rs @@ -315,3 +315,27 @@ unsafe fn clear_enable_mask(mask: u32) { pub fn logical2hw(logical: u8, nvic_prio_bits: u8) -> u8 { ((1 << nvic_prio_bits) - logical) << (8 - nvic_prio_bits) } + +#[cfg(not(armv6m))] +pub const fn create_mask(_: [u32; N]) -> u32 { + 0 +} + +#[cfg(armv6m)] +pub const fn create_mask(list_of_shifts: [u32; N]) -> u32 { + let mut mask = 0; + let mut i = 0; + + while i < N { + let shift = list_of_shifts[i]; + i += 1; + + if shift > 31 { + panic!("Generating masks for thumbv6 failed! Are you compiling for thumbv6 on an thumbv7 MCU?"); + } + + mask |= 1 << shift; + } + + mask +} -- cgit v1.2.3 From 0f8bdbdd3f2739e37d788493cb83cf2d9c557f4e Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 20 Apr 2022 13:02:55 +0200 Subject: Added check for resource usage and to generate an compile error for thumbv6 exceptions --- src/export.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/export.rs b/src/export.rs index 0358991..42f3fe2 100644 --- a/src/export.rs +++ b/src/export.rs @@ -339,3 +339,13 @@ pub const fn create_mask(list_of_shifts: [u32; N]) -> u32 { mask } + +#[cfg(not(armv6m))] +pub const fn v6_panic() { + // For non-v6 all is fine +} + +#[cfg(armv6m)] +pub const fn v6_panic() { + panic!("Exceptions with shared resources are not allowed when compiling for thumbv6. Use local resources or `#[lock_free]` shared resources"); +} -- cgit v1.2.3