This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to disable IRQ to stop occuring uart_evt_handler() for a short time

After I process some data (command) received by UART fifo module (I have installed handler for APP_UART_DATA_READY) I need to do a short atomic operation of a few instructions. What is the best way to disable interrupt(s) in this case? Is NVIC_DisableIRQ(UART0_IRQn) or sd_nvic_DisableIRQ(UART0_IRQn) enough? Or can I use sd_nvic_critical_region_enter() / exit - afaik this disable some other IRQs that I don't care...

  • As far as I understand your question, either of those should be usable. sd_nvic_DisableIRQ() will disable just the UART IRQ, while sd_nvic_critical_region_enter()/_exit() will protect the region against any application interrupt. Depending on what you actually want to achieve, either may make sense.

    Beware that there is a macro wrapping sd_nvic_critical_region_enter() called CRITICAL_REGION_ENTER() in app_util.h, which can be used independent of calling context.

  • In my case I only need to prevent that no other UART IRQ rise during that operation, so I use sd_nvic_DisableIRQ. I also find thare's __disable_irq() but it shouldn't be called during SoftDevice operation because of risk of losing some data. So this mean that CRITICAL_REGION_ENTER() don't disable all interrupts but keeps enabled some used by SoftDevice. Curently I don't need it but it's good to understand this IRQ things...

Related