Renesas 70 Manual De Usuario

Descargar
Página de 162
Chapter 3 Introduction to MR308 
   
- 37 - 
3.5.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 3.28, communication 
line-to-task connections can be made without incurring contention. 
 
Semaphore
Communication
Line
Task
Task
Task
Task
Communication
Line
Communication
Line
 
Figure 3.28 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 3.29). 
 
Task
Acquired
Returned after use
 
Figure 3.29 Semaphore Counter 
The MR308 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 service, or increments the semaphore counter by 1 if no task is waiting for the sema-
phores 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 re-
turned and the WAITING state does not prevail.