Problem: How do you protect critical code from interrupts on TMS320C6000 digital signal processors?
Solution: Critical code sections are usually those that update shared data accessible by multiple threads in an application. Normally, protecting a code segment involves disabling global interrupts by clearing the global interrupt enable (GIE) bit in the control status register before entering the segment, then restoring the previous value of the GIE bit afterward. The typical code method is shown in the figure above.

These operations require four instructions, three extra cycles and one register (B12). A more efficient way to protect a segment, however, is to use the branch instruction. This method can be especially useful when the critical code segment is short. The branch instruction on C64x DSPs has five delay slots, and instructions that execute in those slots are not interruptible. Using the branch instruction, the above example can be rewritten as shown in the figure below.

More branch instructions can be added (see below), but usually one or two suffice, since up to eight can be executed in each execution packet. Compared with the CPIE bit method of protecting code, branching is faster, safer and doesn't require additional register resources.
Xiangdong Fu (xdfu@ti.com), system applications engineer at Texas Instruments Inc. (Dallas)