Formatting changes only.

pull/8/head
Richard Barry 5 years ago
parent dbbebbfcbc
commit dbac79045c

@ -38,7 +38,7 @@
#define ATOMIC_H #define ATOMIC_H
#ifndef INC_FREERTOS_H #ifndef INC_FREERTOS_H
#error "include FreeRTOS.h must appear in source files before include atomic.h" #error "include FreeRTOS.h must appear in source files before include atomic.h"
#endif #endif
/* Standard includes. */ /* Standard includes. */
@ -56,18 +56,18 @@ extern "C" {
* */ * */
#if defined( portSET_INTERRUPT_MASK_FROM_ISR ) #if defined( portSET_INTERRUPT_MASK_FROM_ISR )
/* Nested interrupt scheme is supported in this port. */ /* Nested interrupt scheme is supported in this port. */
#define ATOMIC_ENTER_CRITICAL() \ #define ATOMIC_ENTER_CRITICAL() \
UBaseType_t uxCriticalSectionType = portSET_INTERRUPT_MASK_FROM_ISR() UBaseType_t uxCriticalSectionType = portSET_INTERRUPT_MASK_FROM_ISR()
#define ATOMIC_EXIT_CRITICAL() \ #define ATOMIC_EXIT_CRITICAL() \
portCLEAR_INTERRUPT_MASK_FROM_ISR( uxCriticalSectionType ) portCLEAR_INTERRUPT_MASK_FROM_ISR( uxCriticalSectionType )
#else #else
/* Nested interrupt scheme is NOT supported in this port. */ /* Nested interrupt scheme is NOT supported in this port. */
#define ATOMIC_ENTER_CRITICAL() portENTER_CRITICAL() #define ATOMIC_ENTER_CRITICAL() portENTER_CRITICAL()
#define ATOMIC_EXIT_CRITICAL() portEXIT_CRITICAL() #define ATOMIC_EXIT_CRITICAL() portEXIT_CRITICAL()
#endif /* portSET_INTERRUPT_MASK_FROM_ISR() */ #endif /* portSET_INTERRUPT_MASK_FROM_ISR() */
@ -78,11 +78,11 @@ extern "C" {
* simply define it. * simply define it.
*/ */
#ifndef portFORCE_INLINE #ifndef portFORCE_INLINE
#define portFORCE_INLINE #define portFORCE_INLINE
#endif #endif
#define ATOMIC_COMPARE_AND_SWAP_SUCCESS 0x1U /**< Compare and swap succeeded, swapped. */ #define ATOMIC_COMPARE_AND_SWAP_SUCCESS 0x1U /**< Compare and swap succeeded, swapped. */
#define ATOMIC_COMPARE_AND_SWAP_FAILURE 0x0U /**< Compare and swap failed, did not swap. */ #define ATOMIC_COMPARE_AND_SWAP_FAILURE 0x0U /**< Compare and swap failed, did not swap. */
/*----------------------------- Swap && CAS ------------------------------*/ /*----------------------------- Swap && CAS ------------------------------*/
@ -92,34 +92,34 @@ extern "C" {
* @brief Performs an atomic compare-and-swap operation on the specified values. * @brief Performs an atomic compare-and-swap operation on the specified values.
* *
* @param[in, out] pDestination Pointer to memory location from where value is * @param[in, out] pDestination Pointer to memory location from where value is
* to be loaded and checked. * to be loaded and checked.
* @param[in] ulExchange If condition meets, write this value to memory. * @param[in] ulExchange If condition meets, write this value to memory.
* @param[in] ulComparand Swap condition. * @param[in] ulComparand Swap condition.
* *
* @return Unsigned integer of value 1 or 0. 1 for swapped, 0 for not swapped. * @return Unsigned integer of value 1 or 0. 1 for swapped, 0 for not swapped.
* *
* @note This function only swaps *pDestination with ulExchange, if previous * @note This function only swaps *pDestination with ulExchange, if previous
* *pDestination value equals ulComparand. * *pDestination value equals ulComparand.
*/ */
static portFORCE_INLINE uint32_t Atomic_CompareAndSwap_u32( static portFORCE_INLINE uint32_t Atomic_CompareAndSwap_u32(
uint32_t volatile * pDestination, uint32_t volatile * pDestination,
uint32_t ulExchange, uint32_t ulExchange,
uint32_t ulComparand ) uint32_t ulComparand )
{ {
uint32_t ulReturnValue = ATOMIC_COMPARE_AND_SWAP_FAILURE; uint32_t ulReturnValue = ATOMIC_COMPARE_AND_SWAP_FAILURE;
ATOMIC_ENTER_CRITICAL(); ATOMIC_ENTER_CRITICAL();
if ( *pDestination == ulComparand ) if ( *pDestination == ulComparand )
{ {
*pDestination = ulExchange; *pDestination = ulExchange;
ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS; ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS;
} }
ATOMIC_EXIT_CRITICAL(); ATOMIC_EXIT_CRITICAL();
return ulReturnValue; return ulReturnValue;
} }
@ -127,64 +127,64 @@ static portFORCE_INLINE uint32_t Atomic_CompareAndSwap_u32(
* Atomic swap (pointers) * Atomic swap (pointers)
* *
* @brief Atomically sets the address pointed to by *ppDestination to the value * @brief Atomically sets the address pointed to by *ppDestination to the value
* of *pExchange. * of *pExchange.
* *
* @param[in, out] ppDestination Pointer to memory location from where a pointer * @param[in, out] ppDestination Pointer to memory location from where a pointer
* value is to be loaded and written back to. * value is to be loaded and written back to.
* @param[in] pExchange Pointer value to be written to *ppDestination. * @param[in] pExchange Pointer value to be written to *ppDestination.
* *
* @return The initial value of *ppDestination. * @return The initial value of *ppDestination.
*/ */
static portFORCE_INLINE void * Atomic_SwapPointers_p32( static portFORCE_INLINE void * Atomic_SwapPointers_p32(
void * volatile * ppDestination, void * volatile * ppDestination,
void * pExchange ) void * pExchange )
{ {
void * pReturnValue; void * pReturnValue;
ATOMIC_ENTER_CRITICAL(); ATOMIC_ENTER_CRITICAL();
pReturnValue = *ppDestination; pReturnValue = *ppDestination;
*ppDestination = pExchange; *ppDestination = pExchange;
ATOMIC_EXIT_CRITICAL(); ATOMIC_EXIT_CRITICAL();
return pReturnValue; return pReturnValue;
} }
/** /**
* Atomic compare-and-swap (pointers) * Atomic compare-and-swap (pointers)
* *
* @brief Performs an atomic compare-and-swap operation on the specified pointer * @brief Performs an atomic compare-and-swap operation on the specified pointer
* values. * values.
* *
* @param[in, out] ppDestination Pointer to memory location from where a pointer * @param[in, out] ppDestination Pointer to memory location from where a pointer
* value is to be loaded and checked. * value is to be loaded and checked.
* @param[in] pExchange If condition meets, write this value to memory. * @param[in] pExchange If condition meets, write this value to memory.
* @param[in] pComparand Swap condition. * @param[in] pComparand Swap condition.
* *
* @return Unsigned integer of value 1 or 0. 1 for swapped, 0 for not swapped. * @return Unsigned integer of value 1 or 0. 1 for swapped, 0 for not swapped.
* *
* @note This function only swaps *ppDestination with pExchange, if previous * @note This function only swaps *ppDestination with pExchange, if previous
* *ppDestination value equals pComparand. * *ppDestination value equals pComparand.
*/ */
static portFORCE_INLINE uint32_t Atomic_CompareAndSwapPointers_p32( static portFORCE_INLINE uint32_t Atomic_CompareAndSwapPointers_p32(
void * volatile * ppDestination, void * volatile * ppDestination,
void * pExchange, void * pComparand ) void * pExchange, void * pComparand )
{ {
uint32_t ulReturnValue = ATOMIC_COMPARE_AND_SWAP_FAILURE; uint32_t ulReturnValue = ATOMIC_COMPARE_AND_SWAP_FAILURE;
ATOMIC_ENTER_CRITICAL(); ATOMIC_ENTER_CRITICAL();
if ( *ppDestination == pComparand ) if ( *ppDestination == pComparand )
{ {
*ppDestination = pExchange; *ppDestination = pExchange;
ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS; ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS;
} }
ATOMIC_EXIT_CRITICAL(); ATOMIC_EXIT_CRITICAL();
return ulReturnValue; return ulReturnValue;
} }
@ -196,55 +196,55 @@ static portFORCE_INLINE uint32_t Atomic_CompareAndSwapPointers_p32(
* @brief Atomically adds count to the value of the specified pointer points to. * @brief Atomically adds count to the value of the specified pointer points to.
* *
* @param[in,out] pAddend Pointer to memory location from where value is to be * @param[in,out] pAddend Pointer to memory location from where value is to be
* loaded and written back to. * loaded and written back to.
* @param[in] ulCount Value to be added to *pAddend. * @param[in] ulCount Value to be added to *pAddend.
* *
* @return previous *pAddend value. * @return previous *pAddend value.
*/ */
static portFORCE_INLINE uint32_t Atomic_Add_u32( static portFORCE_INLINE uint32_t Atomic_Add_u32(
uint32_t volatile * pAddend, uint32_t volatile * pAddend,
uint32_t ulCount ) uint32_t ulCount )
{ {
uint32_t ulCurrent; uint32_t ulCurrent;
ATOMIC_ENTER_CRITICAL(); ATOMIC_ENTER_CRITICAL();
ulCurrent = *pAddend; ulCurrent = *pAddend;
*pAddend += ulCount; *pAddend += ulCount;
ATOMIC_EXIT_CRITICAL(); ATOMIC_EXIT_CRITICAL();
return ulCurrent; return ulCurrent;
} }
/** /**
* Atomic subtract * Atomic subtract
* *
* @brief Atomically subtracts count from the value of the specified pointer * @brief Atomically subtracts count from the value of the specified pointer
* pointers to. * pointers to.
* *
* @param[in,out] pAddend Pointer to memory location from where value is to be * @param[in,out] pAddend Pointer to memory location from where value is to be
* loaded and written back to. * loaded and written back to.
* @param[in] ulCount Value to be subtract from *pAddend. * @param[in] ulCount Value to be subtract from *pAddend.
* *
* @return previous *pAddend value. * @return previous *pAddend value.
*/ */
static portFORCE_INLINE uint32_t Atomic_Subtract_u32( static portFORCE_INLINE uint32_t Atomic_Subtract_u32(
uint32_t volatile * pAddend, uint32_t volatile * pAddend,
uint32_t ulCount ) uint32_t ulCount )
{ {
uint32_t ulCurrent; uint32_t ulCurrent;
ATOMIC_ENTER_CRITICAL(); ATOMIC_ENTER_CRITICAL();
ulCurrent = *pAddend; ulCurrent = *pAddend;
*pAddend -= ulCount; *pAddend -= ulCount;
ATOMIC_EXIT_CRITICAL(); ATOMIC_EXIT_CRITICAL();
return ulCurrent; return ulCurrent;
} }
/** /**
@ -253,23 +253,23 @@ static portFORCE_INLINE uint32_t Atomic_Subtract_u32(
* @brief Atomically increments the value of the specified pointer points to. * @brief Atomically increments the value of the specified pointer points to.
* *
* @param[in,out] pAddend Pointer to memory location from where value is to be * @param[in,out] pAddend Pointer to memory location from where value is to be
* loaded and written back to. * loaded and written back to.
* *
* @return *pAddend value before increment. * @return *pAddend value before increment.
*/ */
static portFORCE_INLINE uint32_t Atomic_Increment_u32( uint32_t volatile * pAddend ) static portFORCE_INLINE uint32_t Atomic_Increment_u32( uint32_t volatile * pAddend )
{ {
uint32_t ulCurrent; uint32_t ulCurrent;
ATOMIC_ENTER_CRITICAL(); ATOMIC_ENTER_CRITICAL();
ulCurrent = *pAddend; ulCurrent = *pAddend;
*pAddend += 1; *pAddend += 1;
ATOMIC_EXIT_CRITICAL(); ATOMIC_EXIT_CRITICAL();
return ulCurrent; return ulCurrent;
} }
/** /**
@ -278,23 +278,23 @@ static portFORCE_INLINE uint32_t Atomic_Increment_u32( uint32_t volatile * pAdde
* @brief Atomically decrements the value of the specified pointer points to * @brief Atomically decrements the value of the specified pointer points to
* *
* @param[in,out] pAddend Pointer to memory location from where value is to be * @param[in,out] pAddend Pointer to memory location from where value is to be
* loaded and written back to. * loaded and written back to.
* *
* @return *pAddend value before decrement. * @return *pAddend value before decrement.
*/ */
static portFORCE_INLINE uint32_t Atomic_Decrement_u32( uint32_t volatile * pAddend ) static portFORCE_INLINE uint32_t Atomic_Decrement_u32( uint32_t volatile * pAddend )
{ {
uint32_t ulCurrent; uint32_t ulCurrent;
ATOMIC_ENTER_CRITICAL(); ATOMIC_ENTER_CRITICAL();
ulCurrent = *pAddend; ulCurrent = *pAddend;
*pAddend -= 1; *pAddend -= 1;
ATOMIC_EXIT_CRITICAL(); ATOMIC_EXIT_CRITICAL();
return ulCurrent; return ulCurrent;
} }
/*----------------------------- Bitwise Logical ------------------------------*/ /*----------------------------- Bitwise Logical ------------------------------*/
@ -305,26 +305,26 @@ static portFORCE_INLINE uint32_t Atomic_Decrement_u32( uint32_t volatile * pAdde
* @brief Performs an atomic OR operation on the specified values. * @brief Performs an atomic OR operation on the specified values.
* *
* @param [in, out] pDestination Pointer to memory location from where value is * @param [in, out] pDestination Pointer to memory location from where value is
* to be loaded and written back to. * to be loaded and written back to.
* @param [in] ulValue Value to be ORed with *pDestination. * @param [in] ulValue Value to be ORed with *pDestination.
* *
* @return The original value of *pDestination. * @return The original value of *pDestination.
*/ */
static portFORCE_INLINE uint32_t Atomic_OR_u32( static portFORCE_INLINE uint32_t Atomic_OR_u32(
uint32_t volatile * pDestination, uint32_t volatile * pDestination,
uint32_t ulValue ) uint32_t ulValue )
{ {
uint32_t ulCurrent; uint32_t ulCurrent;
ATOMIC_ENTER_CRITICAL(); ATOMIC_ENTER_CRITICAL();
ulCurrent = *pDestination; ulCurrent = *pDestination;
*pDestination |= ulValue; *pDestination |= ulValue;
ATOMIC_EXIT_CRITICAL(); ATOMIC_EXIT_CRITICAL();
return ulCurrent; return ulCurrent;
} }
/** /**
@ -333,26 +333,26 @@ static portFORCE_INLINE uint32_t Atomic_OR_u32(
* @brief Performs an atomic AND operation on the specified values. * @brief Performs an atomic AND operation on the specified values.
* *
* @param [in, out] pDestination Pointer to memory location from where value is * @param [in, out] pDestination Pointer to memory location from where value is
* to be loaded and written back to. * to be loaded and written back to.
* @param [in] ulValue Value to be ANDed with *pDestination. * @param [in] ulValue Value to be ANDed with *pDestination.
* *
* @return The original value of *pDestination. * @return The original value of *pDestination.
*/ */
static portFORCE_INLINE uint32_t Atomic_AND_u32( static portFORCE_INLINE uint32_t Atomic_AND_u32(
uint32_t volatile * pDestination, uint32_t volatile * pDestination,
uint32_t ulValue ) uint32_t ulValue )
{ {
uint32_t ulCurrent; uint32_t ulCurrent;
ATOMIC_ENTER_CRITICAL(); ATOMIC_ENTER_CRITICAL();
ulCurrent = *pDestination; ulCurrent = *pDestination;
*pDestination &= ulValue; *pDestination &= ulValue;
ATOMIC_EXIT_CRITICAL(); ATOMIC_EXIT_CRITICAL();
return ulCurrent; return ulCurrent;
} }
/** /**
@ -361,26 +361,26 @@ static portFORCE_INLINE uint32_t Atomic_AND_u32(
* @brief Performs an atomic NAND operation on the specified values. * @brief Performs an atomic NAND operation on the specified values.
* *
* @param [in, out] pDestination Pointer to memory location from where value is * @param [in, out] pDestination Pointer to memory location from where value is
* to be loaded and written back to. * to be loaded and written back to.
* @param [in] ulValue Value to be NANDed with *pDestination. * @param [in] ulValue Value to be NANDed with *pDestination.
* *
* @return The original value of *pDestination. * @return The original value of *pDestination.
*/ */
static portFORCE_INLINE uint32_t Atomic_NAND_u32( static portFORCE_INLINE uint32_t Atomic_NAND_u32(
uint32_t volatile * pDestination, uint32_t volatile * pDestination,
uint32_t ulValue ) uint32_t ulValue )
{ {
uint32_t ulCurrent; uint32_t ulCurrent;
ATOMIC_ENTER_CRITICAL(); ATOMIC_ENTER_CRITICAL();
ulCurrent = *pDestination; ulCurrent = *pDestination;
*pDestination = ~(ulCurrent & ulValue); *pDestination = ~(ulCurrent & ulValue);
ATOMIC_EXIT_CRITICAL(); ATOMIC_EXIT_CRITICAL();
return ulCurrent; return ulCurrent;
} }
/** /**
@ -389,26 +389,26 @@ static portFORCE_INLINE uint32_t Atomic_NAND_u32(
* @brief Performs an atomic XOR operation on the specified values. * @brief Performs an atomic XOR operation on the specified values.
* *
* @param [in, out] pDestination Pointer to memory location from where value is * @param [in, out] pDestination Pointer to memory location from where value is
* to be loaded and written back to. * to be loaded and written back to.
* @param [in] ulValue Value to be XORed with *pDestination. * @param [in] ulValue Value to be XORed with *pDestination.
* *
* @return The original value of *pDestination. * @return The original value of *pDestination.
*/ */
static portFORCE_INLINE uint32_t Atomic_XOR_u32( static portFORCE_INLINE uint32_t Atomic_XOR_u32(
uint32_t volatile * pDestination, uint32_t volatile * pDestination,
uint32_t ulValue ) uint32_t ulValue )
{ {
uint32_t ulCurrent; uint32_t ulCurrent;
ATOMIC_ENTER_CRITICAL(); ATOMIC_ENTER_CRITICAL();
ulCurrent = *pDestination; ulCurrent = *pDestination;
*pDestination ^= ulValue; *pDestination ^= ulValue;
ATOMIC_EXIT_CRITICAL(); ATOMIC_EXIT_CRITICAL();
return ulCurrent; return ulCurrent;
} }
#ifdef __cplusplus #ifdef __cplusplus

Loading…
Cancel
Save