English
Language : 

PXS20RM Datasheet, PDF (1295/1368 Pages) Freescale Semiconductor, Inc – PXS20 Microcontroller
Semaphore Unit (SEMA4)
• 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 43-1. This function follows the
Hennessy/Patterson example.
Example 43-1. Sample Gatelock Function
#define UNLOCK
0
#define CP0_LOCK 1
#define CP1_LOCK 2
void gateLock (n)
int n;
{
int i;
int current_value;
int locked_value;
/* gate number to lock */
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
Freescale Semiconductor
PXS20 Microcontroller Reference Manual, Rev. 1
43-13