39 #ifndef INC_FREERTOS_H 40 #error "include FreeRTOS.h must appear in source files before include atomic.h" 60 #if defined( portSET_INTERRUPT_MASK_FROM_ISR ) 63 #define ATOMIC_ENTER_CRITICAL() \ 64 UBaseType_t uxCriticalSectionType = portSET_INTERRUPT_MASK_FROM_ISR() 66 #define ATOMIC_EXIT_CRITICAL() \ 67 portCLEAR_INTERRUPT_MASK_FROM_ISR( uxCriticalSectionType ) 72 #define ATOMIC_ENTER_CRITICAL() portENTER_CRITICAL() 73 #define ATOMIC_EXIT_CRITICAL() portEXIT_CRITICAL() 84 #ifndef portFORCE_INLINE 85 #define portFORCE_INLINE 88 #define ATOMIC_COMPARE_AND_SWAP_SUCCESS 0x1U 89 #define ATOMIC_COMPARE_AND_SWAP_FAILURE 0x0U 110 uint32_t ulComparand )
112 uint32_t ulReturnValue;
114 ATOMIC_ENTER_CRITICAL();
116 if( *pulDestination == ulComparand )
118 *pulDestination = ulExchange;
126 ATOMIC_EXIT_CRITICAL();
128 return ulReturnValue;
149 ATOMIC_ENTER_CRITICAL();
151 pReturnValue = *ppvDestination;
152 *ppvDestination = pvExchange;
154 ATOMIC_EXIT_CRITICAL();
182 ATOMIC_ENTER_CRITICAL();
184 if( *ppvDestination == pvComparand )
186 *ppvDestination = pvExchange;
190 ATOMIC_EXIT_CRITICAL();
192 return ulReturnValue;
214 ATOMIC_ENTER_CRITICAL();
216 ulCurrent = *pulAddend;
217 *pulAddend += ulCount;
219 ATOMIC_EXIT_CRITICAL();
242 ATOMIC_ENTER_CRITICAL();
244 ulCurrent = *pulAddend;
245 *pulAddend -= ulCount;
247 ATOMIC_EXIT_CRITICAL();
267 ATOMIC_ENTER_CRITICAL();
269 ulCurrent = *pulAddend;
272 ATOMIC_EXIT_CRITICAL();
292 ATOMIC_ENTER_CRITICAL();
294 ulCurrent = *pulAddend;
297 ATOMIC_EXIT_CRITICAL();
315 static portFORCE_INLINE uint32_t
Atomic_OR_u32( uint32_t
volatile * pulDestination,
320 ATOMIC_ENTER_CRITICAL();
322 ulCurrent = *pulDestination;
323 *pulDestination |= ulValue;
325 ATOMIC_EXIT_CRITICAL();
342 static portFORCE_INLINE uint32_t
Atomic_AND_u32( uint32_t
volatile * pulDestination,
347 ATOMIC_ENTER_CRITICAL();
349 ulCurrent = *pulDestination;
350 *pulDestination &= ulValue;
352 ATOMIC_EXIT_CRITICAL();
374 ATOMIC_ENTER_CRITICAL();
376 ulCurrent = *pulDestination;
377 *pulDestination = ~( ulCurrent & ulValue );
379 ATOMIC_EXIT_CRITICAL();
396 static portFORCE_INLINE uint32_t
Atomic_XOR_u32( uint32_t
volatile * pulDestination,
401 ATOMIC_ENTER_CRITICAL();
403 ulCurrent = *pulDestination;
404 *pulDestination ^= ulValue;
406 ATOMIC_EXIT_CRITICAL();
static portFORCE_INLINE void * Atomic_SwapPointers_p32(void *volatile *ppvDestination, void *pvExchange)
Atomically sets the address pointed to by *ppvDestination to the value of *pvExchange.
Definition: atomic.h:144
#define ATOMIC_COMPARE_AND_SWAP_SUCCESS
Definition: atomic.h:88
static portFORCE_INLINE uint32_t Atomic_XOR_u32(uint32_t volatile *pulDestination, uint32_t ulValue)
Performs an atomic XOR operation on the specified values.
Definition: atomic.h:396
static portFORCE_INLINE uint32_t Atomic_AND_u32(uint32_t volatile *pulDestination, uint32_t ulValue)
Performs an atomic AND operation on the specified values.
Definition: atomic.h:342
static portFORCE_INLINE uint32_t Atomic_NAND_u32(uint32_t volatile *pulDestination, uint32_t ulValue)
Performs an atomic NAND operation on the specified values.
Definition: atomic.h:369
#define ATOMIC_COMPARE_AND_SWAP_FAILURE
Definition: atomic.h:89
static portFORCE_INLINE uint32_t Atomic_Decrement_u32(uint32_t volatile *pulAddend)
Atomically decrements the value of the specified pointer points to.
Definition: atomic.h:288
static portFORCE_INLINE uint32_t Atomic_Subtract_u32(uint32_t volatile *pulAddend, uint32_t ulCount)
Atomically subtracts count from the value of the specified pointer pointers to.
Definition: atomic.h:237
static portFORCE_INLINE uint32_t Atomic_OR_u32(uint32_t volatile *pulDestination, uint32_t ulValue)
Performs an atomic OR operation on the specified values.
Definition: atomic.h:315
static portFORCE_INLINE uint32_t Atomic_CompareAndSwap_u32(uint32_t volatile *pulDestination, uint32_t ulExchange, uint32_t ulComparand)
Performs an atomic compare-and-swap operation on the specified values.
Definition: atomic.h:108
static portFORCE_INLINE uint32_t Atomic_CompareAndSwapPointers_p32(void *volatile *ppvDestination, void *pvExchange, void *pvComparand)
Performs an atomic compare-and-swap operation on the specified pointer values.
Definition: atomic.h:176
static portFORCE_INLINE uint32_t Atomic_Increment_u32(uint32_t volatile *pulAddend)
Atomically increments the value of the specified pointer points to.
Definition: atomic.h:263
static portFORCE_INLINE uint32_t Atomic_Add_u32(uint32_t volatile *pulAddend, uint32_t ulCount)
Atomically adds count to the value of the specified pointer points to.
Definition: atomic.h:209