summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-12-04 11:38:23 +0000
committerDamien George <damien.p.george@gmail.com>2015-12-04 11:38:23 +0000
commit95c9cc8114a7dd2bc73dc820d45ba8a97f16a60a (patch)
tree408bd26cfed8a97ecb69950b19b5908d5803c03f
parentadd6f4556ed743e150db3a52f2dcab221ff731f1 (diff)
downloadmicropython-95c9cc8114a7dd2bc73dc820d45ba8a97f16a60a.tar.gz
micropython-95c9cc8114a7dd2bc73dc820d45ba8a97f16a60a.zip
stmhal: Add raise_irq_pri and restore_irq_pri functions.
These can be used to disable only certain interrupts, ones at or above the given priority value.
-rw-r--r--stmhal/irq.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/stmhal/irq.h b/stmhal/irq.h
index 7ebf70e108..878ef460b3 100644
--- a/stmhal/irq.h
+++ b/stmhal/irq.h
@@ -34,6 +34,25 @@ static inline mp_uint_t query_irq(void) {
// enable_irq and disable_irq are defined inline in mpconfigport.h
+// irqs with a priority value greater or equal to "pri" will be disabled
+// "pri" should be between 1 and 15 inclusive
+static inline uint32_t raise_irq_pri(uint32_t pri) {
+ uint32_t basepri = __get_BASEPRI();
+ // If non-zero, the processor does not process any exception with a
+ // priority value greater than or equal to BASEPRI.
+ // When writing to BASEPRI_MAX the write goes to BASEPRI only if either:
+ // - Rn is non-zero and the current BASEPRI value is 0
+ // - Rn is non-zero and less than the current BASEPRI value
+ pri <<= (8 - __NVIC_PRIO_BITS);
+ __ASM volatile ("msr basepri_max, %0" : : "r" (pri) : "memory");
+ return basepri;
+}
+
+// "basepri" should be the value returned from raise_irq_pri
+static inline void restore_irq_pri(uint32_t basepri) {
+ __set_BASEPRI(basepri);
+}
+
MP_DECLARE_CONST_FUN_OBJ(pyb_wfi_obj);
MP_DECLARE_CONST_FUN_OBJ(pyb_disable_irq_obj);
MP_DECLARE_CONST_FUN_OBJ(pyb_enable_irq_obj);