bug fix

Dependencies:   HTS221

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers atomic-cm3.c Source File

atomic-cm3.c

00001 // ----------------------------------------------------------------------------
00002 // Copyright 2015-2017 ARM Ltd.
00003 //
00004 // SPDX-License-Identifier: Apache-2.0
00005 //
00006 // Licensed under the Apache License, Version 2.0 (the "License");
00007 // you may not use this file except in compliance with the License.
00008 // You may obtain a copy of the License at
00009 //
00010 //     http://www.apache.org/licenses/LICENSE-2.0
00011 //
00012 // Unless required by applicable law or agreed to in writing, software
00013 // distributed under the License is distributed on an "AS IS" BASIS,
00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 // See the License for the specific language governing permissions and
00016 // limitations under the License.
00017 // ----------------------------------------------------------------------------
00018 
00019 #include "atomic.h"
00020 
00021 #if defined(TARGET_LIKE_MBED)
00022 #include "cmsis.h"
00023 #endif
00024 
00025 #if defined(__CORTEX_M) && (__CORTEX_M >= 0x03)
00026 
00027 #define STATIC_ASSERT(STATIC_ASSERT_FAILED,MSG)\
00028     switch(0){\
00029         case 0:case (STATIC_ASSERT_FAILED): \
00030         break;}
00031 
00032 #include <stddef.h>
00033 #include <stdint.h>
00034 
00035 int aq_atomic_cas_deref_uintptr(uintptr_t* volatile * ptrAddr,
00036                             uintptr_t** currentPtrValue,
00037                             uintptr_t expectedDerefValue,
00038                             uintptr_t* newPtrValue,
00039                             uintptr_t valueOffset)
00040 {
00041     STATIC_ASSERT(sizeof(uintptr_t) == sizeof(uint32_t), Error: Pointer size mismatch)
00042     uint32_t *current;
00043     current = (uint32_t *)__LDREXW((volatile uint32_t *)ptrAddr);
00044     if (currentPtrValue != NULL) {
00045         *currentPtrValue = (uintptr_t *)current;
00046     }
00047     if (current == NULL) {
00048         return AQ_ATOMIC_CAS_DEREF_NULLPTR;
00049     } else if ( *(uint32_t *)((uintptr_t)current + valueOffset) != expectedDerefValue) {
00050         return AQ_ATOMIC_CAS_DEREF_VALUE;
00051     } else if(__STREXW((uint32_t)newPtrValue, (volatile uint32_t *)ptrAddr)) {
00052         return AQ_ATOMIC_CAS_DEREF_INTERUPTED;
00053     } else {
00054         return AQ_ATOMIC_CAS_DEREF_SUCCESS;
00055     }
00056 }
00057 #endif
00058