Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-cloud-client/update-client-hub/modules/atomic-queue/source/atomic-cm3.c@0:276e7a263c35, 2018-07-02 (annotated)
- Committer:
- MACRUM
- Date:
- Mon Jul 02 06:30:39 2018 +0000
- Revision:
- 0:276e7a263c35
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| MACRUM | 0:276e7a263c35 | 1 | // ---------------------------------------------------------------------------- |
| MACRUM | 0:276e7a263c35 | 2 | // Copyright 2015-2017 ARM Ltd. |
| MACRUM | 0:276e7a263c35 | 3 | // |
| MACRUM | 0:276e7a263c35 | 4 | // SPDX-License-Identifier: Apache-2.0 |
| MACRUM | 0:276e7a263c35 | 5 | // |
| MACRUM | 0:276e7a263c35 | 6 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| MACRUM | 0:276e7a263c35 | 7 | // you may not use this file except in compliance with the License. |
| MACRUM | 0:276e7a263c35 | 8 | // You may obtain a copy of the License at |
| MACRUM | 0:276e7a263c35 | 9 | // |
| MACRUM | 0:276e7a263c35 | 10 | // http://www.apache.org/licenses/LICENSE-2.0 |
| MACRUM | 0:276e7a263c35 | 11 | // |
| MACRUM | 0:276e7a263c35 | 12 | // Unless required by applicable law or agreed to in writing, software |
| MACRUM | 0:276e7a263c35 | 13 | // distributed under the License is distributed on an "AS IS" BASIS, |
| MACRUM | 0:276e7a263c35 | 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| MACRUM | 0:276e7a263c35 | 15 | // See the License for the specific language governing permissions and |
| MACRUM | 0:276e7a263c35 | 16 | // limitations under the License. |
| MACRUM | 0:276e7a263c35 | 17 | // ---------------------------------------------------------------------------- |
| MACRUM | 0:276e7a263c35 | 18 | |
| MACRUM | 0:276e7a263c35 | 19 | #include "atomic.h" |
| MACRUM | 0:276e7a263c35 | 20 | |
| MACRUM | 0:276e7a263c35 | 21 | #if defined(TARGET_LIKE_MBED) |
| MACRUM | 0:276e7a263c35 | 22 | #include "cmsis.h" |
| MACRUM | 0:276e7a263c35 | 23 | #endif |
| MACRUM | 0:276e7a263c35 | 24 | |
| MACRUM | 0:276e7a263c35 | 25 | #if defined(__CORTEX_M) && (__CORTEX_M >= 0x03) |
| MACRUM | 0:276e7a263c35 | 26 | |
| MACRUM | 0:276e7a263c35 | 27 | #define STATIC_ASSERT(STATIC_ASSERT_FAILED,MSG)\ |
| MACRUM | 0:276e7a263c35 | 28 | switch(0){\ |
| MACRUM | 0:276e7a263c35 | 29 | case 0:case (STATIC_ASSERT_FAILED): \ |
| MACRUM | 0:276e7a263c35 | 30 | break;} |
| MACRUM | 0:276e7a263c35 | 31 | |
| MACRUM | 0:276e7a263c35 | 32 | #include <stddef.h> |
| MACRUM | 0:276e7a263c35 | 33 | #include <stdint.h> |
| MACRUM | 0:276e7a263c35 | 34 | |
| MACRUM | 0:276e7a263c35 | 35 | int aq_atomic_cas_deref_uintptr(uintptr_t* volatile * ptrAddr, |
| MACRUM | 0:276e7a263c35 | 36 | uintptr_t** currentPtrValue, |
| MACRUM | 0:276e7a263c35 | 37 | uintptr_t expectedDerefValue, |
| MACRUM | 0:276e7a263c35 | 38 | uintptr_t* newPtrValue, |
| MACRUM | 0:276e7a263c35 | 39 | uintptr_t valueOffset) |
| MACRUM | 0:276e7a263c35 | 40 | { |
| MACRUM | 0:276e7a263c35 | 41 | STATIC_ASSERT(sizeof(uintptr_t) == sizeof(uint32_t), Error: Pointer size mismatch) |
| MACRUM | 0:276e7a263c35 | 42 | uint32_t *current; |
| MACRUM | 0:276e7a263c35 | 43 | current = (uint32_t *)__LDREXW((volatile uint32_t *)ptrAddr); |
| MACRUM | 0:276e7a263c35 | 44 | if (currentPtrValue != NULL) { |
| MACRUM | 0:276e7a263c35 | 45 | *currentPtrValue = (uintptr_t *)current; |
| MACRUM | 0:276e7a263c35 | 46 | } |
| MACRUM | 0:276e7a263c35 | 47 | if (current == NULL) { |
| MACRUM | 0:276e7a263c35 | 48 | return AQ_ATOMIC_CAS_DEREF_NULLPTR; |
| MACRUM | 0:276e7a263c35 | 49 | } else if ( *(uint32_t *)((uintptr_t)current + valueOffset) != expectedDerefValue) { |
| MACRUM | 0:276e7a263c35 | 50 | return AQ_ATOMIC_CAS_DEREF_VALUE; |
| MACRUM | 0:276e7a263c35 | 51 | } else if(__STREXW((uint32_t)newPtrValue, (volatile uint32_t *)ptrAddr)) { |
| MACRUM | 0:276e7a263c35 | 52 | return AQ_ATOMIC_CAS_DEREF_INTERUPTED; |
| MACRUM | 0:276e7a263c35 | 53 | } else { |
| MACRUM | 0:276e7a263c35 | 54 | return AQ_ATOMIC_CAS_DEREF_SUCCESS; |
| MACRUM | 0:276e7a263c35 | 55 | } |
| MACRUM | 0:276e7a263c35 | 56 | } |
| MACRUM | 0:276e7a263c35 | 57 | #endif |
| MACRUM | 0:276e7a263c35 | 58 |