Page 1 of 1

如何彻底关闭中断

Posted: Tue Aug 06, 2019 5:53 am
by jiangteng
现在要实现一个ns级的延时函数,用nop指令已经调试完成,然而问题在于这个延时函数经常被中断,导致延时时间不可控,我在延时函数前后加了
  1. portENTER_CRITICAL(&delay_spinlock);
  2. portEXIT_CRITICAL(&delay_spinlock);
这两个宏,似乎并没有任何作用,延时依然不可控,这是什么原因呢?

Re: 如何彻底关闭中断

Posted: Tue Aug 06, 2019 7:01 am
by ESP_igrr
These 2 macros disable interrupts up to and including level 3. Interrupts level 4 and 5 are still allowed in FreeRTOS critical sections. In practice, you may find that disabling interrupts up to level 4 will give the result you need. Note however that your timing requirements come from some bitbanging procedure, it may be better to use one of the ESP32's peripherals (RMT, I2S) instead.

Re: 如何彻底关闭中断

Posted: Tue Aug 06, 2019 7:35 am
by jiangteng
ESP_igrr wrote:
Tue Aug 06, 2019 7:01 am
These 2 macros disable interrupts up to and including level 3. Interrupts level 4 and 5 are still allowed in FreeRTOS critical sections. In practice, you may find that disabling interrupts up to level 4 will give the result you need. Note however that your timing requirements come from some bitbanging procedure, it may be better to use one of the ESP32's peripherals (RMT, I2S) instead.
Thanks for reply.
Yeah, my timing requirements come from a custom protocal, it's not suitable for stantard peripherals , like I2C etc.
Now I found it works well if I do not start wifi task, so maybe a high level interrupt was allocated to wifi task? which function or macro can disable high level interrupts.

Re: 如何彻底关闭中断

Posted: Tue Aug 06, 2019 9:31 am
by jiangteng
I've tried changing
#define XCHAL_EXCM_LEVEL 3 /* level masked by PS.EXCM */
to
#define XCHAL_EXCM_LEVEL 5 /* level masked by PS.EXCM */

but it doesn't work.