mimxrt: Fix mp_hal_quiet_timing_enter()/exit() so timer still runs.

The initial code disabled IRQs, which caused the us-ticks timer to stop.
The change here changes the priotity level, such that the timer still runs.
This commit is contained in:
robert-hh 2021-11-10 13:59:09 +01:00 committed by Damien George
parent 7cc9b257a9
commit 7d7d29dbe2
2 changed files with 19 additions and 2 deletions

View File

@ -189,6 +189,23 @@ __attribute__((always_inline)) static inline uint32_t disable_irq(void) {
return state;
}
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);
}
#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq()
#define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state)

View File

@ -53,8 +53,8 @@ extern ringbuf_t stdin_ringbuf;
#define mp_hal_pin_od_low(p) mp_hal_pin_low(p)
#define mp_hal_pin_od_high(p) mp_hal_pin_high(p)
#define mp_hal_quiet_timing_enter() MICROPY_BEGIN_ATOMIC_SECTION()
#define mp_hal_quiet_timing_exit(irq_state) MICROPY_END_ATOMIC_SECTION(irq_state)
#define mp_hal_quiet_timing_enter() raise_irq_pri(1)
#define mp_hal_quiet_timing_exit(irq_state) restore_irq_pri(irq_state)
void mp_hal_set_interrupt_char(int c);