Semaphores
MPC5510 Microcontroller Family Reference Manual, Rev. 1
18-12
Freescale Semiconductor
Preliminary
Example 2: Coherent read done with semaphores...
•
The Z1 wants to coherently read a section of shared memory.
•
The Z1 should check that the semaphore for the shared memory is not currently set.
•
The Z1 should set the semaphore for the shared memory to prevent the Z0 from updating the shared
memory.
•
The Z1 will read the required data, then unlock the semaphore.
18.5
Initialization Information
The reset state of the semaphores module allows it to begin operation without the need for any further
initialization. All the internal state machines are cleared by any reset event, allowing the module to
immediately begin operation.
18.6
Application Information
In an operational multi-core system, most interactions involving the semaphores module involves reads
and writes to the SEMA4_GATEn registers for implementation of the hardware-enforced software gate
functions. Typical code segments for gate functions perform the following operations:
•
To lock (close) a gate
— The processor performs a byte write of logical_processor_ 1 to gate[i]
— The processor reads back gate[i] and checks for a value of logical_processor_ 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 gatelck function is shown in
Hennessy/Patterson example.
Example 18-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;