Technical data
Application example for
semaphores
Tasks:
Four CPUs are plugged into an S5-135U. They output status messages to a
status signalling device via a common memory area of the O peripherals
(OW 6). A CPU must output each status message for 10 seconds. Only after
a 10 second output can a new message be output from the same CPU or a
different CPU overwrite the first message. The use of peripheral word OW
6 (extended I/O area, no process image) is controlled by a semaphore.
Only the CPU that was able to reserve this area for itself by disabling
the assigned semaphore can write this message to OW 6. The semaphore
remains disabled for 10 seconds at a time (TIMER T 10). The CPU
re-enables the semaphore only after this timer has elapsed. After the
semaphore has been re-enabled, the other CPUs can access the reserved
area. The new message can then be written to OW 6.
If one CPU attempts to disable a semaphore and the semaphore is already
disabled by a second CPU, the first CPU waits until the next cycle. It
then re-attempts to set the semaphore and output its message.
Implementation:
The following program can run in all four CPUs, each with a different
message. The blocks shown below are loaded.
5 flags are used as follows:
F 10.0 = 1: a message was requested or is being processed
F 10.1 = 1: the semaphore was disabled successfully
F 10.2 = 1: the timer was started
F 10.3 = 1: the message was transmitted
F 10.4 = 1: the semaphore was re-enabled
Continued on next page
FB 0:
MAIN PROGRAM
FB 10:
REPORT
FB 100:
DISABLE SEMAPHORE
FB 110:
OUTPUT REPORT
FB 101:
ENABLE SEMAPHORE
3
Semaphore Operations
CPU 928B Programming Guide
C79000-B8576-C898-01
3 - 75