Committer:
leothedragon
Date:
Sun Apr 18 15:20:23 2021 +0000
Revision:
0:25fa8795676b
DS

Who changed what in which revision?

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