EasyManua.ls Logo

NXP Semiconductors PXN2020 - Page 425

NXP Semiconductors PXN2020
1376 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Semaphores
PXN20 Microcontroller Reference Manual, Rev. 1
Freescale Semiconductor 15-13
To lock (close) a gate
The processor performs a byte write of logical_processor_number + 1 to gate[i]
The processor reads back gate[i] and checks for a value of logical_processor_number + 1
If the compare indicates the expected value
then the gate is locked; proceed with the protected code segment
else
lock operation failed;
repeat process beginning with byte write to gate[i] in spin-wait loop, or
proceed with another execution path and wait for failed lock interrupt notification
A simple C-language example of a gatelock function is shown in Example 15-1. This function follows the
Hennessy/Patterson example.
Example 15-1. Sample Gatelock Function
#define UNLOCK 0
#define CP0_LOCK 1
#define CP2_LOCK 2
void gateLock (n)
int n; /* gate number to lock */
{
int i;
int current_value;
int locked_value;
i = processor_number(); /* obtain logical CPU number */
if (i == 0)
locked_value = CP0_LOCK;
else
locked_value = CP1_LOCK;
/* read the current value of the gate and wait until the state == UNLOCK */
do {
current_value = gate[n];
} while (current_value != UNLOCK);
/* the current value of the gate == UNLOCK. attempt to lock the gate for this
processor. spin-wait in this loop until gate ownership is obtained */
do {
gate[n] = locked_value; /* write gate with processor_number + 1 */
current_value = gate[n]; /* read gate to verify ownership was obtained */
} while (current_value != locked_value);
}
To unlock (open) a gate
After completing the protected code segment, the locking processor performs a byte write of
zeroes to gate[i], unlocking (opening) the gate
In this example, a reference to processor_number() is used to retrieve this hardware configuration
value. Typically, the logical processor numbers are defined by a hardwired input vector to the individual

Table of Contents

Related product manuals