* @file atomic.h\r
* @brief FreeRTOS atomic operation support.\r
*\r
- * This file implements atomic by disabling interrupts globally. \r
- * Implementation with architecture specific atomic instructions \r
- * are to be provided under each compiler directory. \r
+ * This file implements atomic by disabling interrupts globally.\r
+ * Implementation with architecture specific atomic instructions\r
+ * are to be provided under each compiler directory.\r
*/\r
\r
#ifndef ATOMIC_H\r
#define ATOMIC_H\r
\r
#ifndef INC_FREERTOS_H\r
- #error "include FreeRTOS.h must appear in source files before include atomic.h"\r
+ #error "include FreeRTOS.h must appear in source files before include atomic.h"\r
#endif\r
\r
/* Standard includes. */\r
* */\r
#if defined( portSET_INTERRUPT_MASK_FROM_ISR )\r
\r
- /* Nested interrupt scheme is supported in this port. */\r
- #define ATOMIC_ENTER_CRITICAL() \\r
- UBaseType_t uxCriticalSectionType = portSET_INTERRUPT_MASK_FROM_ISR()\r
+ /* Nested interrupt scheme is supported in this port. */\r
+ #define ATOMIC_ENTER_CRITICAL() \\r
+ UBaseType_t uxCriticalSectionType = portSET_INTERRUPT_MASK_FROM_ISR()\r
\r
- #define ATOMIC_EXIT_CRITICAL() \\r
- portCLEAR_INTERRUPT_MASK_FROM_ISR( uxCriticalSectionType )\r
+ #define ATOMIC_EXIT_CRITICAL() \\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxCriticalSectionType )\r
\r
#else\r
\r
- /* Nested interrupt scheme is NOT supported in this port. */\r
- #define ATOMIC_ENTER_CRITICAL() portENTER_CRITICAL()\r
- #define ATOMIC_EXIT_CRITICAL() portEXIT_CRITICAL()\r
+ /* Nested interrupt scheme is NOT supported in this port. */\r
+ #define ATOMIC_ENTER_CRITICAL() portENTER_CRITICAL()\r
+ #define ATOMIC_EXIT_CRITICAL() portEXIT_CRITICAL()\r
\r
#endif /* portSET_INTERRUPT_MASK_FROM_ISR() */\r
\r
-/* Port specific definition -- "always inline". \r
- * Inline is compiler specific, and may not always get inlined depending on your optimization level. \r
- * Also, inline is considerred as performance optimization for atomic. \r
+/* Port specific definition -- "always inline".\r
+ * Inline is compiler specific, and may not always get inlined depending on your optimization level.\r
+ * Also, inline is considerred as performance optimization for atomic.\r
* Thus, if portFORCE_INLINE is not provided by portmacro.h, instead of resulting error,\r
- * simply define it. \r
+ * simply define it.\r
*/\r
#ifndef portFORCE_INLINE\r
- #define portFORCE_INLINE \r
+ #define portFORCE_INLINE\r
#endif\r
\r
-#define ATOMIC_COMPARE_AND_SWAP_SUCCESS 0x1U /**< Compare and swap succeeded, swapped. */\r
-#define ATOMIC_COMPARE_AND_SWAP_FAILURE 0x0U /**< Compare and swap failed, did not swap. */\r
+#define ATOMIC_COMPARE_AND_SWAP_SUCCESS 0x1U /**< Compare and swap succeeded, swapped. */\r
+#define ATOMIC_COMPARE_AND_SWAP_FAILURE 0x0U /**< Compare and swap failed, did not swap. */\r
\r
/*----------------------------- Swap && CAS ------------------------------*/\r
\r
* @brief Performs an atomic compare-and-swap operation on the specified values.\r
*\r
* @param[in, out] pDestination Pointer to memory location from where value is\r
- * to be loaded and checked.\r
- * @param[in] ulExchange If condition meets, write this value to memory.\r
- * @param[in] ulComparand Swap condition.\r
+ * to be loaded and checked.\r
+ * @param[in] ulExchange If condition meets, write this value to memory.\r
+ * @param[in] ulComparand Swap condition.\r
*\r
* @return Unsigned integer of value 1 or 0. 1 for swapped, 0 for not swapped.\r
*\r
* @note This function only swaps *pDestination with ulExchange, if previous\r
- * *pDestination value equals ulComparand.\r
+ * *pDestination value equals ulComparand.\r
*/\r
static portFORCE_INLINE uint32_t Atomic_CompareAndSwap_u32(\r
- uint32_t volatile * pDestination,\r
- uint32_t ulExchange,\r
- uint32_t ulComparand )\r
+ uint32_t volatile * pDestination,\r
+ uint32_t ulExchange,\r
+ uint32_t ulComparand )\r
{\r
\r
- uint32_t ulReturnValue = ATOMIC_COMPARE_AND_SWAP_FAILURE;\r
+ uint32_t ulReturnValue = ATOMIC_COMPARE_AND_SWAP_FAILURE;\r
\r
- ATOMIC_ENTER_CRITICAL();\r
+ ATOMIC_ENTER_CRITICAL();\r
\r
- if ( *pDestination == ulComparand )\r
- {\r
- *pDestination = ulExchange;\r
- ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS;\r
- }\r
+ if ( *pDestination == ulComparand )\r
+ {\r
+ *pDestination = ulExchange;\r
+ ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS;\r
+ }\r
\r
- ATOMIC_EXIT_CRITICAL();\r
+ ATOMIC_EXIT_CRITICAL();\r
\r
- return ulReturnValue;\r
+ return ulReturnValue;\r
\r
}\r
\r
* Atomic swap (pointers)\r
*\r
* @brief Atomically sets the address pointed to by *ppDestination to the value\r
- * of *pExchange.\r
+ * of *pExchange.\r
*\r
* @param[in, out] ppDestination Pointer to memory location from where a pointer\r
- * value is to be loaded and written back to.\r
- * @param[in] pExchange Pointer value to be written to *ppDestination.\r
+ * value is to be loaded and written back to.\r
+ * @param[in] pExchange Pointer value to be written to *ppDestination.\r
*\r
* @return The initial value of *ppDestination.\r
*/\r
static portFORCE_INLINE void * Atomic_SwapPointers_p32(\r
- void * volatile * ppDestination,\r
- void * pExchange )\r
+ void * volatile * ppDestination,\r
+ void * pExchange )\r
{\r
- void * pReturnValue;\r
+ void * pReturnValue;\r
\r
- ATOMIC_ENTER_CRITICAL();\r
+ ATOMIC_ENTER_CRITICAL();\r
\r
- pReturnValue = *ppDestination;\r
+ pReturnValue = *ppDestination;\r
\r
- *ppDestination = pExchange;\r
+ *ppDestination = pExchange;\r
\r
- ATOMIC_EXIT_CRITICAL();\r
+ ATOMIC_EXIT_CRITICAL();\r
\r
- return pReturnValue;\r
+ return pReturnValue;\r
}\r
\r
/**\r
* Atomic compare-and-swap (pointers)\r
*\r
* @brief Performs an atomic compare-and-swap operation on the specified pointer\r
- * values.\r
+ * values.\r
*\r
* @param[in, out] ppDestination Pointer to memory location from where a pointer\r
- * value is to be loaded and checked.\r
- * @param[in] pExchange If condition meets, write this value to memory.\r
- * @param[in] pComparand Swap condition.\r
+ * value is to be loaded and checked.\r
+ * @param[in] pExchange If condition meets, write this value to memory.\r
+ * @param[in] pComparand Swap condition.\r
*\r
* @return Unsigned integer of value 1 or 0. 1 for swapped, 0 for not swapped.\r
*\r
* @note This function only swaps *ppDestination with pExchange, if previous\r
- * *ppDestination value equals pComparand.\r
+ * *ppDestination value equals pComparand.\r
*/\r
static portFORCE_INLINE uint32_t Atomic_CompareAndSwapPointers_p32(\r
- void * volatile * ppDestination,\r
- void * pExchange, void * pComparand )\r
+ void * volatile * ppDestination,\r
+ void * pExchange, void * pComparand )\r
{\r
- uint32_t ulReturnValue = ATOMIC_COMPARE_AND_SWAP_FAILURE;\r
+ uint32_t ulReturnValue = ATOMIC_COMPARE_AND_SWAP_FAILURE;\r
\r
- ATOMIC_ENTER_CRITICAL();\r
+ ATOMIC_ENTER_CRITICAL();\r
\r
- if ( *ppDestination == pComparand )\r
- {\r
- *ppDestination = pExchange;\r
- ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS;\r
- }\r
+ if ( *ppDestination == pComparand )\r
+ {\r
+ *ppDestination = pExchange;\r
+ ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS;\r
+ }\r
\r
- ATOMIC_EXIT_CRITICAL();\r
+ ATOMIC_EXIT_CRITICAL();\r
\r
- return ulReturnValue;\r
+ return ulReturnValue;\r
}\r
\r
\r
* @brief Atomically adds count to the value of the specified pointer points to.\r
*\r
* @param[in,out] pAddend Pointer to memory location from where value is to be\r
- * loaded and written back to.\r
- * @param[in] ulCount Value to be added to *pAddend.\r
+ * loaded and written back to.\r
+ * @param[in] ulCount Value to be added to *pAddend.\r
*\r
* @return previous *pAddend value.\r
*/\r
static portFORCE_INLINE uint32_t Atomic_Add_u32(\r
- uint32_t volatile * pAddend,\r
- uint32_t ulCount )\r
+ uint32_t volatile * pAddend,\r
+ uint32_t ulCount )\r
{\r
- uint32_t ulCurrent;\r
+ uint32_t ulCurrent;\r
\r
- ATOMIC_ENTER_CRITICAL();\r
+ ATOMIC_ENTER_CRITICAL();\r
\r
- ulCurrent = *pAddend;\r
+ ulCurrent = *pAddend;\r
\r
- *pAddend += ulCount;\r
+ *pAddend += ulCount;\r
\r
- ATOMIC_EXIT_CRITICAL();\r
+ ATOMIC_EXIT_CRITICAL();\r
\r
- return ulCurrent;\r
+ return ulCurrent;\r
}\r
\r
/**\r
* Atomic subtract\r
*\r
* @brief Atomically subtracts count from the value of the specified pointer\r
- * pointers to.\r
+ * pointers to.\r
*\r
* @param[in,out] pAddend Pointer to memory location from where value is to be\r
- * loaded and written back to.\r
- * @param[in] ulCount Value to be subtract from *pAddend.\r
+ * loaded and written back to.\r
+ * @param[in] ulCount Value to be subtract from *pAddend.\r
*\r
* @return previous *pAddend value.\r
*/\r
static portFORCE_INLINE uint32_t Atomic_Subtract_u32(\r
- uint32_t volatile * pAddend,\r
- uint32_t ulCount )\r
+ uint32_t volatile * pAddend,\r
+ uint32_t ulCount )\r
{\r
- uint32_t ulCurrent;\r
+ uint32_t ulCurrent;\r
\r
- ATOMIC_ENTER_CRITICAL();\r
+ ATOMIC_ENTER_CRITICAL();\r
\r
- ulCurrent = *pAddend;\r
+ ulCurrent = *pAddend;\r
\r
- *pAddend -= ulCount;\r
+ *pAddend -= ulCount;\r
\r
- ATOMIC_EXIT_CRITICAL();\r
+ ATOMIC_EXIT_CRITICAL();\r
\r
- return ulCurrent;\r
+ return ulCurrent;\r
}\r
\r
/**\r
* @brief Atomically increments the value of the specified pointer points to.\r
*\r
* @param[in,out] pAddend Pointer to memory location from where value is to be\r
- * loaded and written back to.\r
+ * loaded and written back to.\r
*\r
* @return *pAddend value before increment.\r
*/\r
static portFORCE_INLINE uint32_t Atomic_Increment_u32( uint32_t volatile * pAddend )\r
{\r
- uint32_t ulCurrent;\r
+ uint32_t ulCurrent;\r
\r
- ATOMIC_ENTER_CRITICAL();\r
+ ATOMIC_ENTER_CRITICAL();\r
\r
- ulCurrent = *pAddend;\r
+ ulCurrent = *pAddend;\r
\r
- *pAddend += 1;\r
+ *pAddend += 1;\r
\r
- ATOMIC_EXIT_CRITICAL();\r
+ ATOMIC_EXIT_CRITICAL();\r
\r
- return ulCurrent;\r
+ return ulCurrent;\r
}\r
\r
/**\r
* @brief Atomically decrements the value of the specified pointer points to\r
*\r
* @param[in,out] pAddend Pointer to memory location from where value is to be\r
- * loaded and written back to.\r
+ * loaded and written back to.\r
*\r
* @return *pAddend value before decrement.\r
*/\r
static portFORCE_INLINE uint32_t Atomic_Decrement_u32( uint32_t volatile * pAddend )\r
{\r
- uint32_t ulCurrent;\r
+ uint32_t ulCurrent;\r
\r
- ATOMIC_ENTER_CRITICAL();\r
+ ATOMIC_ENTER_CRITICAL();\r
\r
- ulCurrent = *pAddend;\r
+ ulCurrent = *pAddend;\r
\r
- *pAddend -= 1;\r
+ *pAddend -= 1;\r
\r
- ATOMIC_EXIT_CRITICAL();\r
+ ATOMIC_EXIT_CRITICAL();\r
\r
- return ulCurrent;\r
+ return ulCurrent;\r
}\r
\r
/*----------------------------- Bitwise Logical ------------------------------*/\r
* @brief Performs an atomic OR operation on the specified values.\r
*\r
* @param [in, out] pDestination Pointer to memory location from where value is\r
- * to be loaded and written back to.\r
- * @param [in] ulValue Value to be ORed with *pDestination.\r
+ * to be loaded and written back to.\r
+ * @param [in] ulValue Value to be ORed with *pDestination.\r
*\r
* @return The original value of *pDestination.\r
*/\r
static portFORCE_INLINE uint32_t Atomic_OR_u32(\r
- uint32_t volatile * pDestination,\r
- uint32_t ulValue )\r
+ uint32_t volatile * pDestination,\r
+ uint32_t ulValue )\r
{\r
- uint32_t ulCurrent;\r
+ uint32_t ulCurrent;\r
\r
- ATOMIC_ENTER_CRITICAL();\r
+ ATOMIC_ENTER_CRITICAL();\r
\r
- ulCurrent = *pDestination;\r
+ ulCurrent = *pDestination;\r
\r
- *pDestination |= ulValue;\r
+ *pDestination |= ulValue;\r
\r
- ATOMIC_EXIT_CRITICAL();\r
+ ATOMIC_EXIT_CRITICAL();\r
\r
- return ulCurrent;\r
+ return ulCurrent;\r
}\r
\r
/**\r
* @brief Performs an atomic AND operation on the specified values.\r
*\r
* @param [in, out] pDestination Pointer to memory location from where value is\r
- * to be loaded and written back to.\r
- * @param [in] ulValue Value to be ANDed with *pDestination.\r
+ * to be loaded and written back to.\r
+ * @param [in] ulValue Value to be ANDed with *pDestination.\r
*\r
* @return The original value of *pDestination.\r
*/\r
static portFORCE_INLINE uint32_t Atomic_AND_u32(\r
- uint32_t volatile * pDestination,\r
- uint32_t ulValue )\r
+ uint32_t volatile * pDestination,\r
+ uint32_t ulValue )\r
{\r
- uint32_t ulCurrent;\r
+ uint32_t ulCurrent;\r
\r
- ATOMIC_ENTER_CRITICAL();\r
+ ATOMIC_ENTER_CRITICAL();\r
\r
- ulCurrent = *pDestination;\r
+ ulCurrent = *pDestination;\r
\r
- *pDestination &= ulValue;\r
+ *pDestination &= ulValue;\r
\r
- ATOMIC_EXIT_CRITICAL();\r
+ ATOMIC_EXIT_CRITICAL();\r
\r
- return ulCurrent;\r
+ return ulCurrent;\r
}\r
\r
/**\r
* @brief Performs an atomic NAND operation on the specified values.\r
*\r
* @param [in, out] pDestination Pointer to memory location from where value is\r
- * to be loaded and written back to.\r
- * @param [in] ulValue Value to be NANDed with *pDestination.\r
+ * to be loaded and written back to.\r
+ * @param [in] ulValue Value to be NANDed with *pDestination.\r
*\r
* @return The original value of *pDestination.\r
*/\r
static portFORCE_INLINE uint32_t Atomic_NAND_u32(\r
- uint32_t volatile * pDestination,\r
- uint32_t ulValue )\r
+ uint32_t volatile * pDestination,\r
+ uint32_t ulValue )\r
{\r
- uint32_t ulCurrent;\r
+ uint32_t ulCurrent;\r
\r
- ATOMIC_ENTER_CRITICAL();\r
+ ATOMIC_ENTER_CRITICAL();\r
\r
- ulCurrent = *pDestination;\r
+ ulCurrent = *pDestination;\r
\r
- *pDestination = ~(ulCurrent & ulValue);\r
+ *pDestination = ~(ulCurrent & ulValue);\r
\r
- ATOMIC_EXIT_CRITICAL();\r
+ ATOMIC_EXIT_CRITICAL();\r
\r
- return ulCurrent;\r
+ return ulCurrent;\r
}\r
\r
/**\r
* @brief Performs an atomic XOR operation on the specified values.\r
*\r
* @param [in, out] pDestination Pointer to memory location from where value is\r
- * to be loaded and written back to.\r
- * @param [in] ulValue Value to be XORed with *pDestination.\r
+ * to be loaded and written back to.\r
+ * @param [in] ulValue Value to be XORed with *pDestination.\r
*\r
* @return The original value of *pDestination.\r
*/\r
static portFORCE_INLINE uint32_t Atomic_XOR_u32(\r
- uint32_t volatile * pDestination,\r
- uint32_t ulValue )\r
+ uint32_t volatile * pDestination,\r
+ uint32_t ulValue )\r
{\r
- uint32_t ulCurrent;\r
+ uint32_t ulCurrent;\r
\r
- ATOMIC_ENTER_CRITICAL();\r
+ ATOMIC_ENTER_CRITICAL();\r
\r
- ulCurrent = *pDestination;\r
+ ulCurrent = *pDestination;\r
\r
- *pDestination ^= ulValue;\r
+ *pDestination ^= ulValue;\r
\r
- ATOMIC_EXIT_CRITICAL();\r
+ ATOMIC_EXIT_CRITICAL();\r
\r
- return ulCurrent;\r
+ return ulCurrent;\r
}\r
\r
#ifdef __cplusplus\r