Skip to content

Commit 95c9cc8

Browse files
committed
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.
1 parent add6f45 commit 95c9cc8

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

stmhal/irq.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ static inline mp_uint_t query_irq(void) {
3434

3535
// enable_irq and disable_irq are defined inline in mpconfigport.h
3636

37+
// irqs with a priority value greater or equal to "pri" will be disabled
38+
// "pri" should be between 1 and 15 inclusive
39+
static inline uint32_t raise_irq_pri(uint32_t pri) {
40+
uint32_t basepri = __get_BASEPRI();
41+
// If non-zero, the processor does not process any exception with a
42+
// priority value greater than or equal to BASEPRI.
43+
// When writing to BASEPRI_MAX the write goes to BASEPRI only if either:
44+
// - Rn is non-zero and the current BASEPRI value is 0
45+
// - Rn is non-zero and less than the current BASEPRI value
46+
pri <<= (8 - __NVIC_PRIO_BITS);
47+
__ASM volatile ("msr basepri_max, %0" : : "r" (pri) : "memory");
48+
return basepri;
49+
}
50+
51+
// "basepri" should be the value returned from raise_irq_pri
52+
static inline void restore_irq_pri(uint32_t basepri) {
53+
__set_BASEPRI(basepri);
54+
}
55+
3756
MP_DECLARE_CONST_FUN_OBJ(pyb_wfi_obj);
3857
MP_DECLARE_CONST_FUN_OBJ(pyb_disable_irq_obj);
3958
MP_DECLARE_CONST_FUN_OBJ(pyb_enable_irq_obj);

0 commit comments

Comments
 (0)