MDK-ARM Keil, MDK-ARM Datasheet - Page 38

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
38
Chapter 2. Developing With an RTOS
Semaphore Caveats
Semaphores are an extremely useful feature of any RTOS. However,
semaphores can be misused. You must always remember that the number of
tokens in a semaphore is not fixed. During the runtime of a program, semaphore
tokens may be created and destroyed. Sometimes this is useful, but if your code
depends on having a fixed number of tokens available to a semaphore, you must
be very careful to return tokens always back to it. You should also rule out the
possibility of creating additional new tokens.
Mutex
Mutex stands for “Mutual Exclusion”. A Mutex is a specialized version of a
semaphore. Like a semaphore, a Mutex is a container for tokens. The difference
is that a Mutex is initialized with one token. Additional Mutex tokens cannot be
created by tasks. The main use of a Mutex is to control access to a chip resource
such as a peripheral. For this reason, a Mutex token is binary and bounded.
Apart from this, it really works in the same way as a semaphore. First, we must
declare the Mutex container and initialize the Mutex:
os_mut_init (OS_ID mutex);
Then any task needing to access the peripheral must first acquire the Mutex
token:
os_mut_wait (OS_ID mutex, U16 timeout);
Finally, when we are finished with the peripheral, the Mutex must be released:
os_mut_release (OS_ID mutex);
Mutex use is much more rigid than semaphore use, but is a much safer
mechanism when controlling absolute access to underlying chip registers.
Exercise: Mutex
This exercise uses a Mutex to control access to the microcontroller UART.

Related parts for MDK-ARM