beautypg.com

Renesas Emulator System M3T-MR100 User Manual

Page 59

background image

- 43 -

4.1.5

Synchronization and Communication Function (Semaphore)

The semaphore is a function executed to coordinate the use of devices and other resources to be shared by several tasks in
cases where the tasks simultaneously require the use of them. When, for instance, four tasks simultaneously try to acquire a
total of only three communication lines as shown in Figure 4.10, communication line-to-task connections can be made
without incurring contention.

Semaphore

Communication

Line

Task

Task

Task

Task

Communication

Line

Communication

Line

Figure 4.10 Exclusive Control by Semaphore

The semaphore has an internal semaphore counter. In accordance with this counter, the semaphore is acquired or released to
prevent competition for use of the same resource.(See Figure 4.11).

Task

Acquired

Returned after use

Figure 4.11 Semaphore Counter

The MR100 kernel offers the following semaphore synchronization service calls.

Release Semaphore Resource(sig_sem, isig_sem)

Releases one resource to the semaphore. This service call wakes up a task that is waiting for the semaphores ser-
vice, or increments the semaphore counter by 1 if no task is waiting for the semaphores service.

Acquire Semaphore Resource(wai_sem, twai_sem)

Waits for the semaphores service. If the semaphore counter value is 0 (zero), the semaphore cannot be acquired.
Therefore, the WAITING state prevails.

Acquire Semaphore Resource(pol_sem, ipol_sem)

Acquires the semaphore resource. If there is no semaphore resource to acquire, an error code is returned and the
WAITING state does not prevail.