File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,23 @@ __attribute__((always_inline)) static inline uint32_t disable_irq(void) {
189
189
return state ;
190
190
}
191
191
192
+ static inline uint32_t raise_irq_pri (uint32_t pri ) {
193
+ uint32_t basepri = __get_BASEPRI ();
194
+ // If non-zero, the processor does not process any exception with a
195
+ // priority value greater than or equal to BASEPRI.
196
+ // When writing to BASEPRI_MAX the write goes to BASEPRI only if either:
197
+ // - Rn is non-zero and the current BASEPRI value is 0
198
+ // - Rn is non-zero and less than the current BASEPRI value
199
+ pri <<= (8 - __NVIC_PRIO_BITS );
200
+ __ASM volatile ("msr basepri_max, %0" : : "r" (pri ) : "memory" );
201
+ return basepri ;
202
+ }
203
+
204
+ // "basepri" should be the value returned from raise_irq_pri
205
+ static inline void restore_irq_pri (uint32_t basepri ) {
206
+ __set_BASEPRI (basepri );
207
+ }
208
+
192
209
#define MICROPY_BEGIN_ATOMIC_SECTION () disable_irq()
193
210
#define MICROPY_END_ATOMIC_SECTION (state ) enable_irq(state)
194
211
Original file line number Diff line number Diff line change @@ -53,8 +53,8 @@ extern ringbuf_t stdin_ringbuf;
53
53
#define mp_hal_pin_od_low (p ) mp_hal_pin_low(p)
54
54
#define mp_hal_pin_od_high (p ) mp_hal_pin_high(p)
55
55
56
- #define mp_hal_quiet_timing_enter () MICROPY_BEGIN_ATOMIC_SECTION( )
57
- #define mp_hal_quiet_timing_exit (irq_state ) MICROPY_END_ATOMIC_SECTION (irq_state)
56
+ #define mp_hal_quiet_timing_enter () raise_irq_pri(1 )
57
+ #define mp_hal_quiet_timing_exit (irq_state ) restore_irq_pri (irq_state)
58
58
59
59
void mp_hal_set_interrupt_char (int c );
60
60
You can’t perform that action at this time.
0 commit comments