Keil Logo


Information in this article applies to:

  • RTX51 Version 5 and Later


What is the best way to disable all interrupts when working with RTX Full?

The os_disable_isr routine works well for individual interrupts, but I must disable all interrupts to protect a critical section in my application.


In many programs, a critical code section is a section of program code that may not be interrupted. These critical sections typically perform some operation that must be atomic in nature. The typical way to protect a critical section is to disable all interrupts before and re-enable them after the critical section.

The RTX51 documentation recommends against disabling all interrupts and direct manipulation of the interrupt enable register (specifically EA=0). However, there is no better way to disable all interrupts in an application. For example:

EA = 0;        // disable all interrupts
foo();         // your un-interruptible code sequence
               // foo() must not call any RTX51 routines
EA = 1;        // enable all interrupts

There are a few requirements you must consider if you disable and re-enable interrupts this way.

  • The protected code must not invoke any RTX51 kernel routines. These routines assume that interrupts are enabled and may disable and re-enable interrupts on their own (thereby re-enabling interrupts in your critical section).
  • Only change the global interrupt bit. Do not change the individual interrupt enable bits directly. Use os_disable_isr and os_enable_isr.
  • Make certain that the protected code section is short and does not take longer than an RTX51 timer tick to execute. If it does, the timing properties of RTX51 will be compromised and timing will be skewed. The kernel's worst case reaction time is lengthened by the execution time of the critical section.

Note that the RTX51 kernel has no opportunity to interrupt the above sequence since the system timer interrupt (and any other interrupt) is blocked.


Last Reviewed: Friday, April 13, 2007

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.