File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
3756MP_DECLARE_CONST_FUN_OBJ (pyb_wfi_obj );
3857MP_DECLARE_CONST_FUN_OBJ (pyb_disable_irq_obj );
3958MP_DECLARE_CONST_FUN_OBJ (pyb_enable_irq_obj );
You can’t perform that action at this time.
0 commit comments