67
11100B–ATARM–31-Jul-12
SAM4S Series [Preliminary]
To perform an exclusive read-modify-write of a memory location, the software must:
1.
Use a Load-Exclusive instruction to read the value of the location.
2.
Update the value, as required.
3.
Use a Store-Exclusive instruction to attempt to write the new value back to the memory
location
4.
Test the returned status bit. If this bit is:
0: The read-modify-write completed successfully.
1: No write was performed. This indicates that the value returned at step 1 might be out of
date. The software must retry the read-modify-write sequence.
The software can use the synchronization primitives to implement a semaphore as follows:
1.
Use a Load-Exclusive instruction to read from the semaphore address to check
whether the semaphore is free.
2.
If the semaphore is free, use a Store-Exclusive instruction to write the claim value to the
semaphore address.
3.
If the returned status bit from step 2 indicates that the Store-Exclusive instruction suc-
ceeded then the software has claimed the semaphore. However, if the Store-Exclusive
instruction failed, another process might have claimed the semaphore after the soft-
ware performed the first step.
The Cortex-M4 includes an exclusive access monitor, that tags the fact that the processor has
executed a Load-Exclusive instruction. If the processor is part of a multiprocessor system, the
system also globally tags the memory locations addressed by exclusive accesses by each
processor.
The processor removes its exclusive access tag if:
• It executes a CLREX instruction
• It executes a Store-Exclusive instruction, regardless of whether the write succeeds.
• An exception occurs. This means that the processor can resolve semaphore conflicts
between different threads.
In a multiprocessor implementation:
• Executing a CLREX instruction removes only the local exclusive access tag for the processor
• executing a Store-Exclusive instruction, or an exception, removes the local exclusive access
tags, and all global exclusive access tags for the processor.
For more information about the synchronization primitive instructions, see
and
11.4.2.8
Programming Hints for the Synchronization Primitives
ISO/IEC C cannot directly generate the exclusive access instructions. CMSIS provides intrinsic
functions for generation of these instructions:
Table 11-8.
CMSIS Functions for Exclusive Access Instructions
Instruction
CMSIS Function
LDREX
uint32_t __LDREXW (uint32_t *addr)
LDREXH uint16_t
__LDREXH
(uint16_t
*addr)
LDREXB
uint8_t __LDREXB (uint8_t *addr)
Summary of Contents for SAM4S Series
Page 44: ...44 11100B ATARM 31 Jul 12 SAM4S Series Preliminary ...
Page 412: ...412 11100B ATARM 31 Jul 12 SAM4S Series Preliminary ...
Page 1105: ...1105 11100B ATARM 31 Jul 12 SAM4S Series Preliminary ...
Page 1143: ...1143 11100B ATARM 31 Jul 12 SAM4S Series Preliminary Figure 43 4 64 lead LQFP Package Drawing ...
Page 1145: ...1145 11100B ATARM 31 Jul 12 SAM4S Series Preliminary Figure 43 5 64 lead QFN Package Drawing ...