Dependencies:   MMA7660 LM75B

Committer:
MACRUM
Date:
Sat Jun 30 01:40:30 2018 +0000
Revision:
0:119624335925
Initial commit

Who changed what in which revision?

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