92 of 318
ZBasic System Library 82 ZX Microcontroller Family DisableInt Type Function returning Byte Invocation DisableInt() Discussion This routine disables interrupts, preventing any interrupt source from interrupting the current task. Most commonly, this function is used to temporarily disable interrupts thereby allowing a sequence of instructions to execute without interruption. Of course, interrupts should be disabled for the shortest possible time in order to avoid missing important interrupts (e.g. real time clock interrupts). If interrupts are disabled for longer than one period of the RTC fast tick (typically 976 uS) you run the risk of missing an RTC tick which will result in the RTC losing time. The most common use for DisableInt() is to implement “atomic access” to variables. This should be done for any variable that occupies multiple bytes of memory (e.g. Integer, Long, etc.) or for a read-modify- write operation on any variable when there is a possibility that another task or interrupt handler might attempt to access the same variable. The value returned by DisableInt() should be passed to EnableInt(). Doing so will allow proper nesting of DisableInt() and EnableInt() calls. Note The Atomic block construct (described in the ZBasic Language Reference Manual) is the preferred method for implementing atomic access. Example Dim iflag as Byte iflag = DisableInt() ' place code here that must not be interrupted Call EnableInt(iflag) See Also EnableInt, UpdateRTC, Yield