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 <stddef.h>
MACRUM 0:119624335925 20 #include "atomic.h"
MACRUM 0:119624335925 21
MACRUM 0:119624335925 22 #if defined(TARGET_LIKE_MBED)
MACRUM 0:119624335925 23 #include "cmsis.h"
MACRUM 0:119624335925 24 #endif
MACRUM 0:119624335925 25
MACRUM 0:119624335925 26 #if !defined(__CORTEX_M) || (__CORTEX_M < 0x03)
MACRUM 0:119624335925 27 #include "aq_critical.h"
MACRUM 0:119624335925 28
MACRUM 0:119624335925 29 int aq_atomic_cas_deref_uintptr(uintptr_t* volatile * ptrAddr,
MACRUM 0:119624335925 30 uintptr_t** currentPtrValue,
MACRUM 0:119624335925 31 uintptr_t expectedDerefValue,
MACRUM 0:119624335925 32 uintptr_t* newPtrValue,
MACRUM 0:119624335925 33 uintptr_t valueOffset)
MACRUM 0:119624335925 34 {
MACRUM 0:119624335925 35 int rc;
MACRUM 0:119624335925 36 aq_critical_section_enter();
MACRUM 0:119624335925 37 uintptr_t *current = *ptrAddr;
MACRUM 0:119624335925 38 if (currentPtrValue != NULL) {
MACRUM 0:119624335925 39 *currentPtrValue = current;
MACRUM 0:119624335925 40 }
MACRUM 0:119624335925 41 if (current == NULL) {
MACRUM 0:119624335925 42 rc = AQ_ATOMIC_CAS_DEREF_NULLPTR;
MACRUM 0:119624335925 43 } else if ( *(uintptr_t *)((uintptr_t)current + valueOffset) != expectedDerefValue) {
MACRUM 0:119624335925 44 rc = AQ_ATOMIC_CAS_DEREF_VALUE;
MACRUM 0:119624335925 45 } else {
MACRUM 0:119624335925 46 *ptrAddr = newPtrValue;
MACRUM 0:119624335925 47 rc = AQ_ATOMIC_CAS_DEREF_SUCCESS;
MACRUM 0:119624335925 48 }
MACRUM 0:119624335925 49 aq_critical_section_exit();
MACRUM 0:119624335925 50 return rc;
MACRUM 0:119624335925 51 }
MACRUM 0:119624335925 52 #endif
MACRUM 0:119624335925 53
MACRUM 0:119624335925 54
MACRUM 0:119624335925 55 #if defined(__GNUC__) && (!defined(__CORTEX_M) || (__CORTEX_M >= 0x03))
MACRUM 0:119624335925 56 int aq_atomic_cas_uintptr(uintptr_t *ptr, uintptr_t oldval, uintptr_t newval) {
MACRUM 0:119624335925 57 return __sync_bool_compare_and_swap(ptr, oldval, newval);
MACRUM 0:119624335925 58 }
MACRUM 0:119624335925 59 #else
MACRUM 0:119624335925 60 int aq_atomic_cas_uintptr(uintptr_t *ptr, uintptr_t oldval, uintptr_t newval)
MACRUM 0:119624335925 61 {
MACRUM 0:119624335925 62 int rc;
MACRUM 0:119624335925 63 aq_critical_section_enter();
MACRUM 0:119624335925 64 if (*ptr == oldval) {
MACRUM 0:119624335925 65 rc = 1;
MACRUM 0:119624335925 66 *ptr = newval;
MACRUM 0:119624335925 67 } else {
MACRUM 0:119624335925 68 rc = 0;
MACRUM 0:119624335925 69 }
MACRUM 0:119624335925 70 aq_critical_section_exit();
MACRUM 0:119624335925 71 return rc;
MACRUM 0:119624335925 72 }
MACRUM 0:119624335925 73
MACRUM 0:119624335925 74 #endif