Example

Dependencies:   FXAS21002 FXOS8700Q

Committer:
maygup01
Date:
Tue Nov 19 09:49:38 2019 +0000
Revision:
0:11cc2b7889af
Example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maygup01 0:11cc2b7889af 1 // ----------------------------------------------------------------------------
maygup01 0:11cc2b7889af 2 // Copyright 2015-2017 ARM Ltd.
maygup01 0:11cc2b7889af 3 //
maygup01 0:11cc2b7889af 4 // SPDX-License-Identifier: Apache-2.0
maygup01 0:11cc2b7889af 5 //
maygup01 0:11cc2b7889af 6 // Licensed under the Apache License, Version 2.0 (the "License");
maygup01 0:11cc2b7889af 7 // you may not use this file except in compliance with the License.
maygup01 0:11cc2b7889af 8 // You may obtain a copy of the License at
maygup01 0:11cc2b7889af 9 //
maygup01 0:11cc2b7889af 10 // http://www.apache.org/licenses/LICENSE-2.0
maygup01 0:11cc2b7889af 11 //
maygup01 0:11cc2b7889af 12 // Unless required by applicable law or agreed to in writing, software
maygup01 0:11cc2b7889af 13 // distributed under the License is distributed on an "AS IS" BASIS,
maygup01 0:11cc2b7889af 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
maygup01 0:11cc2b7889af 15 // See the License for the specific language governing permissions and
maygup01 0:11cc2b7889af 16 // limitations under the License.
maygup01 0:11cc2b7889af 17 // ----------------------------------------------------------------------------
maygup01 0:11cc2b7889af 18
maygup01 0:11cc2b7889af 19 #include "atomic.h"
maygup01 0:11cc2b7889af 20
maygup01 0:11cc2b7889af 21 #if defined(TARGET_LIKE_MBED)
maygup01 0:11cc2b7889af 22 #include "cmsis.h"
maygup01 0:11cc2b7889af 23 #endif
maygup01 0:11cc2b7889af 24
maygup01 0:11cc2b7889af 25 #if defined(__CORTEX_M) && (__CORTEX_M >= 0x03)
maygup01 0:11cc2b7889af 26
maygup01 0:11cc2b7889af 27 #define STATIC_ASSERT(STATIC_ASSERT_FAILED,MSG)\
maygup01 0:11cc2b7889af 28 switch(0){\
maygup01 0:11cc2b7889af 29 case 0:case (STATIC_ASSERT_FAILED): \
maygup01 0:11cc2b7889af 30 break;}
maygup01 0:11cc2b7889af 31
maygup01 0:11cc2b7889af 32 #include <stddef.h>
maygup01 0:11cc2b7889af 33 #include <stdint.h>
maygup01 0:11cc2b7889af 34
maygup01 0:11cc2b7889af 35 int aq_atomic_cas_deref_uintptr(uintptr_t *volatile *ptrAddr,
maygup01 0:11cc2b7889af 36 uintptr_t **currentPtrValue,
maygup01 0:11cc2b7889af 37 uintptr_t expectedDerefValue,
maygup01 0:11cc2b7889af 38 uintptr_t *newPtrValue,
maygup01 0:11cc2b7889af 39 uintptr_t valueOffset)
maygup01 0:11cc2b7889af 40 {
maygup01 0:11cc2b7889af 41 STATIC_ASSERT(sizeof(uintptr_t) == sizeof(uint32_t), Error: Pointer size mismatch)
maygup01 0:11cc2b7889af 42 uint32_t *current;
maygup01 0:11cc2b7889af 43 current = (uint32_t *)__LDREXW((volatile uint32_t *)ptrAddr);
maygup01 0:11cc2b7889af 44 if (currentPtrValue != NULL) {
maygup01 0:11cc2b7889af 45 *currentPtrValue = (uintptr_t *)current;
maygup01 0:11cc2b7889af 46 }
maygup01 0:11cc2b7889af 47 if (current == NULL) {
maygup01 0:11cc2b7889af 48 return AQ_ATOMIC_CAS_DEREF_NULLPTR;
maygup01 0:11cc2b7889af 49 } else if (*(uint32_t *)((uintptr_t)current + valueOffset) != expectedDerefValue) {
maygup01 0:11cc2b7889af 50 return AQ_ATOMIC_CAS_DEREF_VALUE;
maygup01 0:11cc2b7889af 51 } else if (__STREXW((uint32_t)newPtrValue, (volatile uint32_t *)ptrAddr)) {
maygup01 0:11cc2b7889af 52 return AQ_ATOMIC_CAS_DEREF_INTERUPTED;
maygup01 0:11cc2b7889af 53 } else {
maygup01 0:11cc2b7889af 54 return AQ_ATOMIC_CAS_DEREF_SUCCESS;
maygup01 0:11cc2b7889af 55 }
maygup01 0:11cc2b7889af 56 }
maygup01 0:11cc2b7889af 57 #endif
maygup01 0:11cc2b7889af 58