MDK-ARM Keil, MDK-ARM Datasheet - Page 37

KIT REALVIEW MCU DEVELOPMENT

MDK-ARM

Manufacturer Part Number
MDK-ARM
Description
KIT REALVIEW MCU DEVELOPMENT
Manufacturer
Keil
Type
Compiler and IDEr
Datasheets

Specifications of MDK-ARM

For Use With/related Products
ARM MCUs
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
Getting Started: Building Applications with RL-ARM
The code for the entry turnstile is duplicated in each of the participating tasks:
os_sem_init(Mutex, 1);
os_sem_init(Entry_Turnstile, 0);
os_sem_init(Exit_Turnstile, 1);
count = 0;
……………
while (1)
……………
In this example, a barrier synchronizes four tasks. As the first task arrives, it will
increment the count variable. Execution continues until it reaches the turnstile
gate os_sem_wait(Entry_Turnstile,0xffff). At this point, the Entry_Turnstile
semaphore is zero. This will cause the task to halt and de-schedule. The same
will happen to the second and third task. When the fourth task enters the
turnstile, the value of count will become four. This causes the
if( count == 4) statement to be executed. Now, a token is placed into the
Entry_Turnstile semaphore. When the fourth task reaches the
os_sem_wait(Entry_Turnstile,0xffff) statement, a token is available, so it can
continue execution. The turnstile gate is now open. Once the fourth task has
passed through the gate, it places a token back into the Entry_Turnstile
semaphore. This allows a waiting task to resume execution. As each waiting
task resumes, it writes a token into the Entry_Turnstile semaphore. The Mutex
semaphore locks access to the critical section of the turnstile. The Mutex
semaphore ensures that each task will exclusively execute the critical section. In
the critical section, the last arriving task will also remove a token from
Exit_Turnstile. This closes the gate of the Exit_Turnstile, as we shall see below.
}
os_sem_wait (Mutex, 0xffff);
count = count+1;
if (count==4)
}
os_sem_send (Mutex);
os_sem_wait (Entry_Turnstile, 0xffff);
os_sem_send (Entry_Turnstile);
os_sem_wait (Mutex, 0xffff);
count = count-1;
if (count==0)
}
os_sem_send (Mutex);
os_sem_wait (Exit_Turnstile,0xffff); );
os_sem_send (Exit_Turnstile);
os_sem_wait (Exit_Turnstile, 0xffff);
os_sem_send (Entry_Turnstile);
os_sem_wait (Entry_Turnstile,0xffff);
os_sem_send (Exit_Turnstile);
{
{
{
// Begin critical section
// End critical section
// Turnstile gate
// Begin critical section
// End critical section
// Turnstile gate
37

Related parts for MDK-ARM