Texas Instruments TMS320C3x User Manual page 200

Texas instruments computer hardware user's guide
Table of Contents

Advertisement

Interlocked Operations
Example 7–8. Busy-Waiting Loop
Example 7–9. Multiprocessor Counter Manipulation
7-16
Example 7–8 shows the implementation of a busy-waiting loop. If location
LOCK is the interlock for a critical section of code, and a nonzero means the
lock is busy, the algorithm for a busy-waiting loop can be used as shown.
LDI
1,R0
L1:
LDII
@LOCK,R1
STII
R0,@LOCK
BNZ
L1
Example 7–9 shows how a location COUNT may contain a count of the number
of times a particular operation must be performed. This operation may be per-
formed by any processor in the system. If the count is 0, the processor waits
until it is nonzero before beginning processing. The example also shows the
algorithm for modifying COUNT correctly.
CT:
OR
LDII
BZ CT
SUBI
STII
Figure 7–2 illustrates multiple 'C3x devices sharing global memory and using the
interlocked instructions as in Example 7–10, Example 7–11, and Example 7–12.
; Put 1 into R0
; Interlocked operation begun
; Contents of LOCK
; Put R0 (= 1) into LOCK, XF0 = 1
; Interlocked operation ended
; Keep trying until LOCK = 0
4,IOF
; XF0 = 1
; Interlocked operation ended
@COUNT,R1
; Interlocked operation begun
; Contents of COUNT
; If COUNT = 0, keep trying
1,R1
; Decrement R1 (= COUNT)
R1,@COUNT
; Update COUNT, XF0 = 1
; Interlocked operation ended
R1
R1

Advertisement

Table of Contents
loading

Table of Contents