Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avtolstoy/affa55f36520721797239eee7fbbd50b to your computer and use it in GitHub Desktop.
Save avtolstoy/affa55f36520721797239eee7fbbd50b to your computer and use it in GitHub Desktop.
From 951255695da3e9b3b51138beefc6188ea7e0103e Mon Sep 17 00:00:00 2001
From: Andrey Tolstoy <andrey@enistek.com>
Date: Wed, 27 Apr 2016 19:36:26 +0700
Subject: [PATCH 1/1] HAL_ServicedIRQn() and HAL_WillPreempt()
---
hal/inc/core_hal.h | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/hal/inc/core_hal.h b/hal/inc/core_hal.h
index f972745..bc39ad4 100644
--- a/hal/inc/core_hal.h
+++ b/hal/inc/core_hal.h
@@ -211,21 +211,45 @@ int HAL_System_Backup_Restore(size_t offset, void* buffer, size_t max_length, si
#ifdef USE_STDPERIPH_DRIVER
#if defined(STM32F10X_MD) || defined(STM32F10X_HD)
#include "stm32f10x.h"
-inline bool HAL_IsISR()
-{
- return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
-}
#elif defined(STM32F2XX)
#include "stm32f2xx.h"
+#endif // defined(STM32F10X_MD) || defined(STM32F10X_HD)
+
+#if defined(STM32F10X_MD) || defined(STM32F10X_HD) || defined(STM32F2XX)
inline bool HAL_IsISR()
{
return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0;
}
+inline int32_t HAL_ServicedIRQn()
+{
+ return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) - 16;
+}
+
+static inline bool HAL_WillPreempt(int32_t irqn1, int32_t irqn2)
+{
+ if (irqn1 == irqn2)
+ return false;
+
+ uint32_t priorityGroup = NVIC_GetPriorityGrouping();
+ uint32_t priority1 = NVIC_GetPriority((IRQn_Type)irqn1);
+ uint32_t priority2 = NVIC_GetPriority((IRQn_Type)irqn2);
+ uint32_t p1, sp1, p2, sp2;
+ NVIC_DecodePriority(priority1, priorityGroup, &p1, &sp1);
+ NVIC_DecodePriority(priority2, priorityGroup, &p2, &sp2);
+ if (p1 < p2)
+ return true;
+
+ return false;
+}
#elif PLATFORM_ID==60000
inline bool HAL_IsISR() { return false; }
+inline int32_t HAL_ServicedIRQn() { return 0; }
+inline bool HAL_WillPreempt(int32_t irqn1, int32_t irqn2) { return false; }
#elif PLATFORM_ID==3
inline bool HAL_IsISR() { return false; }
+inline int32_t HAL_ServicedIRQn() { return 0; }
+inline bool HAL_WillPreempt(int32_t irqn1, int32_t irqn2) { return false; }
#else
#error "*** MCU architecture not supported by HAL_IsISR(). ***"
#endif
--
2.5.4 (Apple Git-61)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment