Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Simon Cooksey 0:fb7af294d5d9 1 /*
Simon Cooksey 0:fb7af294d5d9 2 * Copyright (c) 2015-2016, ARM Limited, All Rights Reserved
Simon Cooksey 0:fb7af294d5d9 3 * SPDX-License-Identifier: Apache-2.0
Simon Cooksey 0:fb7af294d5d9 4 *
Simon Cooksey 0:fb7af294d5d9 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Simon Cooksey 0:fb7af294d5d9 6 * not use this file except in compliance with the License.
Simon Cooksey 0:fb7af294d5d9 7 * You may obtain a copy of the License at
Simon Cooksey 0:fb7af294d5d9 8 *
Simon Cooksey 0:fb7af294d5d9 9 * http://www.apache.org/licenses/LICENSE-2.0
Simon Cooksey 0:fb7af294d5d9 10 *
Simon Cooksey 0:fb7af294d5d9 11 * Unless required by applicable law or agreed to in writing, software
Simon Cooksey 0:fb7af294d5d9 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Simon Cooksey 0:fb7af294d5d9 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Simon Cooksey 0:fb7af294d5d9 14 * See the License for the specific language governing permissions and
Simon Cooksey 0:fb7af294d5d9 15 * limitations under the License.
Simon Cooksey 0:fb7af294d5d9 16 */
Simon Cooksey 0:fb7af294d5d9 17
Simon Cooksey 0:fb7af294d5d9 18 #include "platform/critical.h"
Simon Cooksey 0:fb7af294d5d9 19
Simon Cooksey 0:fb7af294d5d9 20 #include "cmsis.h"
Simon Cooksey 0:fb7af294d5d9 21 #include "platform/mbed_assert.h"
Simon Cooksey 0:fb7af294d5d9 22 #include "platform/toolchain.h"
Simon Cooksey 0:fb7af294d5d9 23
Simon Cooksey 0:fb7af294d5d9 24 #define EXCLUSIVE_ACCESS (!defined (__CORTEX_M0) && !defined (__CORTEX_M0PLUS))
Simon Cooksey 0:fb7af294d5d9 25
Simon Cooksey 0:fb7af294d5d9 26 static volatile uint32_t interrupt_enable_counter = 0;
Simon Cooksey 0:fb7af294d5d9 27 static volatile bool critical_interrupts_disabled = false;
Simon Cooksey 0:fb7af294d5d9 28
Simon Cooksey 0:fb7af294d5d9 29 bool core_util_are_interrupts_enabled(void)
Simon Cooksey 0:fb7af294d5d9 30 {
Simon Cooksey 0:fb7af294d5d9 31 #if defined(__CORTEX_A9)
Simon Cooksey 0:fb7af294d5d9 32 return ((__get_CPSR() & 0x80) == 0);
Simon Cooksey 0:fb7af294d5d9 33 #else
Simon Cooksey 0:fb7af294d5d9 34 return ((__get_PRIMASK() & 0x1) == 0);
Simon Cooksey 0:fb7af294d5d9 35 #endif
Simon Cooksey 0:fb7af294d5d9 36 }
Simon Cooksey 0:fb7af294d5d9 37
Simon Cooksey 0:fb7af294d5d9 38 MBED_WEAK void core_util_critical_section_enter(void)
Simon Cooksey 0:fb7af294d5d9 39 {
Simon Cooksey 0:fb7af294d5d9 40 bool interrupts_disabled = !core_util_are_interrupts_enabled();
Simon Cooksey 0:fb7af294d5d9 41 __disable_irq();
Simon Cooksey 0:fb7af294d5d9 42
Simon Cooksey 0:fb7af294d5d9 43 /* Save the interrupt disabled state as it was prior to any nested critical section lock use */
Simon Cooksey 0:fb7af294d5d9 44 if (!interrupt_enable_counter) {
Simon Cooksey 0:fb7af294d5d9 45 critical_interrupts_disabled = interrupts_disabled;
Simon Cooksey 0:fb7af294d5d9 46 }
Simon Cooksey 0:fb7af294d5d9 47
Simon Cooksey 0:fb7af294d5d9 48 /* If the interrupt_enable_counter overflows or we are in a nested critical section and interrupts
Simon Cooksey 0:fb7af294d5d9 49 are enabled, then something has gone badly wrong thus assert an error.
Simon Cooksey 0:fb7af294d5d9 50 */
Simon Cooksey 0:fb7af294d5d9 51 MBED_ASSERT(interrupt_enable_counter < UINT32_MAX);
Simon Cooksey 0:fb7af294d5d9 52 // FIXME
Simon Cooksey 0:fb7af294d5d9 53 #ifndef FEATURE_UVISOR
Simon Cooksey 0:fb7af294d5d9 54 if (interrupt_enable_counter > 0) {
Simon Cooksey 0:fb7af294d5d9 55 MBED_ASSERT(interrupts_disabled);
Simon Cooksey 0:fb7af294d5d9 56 }
Simon Cooksey 0:fb7af294d5d9 57 #else
Simon Cooksey 0:fb7af294d5d9 58 #warning "core_util_critical_section_enter needs fixing to work from unprivileged code"
Simon Cooksey 0:fb7af294d5d9 59 #endif /* FEATURE_UVISOR */
Simon Cooksey 0:fb7af294d5d9 60 interrupt_enable_counter++;
Simon Cooksey 0:fb7af294d5d9 61 }
Simon Cooksey 0:fb7af294d5d9 62
Simon Cooksey 0:fb7af294d5d9 63 MBED_WEAK void core_util_critical_section_exit(void)
Simon Cooksey 0:fb7af294d5d9 64 {
Simon Cooksey 0:fb7af294d5d9 65 /* If critical_section_enter has not previously been called, do nothing */
Simon Cooksey 0:fb7af294d5d9 66 if (interrupt_enable_counter) {
Simon Cooksey 0:fb7af294d5d9 67
Simon Cooksey 0:fb7af294d5d9 68 // FIXME
Simon Cooksey 0:fb7af294d5d9 69 #ifndef FEATURE_UVISOR
Simon Cooksey 0:fb7af294d5d9 70 bool interrupts_disabled = !core_util_are_interrupts_enabled(); /* get the current interrupt disabled state */
Simon Cooksey 0:fb7af294d5d9 71
Simon Cooksey 0:fb7af294d5d9 72 MBED_ASSERT(interrupts_disabled); /* Interrupts must be disabled on invoking an exit from a critical section */
Simon Cooksey 0:fb7af294d5d9 73 #else
Simon Cooksey 0:fb7af294d5d9 74 #warning "core_util_critical_section_exit needs fixing to work from unprivileged code"
Simon Cooksey 0:fb7af294d5d9 75 #endif /* FEATURE_UVISOR */
Simon Cooksey 0:fb7af294d5d9 76
Simon Cooksey 0:fb7af294d5d9 77 interrupt_enable_counter--;
Simon Cooksey 0:fb7af294d5d9 78
Simon Cooksey 0:fb7af294d5d9 79 /* Only re-enable interrupts if we are exiting the last of the nested critical sections and
Simon Cooksey 0:fb7af294d5d9 80 interrupts were enabled on entry to the first critical section.
Simon Cooksey 0:fb7af294d5d9 81 */
Simon Cooksey 0:fb7af294d5d9 82 if (!interrupt_enable_counter && !critical_interrupts_disabled) {
Simon Cooksey 0:fb7af294d5d9 83 __enable_irq();
Simon Cooksey 0:fb7af294d5d9 84 }
Simon Cooksey 0:fb7af294d5d9 85 }
Simon Cooksey 0:fb7af294d5d9 86 }
Simon Cooksey 0:fb7af294d5d9 87
Simon Cooksey 0:fb7af294d5d9 88 #if EXCLUSIVE_ACCESS
Simon Cooksey 0:fb7af294d5d9 89
Simon Cooksey 0:fb7af294d5d9 90 /* Supress __ldrex and __strex deprecated warnings - "#3731-D: intrinsic is deprecated" */
Simon Cooksey 0:fb7af294d5d9 91 #if defined (__CC_ARM)
Simon Cooksey 0:fb7af294d5d9 92 #pragma diag_suppress 3731
Simon Cooksey 0:fb7af294d5d9 93 #endif
Simon Cooksey 0:fb7af294d5d9 94
Simon Cooksey 0:fb7af294d5d9 95 bool core_util_atomic_cas_u8(uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue)
Simon Cooksey 0:fb7af294d5d9 96 {
Simon Cooksey 0:fb7af294d5d9 97 uint8_t currentValue = __LDREXB((volatile uint8_t*)ptr);
Simon Cooksey 0:fb7af294d5d9 98 if (currentValue != *expectedCurrentValue) {
Simon Cooksey 0:fb7af294d5d9 99 *expectedCurrentValue = currentValue;
Simon Cooksey 0:fb7af294d5d9 100 __CLREX();
Simon Cooksey 0:fb7af294d5d9 101 return false;
Simon Cooksey 0:fb7af294d5d9 102 }
Simon Cooksey 0:fb7af294d5d9 103
Simon Cooksey 0:fb7af294d5d9 104 return !__STREXB(desiredValue, (volatile uint8_t*)ptr);
Simon Cooksey 0:fb7af294d5d9 105 }
Simon Cooksey 0:fb7af294d5d9 106
Simon Cooksey 0:fb7af294d5d9 107 bool core_util_atomic_cas_u16(uint16_t *ptr, uint16_t *expectedCurrentValue, uint16_t desiredValue)
Simon Cooksey 0:fb7af294d5d9 108 {
Simon Cooksey 0:fb7af294d5d9 109 uint16_t currentValue = __LDREXH((volatile uint16_t*)ptr);
Simon Cooksey 0:fb7af294d5d9 110 if (currentValue != *expectedCurrentValue) {
Simon Cooksey 0:fb7af294d5d9 111 *expectedCurrentValue = currentValue;
Simon Cooksey 0:fb7af294d5d9 112 __CLREX();
Simon Cooksey 0:fb7af294d5d9 113 return false;
Simon Cooksey 0:fb7af294d5d9 114 }
Simon Cooksey 0:fb7af294d5d9 115
Simon Cooksey 0:fb7af294d5d9 116 return !__STREXH(desiredValue, (volatile uint16_t*)ptr);
Simon Cooksey 0:fb7af294d5d9 117 }
Simon Cooksey 0:fb7af294d5d9 118
Simon Cooksey 0:fb7af294d5d9 119
Simon Cooksey 0:fb7af294d5d9 120 bool core_util_atomic_cas_u32(uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue)
Simon Cooksey 0:fb7af294d5d9 121 {
Simon Cooksey 0:fb7af294d5d9 122 uint32_t currentValue = __LDREXW((volatile uint32_t*)ptr);
Simon Cooksey 0:fb7af294d5d9 123 if (currentValue != *expectedCurrentValue) {
Simon Cooksey 0:fb7af294d5d9 124 *expectedCurrentValue = currentValue;
Simon Cooksey 0:fb7af294d5d9 125 __CLREX();
Simon Cooksey 0:fb7af294d5d9 126 return false;
Simon Cooksey 0:fb7af294d5d9 127 }
Simon Cooksey 0:fb7af294d5d9 128
Simon Cooksey 0:fb7af294d5d9 129 return !__STREXW(desiredValue, (volatile uint32_t*)ptr);
Simon Cooksey 0:fb7af294d5d9 130 }
Simon Cooksey 0:fb7af294d5d9 131
Simon Cooksey 0:fb7af294d5d9 132 uint8_t core_util_atomic_incr_u8(uint8_t *valuePtr, uint8_t delta)
Simon Cooksey 0:fb7af294d5d9 133 {
Simon Cooksey 0:fb7af294d5d9 134 uint8_t newValue;
Simon Cooksey 0:fb7af294d5d9 135 do {
Simon Cooksey 0:fb7af294d5d9 136 newValue = __LDREXB((volatile uint8_t*)valuePtr) + delta;
Simon Cooksey 0:fb7af294d5d9 137 } while (__STREXB(newValue, (volatile uint8_t*)valuePtr));
Simon Cooksey 0:fb7af294d5d9 138 return newValue;
Simon Cooksey 0:fb7af294d5d9 139 }
Simon Cooksey 0:fb7af294d5d9 140
Simon Cooksey 0:fb7af294d5d9 141 uint16_t core_util_atomic_incr_u16(uint16_t *valuePtr, uint16_t delta)
Simon Cooksey 0:fb7af294d5d9 142 {
Simon Cooksey 0:fb7af294d5d9 143 uint16_t newValue;
Simon Cooksey 0:fb7af294d5d9 144 do {
Simon Cooksey 0:fb7af294d5d9 145 newValue = __LDREXH((volatile uint16_t*)valuePtr) + delta;
Simon Cooksey 0:fb7af294d5d9 146 } while (__STREXH(newValue, (volatile uint16_t*)valuePtr));
Simon Cooksey 0:fb7af294d5d9 147 return newValue;
Simon Cooksey 0:fb7af294d5d9 148 }
Simon Cooksey 0:fb7af294d5d9 149
Simon Cooksey 0:fb7af294d5d9 150 uint32_t core_util_atomic_incr_u32(uint32_t *valuePtr, uint32_t delta)
Simon Cooksey 0:fb7af294d5d9 151 {
Simon Cooksey 0:fb7af294d5d9 152 uint32_t newValue;
Simon Cooksey 0:fb7af294d5d9 153 do {
Simon Cooksey 0:fb7af294d5d9 154 newValue = __LDREXW((volatile uint32_t*)valuePtr) + delta;
Simon Cooksey 0:fb7af294d5d9 155 } while (__STREXW(newValue, (volatile uint32_t*)valuePtr));
Simon Cooksey 0:fb7af294d5d9 156 return newValue;
Simon Cooksey 0:fb7af294d5d9 157 }
Simon Cooksey 0:fb7af294d5d9 158
Simon Cooksey 0:fb7af294d5d9 159
Simon Cooksey 0:fb7af294d5d9 160 uint8_t core_util_atomic_decr_u8(uint8_t *valuePtr, uint8_t delta)
Simon Cooksey 0:fb7af294d5d9 161 {
Simon Cooksey 0:fb7af294d5d9 162 uint8_t newValue;
Simon Cooksey 0:fb7af294d5d9 163 do {
Simon Cooksey 0:fb7af294d5d9 164 newValue = __LDREXB((volatile uint8_t*)valuePtr) - delta;
Simon Cooksey 0:fb7af294d5d9 165 } while (__STREXB(newValue, (volatile uint8_t*)valuePtr));
Simon Cooksey 0:fb7af294d5d9 166 return newValue;
Simon Cooksey 0:fb7af294d5d9 167 }
Simon Cooksey 0:fb7af294d5d9 168
Simon Cooksey 0:fb7af294d5d9 169 uint16_t core_util_atomic_decr_u16(uint16_t *valuePtr, uint16_t delta)
Simon Cooksey 0:fb7af294d5d9 170 {
Simon Cooksey 0:fb7af294d5d9 171 uint16_t newValue;
Simon Cooksey 0:fb7af294d5d9 172 do {
Simon Cooksey 0:fb7af294d5d9 173 newValue = __LDREXH((volatile uint16_t*)valuePtr) - delta;
Simon Cooksey 0:fb7af294d5d9 174 } while (__STREXH(newValue, (volatile uint16_t*)valuePtr));
Simon Cooksey 0:fb7af294d5d9 175 return newValue;
Simon Cooksey 0:fb7af294d5d9 176 }
Simon Cooksey 0:fb7af294d5d9 177
Simon Cooksey 0:fb7af294d5d9 178 uint32_t core_util_atomic_decr_u32(uint32_t *valuePtr, uint32_t delta)
Simon Cooksey 0:fb7af294d5d9 179 {
Simon Cooksey 0:fb7af294d5d9 180 uint32_t newValue;
Simon Cooksey 0:fb7af294d5d9 181 do {
Simon Cooksey 0:fb7af294d5d9 182 newValue = __LDREXW((volatile uint32_t*)valuePtr) - delta;
Simon Cooksey 0:fb7af294d5d9 183 } while (__STREXW(newValue, (volatile uint32_t*)valuePtr));
Simon Cooksey 0:fb7af294d5d9 184 return newValue;
Simon Cooksey 0:fb7af294d5d9 185 }
Simon Cooksey 0:fb7af294d5d9 186
Simon Cooksey 0:fb7af294d5d9 187 #else
Simon Cooksey 0:fb7af294d5d9 188
Simon Cooksey 0:fb7af294d5d9 189 bool core_util_atomic_cas_u8(uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue)
Simon Cooksey 0:fb7af294d5d9 190 {
Simon Cooksey 0:fb7af294d5d9 191 bool success;
Simon Cooksey 0:fb7af294d5d9 192 uint8_t currentValue;
Simon Cooksey 0:fb7af294d5d9 193 core_util_critical_section_enter();
Simon Cooksey 0:fb7af294d5d9 194 currentValue = *ptr;
Simon Cooksey 0:fb7af294d5d9 195 if (currentValue == *expectedCurrentValue) {
Simon Cooksey 0:fb7af294d5d9 196 *ptr = desiredValue;
Simon Cooksey 0:fb7af294d5d9 197 success = true;
Simon Cooksey 0:fb7af294d5d9 198 } else {
Simon Cooksey 0:fb7af294d5d9 199 *expectedCurrentValue = currentValue;
Simon Cooksey 0:fb7af294d5d9 200 success = false;
Simon Cooksey 0:fb7af294d5d9 201 }
Simon Cooksey 0:fb7af294d5d9 202 core_util_critical_section_exit();
Simon Cooksey 0:fb7af294d5d9 203 return success;
Simon Cooksey 0:fb7af294d5d9 204 }
Simon Cooksey 0:fb7af294d5d9 205
Simon Cooksey 0:fb7af294d5d9 206 bool core_util_atomic_cas_u16(uint16_t *ptr, uint16_t *expectedCurrentValue, uint16_t desiredValue)
Simon Cooksey 0:fb7af294d5d9 207 {
Simon Cooksey 0:fb7af294d5d9 208 bool success;
Simon Cooksey 0:fb7af294d5d9 209 uint16_t currentValue;
Simon Cooksey 0:fb7af294d5d9 210 core_util_critical_section_enter();
Simon Cooksey 0:fb7af294d5d9 211 currentValue = *ptr;
Simon Cooksey 0:fb7af294d5d9 212 if (currentValue == *expectedCurrentValue) {
Simon Cooksey 0:fb7af294d5d9 213 *ptr = desiredValue;
Simon Cooksey 0:fb7af294d5d9 214 success = true;
Simon Cooksey 0:fb7af294d5d9 215 } else {
Simon Cooksey 0:fb7af294d5d9 216 *expectedCurrentValue = currentValue;
Simon Cooksey 0:fb7af294d5d9 217 success = false;
Simon Cooksey 0:fb7af294d5d9 218 }
Simon Cooksey 0:fb7af294d5d9 219 core_util_critical_section_exit();
Simon Cooksey 0:fb7af294d5d9 220 return success;
Simon Cooksey 0:fb7af294d5d9 221 }
Simon Cooksey 0:fb7af294d5d9 222
Simon Cooksey 0:fb7af294d5d9 223
Simon Cooksey 0:fb7af294d5d9 224 bool core_util_atomic_cas_u32(uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue)
Simon Cooksey 0:fb7af294d5d9 225 {
Simon Cooksey 0:fb7af294d5d9 226 bool success;
Simon Cooksey 0:fb7af294d5d9 227 uint32_t currentValue;
Simon Cooksey 0:fb7af294d5d9 228 core_util_critical_section_enter();
Simon Cooksey 0:fb7af294d5d9 229 currentValue = *ptr;
Simon Cooksey 0:fb7af294d5d9 230 if (currentValue == *expectedCurrentValue) {
Simon Cooksey 0:fb7af294d5d9 231 *ptr = desiredValue;
Simon Cooksey 0:fb7af294d5d9 232 success = true;
Simon Cooksey 0:fb7af294d5d9 233 } else {
Simon Cooksey 0:fb7af294d5d9 234 *expectedCurrentValue = currentValue;
Simon Cooksey 0:fb7af294d5d9 235 success = false;
Simon Cooksey 0:fb7af294d5d9 236 }
Simon Cooksey 0:fb7af294d5d9 237 core_util_critical_section_exit();
Simon Cooksey 0:fb7af294d5d9 238 return success;
Simon Cooksey 0:fb7af294d5d9 239 }
Simon Cooksey 0:fb7af294d5d9 240
Simon Cooksey 0:fb7af294d5d9 241
Simon Cooksey 0:fb7af294d5d9 242 uint8_t core_util_atomic_incr_u8(uint8_t *valuePtr, uint8_t delta)
Simon Cooksey 0:fb7af294d5d9 243 {
Simon Cooksey 0:fb7af294d5d9 244 uint8_t newValue;
Simon Cooksey 0:fb7af294d5d9 245 core_util_critical_section_enter();
Simon Cooksey 0:fb7af294d5d9 246 newValue = *valuePtr + delta;
Simon Cooksey 0:fb7af294d5d9 247 *valuePtr = newValue;
Simon Cooksey 0:fb7af294d5d9 248 core_util_critical_section_exit();
Simon Cooksey 0:fb7af294d5d9 249 return newValue;
Simon Cooksey 0:fb7af294d5d9 250 }
Simon Cooksey 0:fb7af294d5d9 251
Simon Cooksey 0:fb7af294d5d9 252 uint16_t core_util_atomic_incr_u16(uint16_t *valuePtr, uint16_t delta)
Simon Cooksey 0:fb7af294d5d9 253 {
Simon Cooksey 0:fb7af294d5d9 254 uint16_t newValue;
Simon Cooksey 0:fb7af294d5d9 255 core_util_critical_section_enter();
Simon Cooksey 0:fb7af294d5d9 256 newValue = *valuePtr + delta;
Simon Cooksey 0:fb7af294d5d9 257 *valuePtr = newValue;
Simon Cooksey 0:fb7af294d5d9 258 core_util_critical_section_exit();
Simon Cooksey 0:fb7af294d5d9 259 return newValue;
Simon Cooksey 0:fb7af294d5d9 260 }
Simon Cooksey 0:fb7af294d5d9 261
Simon Cooksey 0:fb7af294d5d9 262 uint32_t core_util_atomic_incr_u32(uint32_t *valuePtr, uint32_t delta)
Simon Cooksey 0:fb7af294d5d9 263 {
Simon Cooksey 0:fb7af294d5d9 264 uint32_t newValue;
Simon Cooksey 0:fb7af294d5d9 265 core_util_critical_section_enter();
Simon Cooksey 0:fb7af294d5d9 266 newValue = *valuePtr + delta;
Simon Cooksey 0:fb7af294d5d9 267 *valuePtr = newValue;
Simon Cooksey 0:fb7af294d5d9 268 core_util_critical_section_exit();
Simon Cooksey 0:fb7af294d5d9 269 return newValue;
Simon Cooksey 0:fb7af294d5d9 270 }
Simon Cooksey 0:fb7af294d5d9 271
Simon Cooksey 0:fb7af294d5d9 272
Simon Cooksey 0:fb7af294d5d9 273 uint8_t core_util_atomic_decr_u8(uint8_t *valuePtr, uint8_t delta)
Simon Cooksey 0:fb7af294d5d9 274 {
Simon Cooksey 0:fb7af294d5d9 275 uint8_t newValue;
Simon Cooksey 0:fb7af294d5d9 276 core_util_critical_section_enter();
Simon Cooksey 0:fb7af294d5d9 277 newValue = *valuePtr - delta;
Simon Cooksey 0:fb7af294d5d9 278 *valuePtr = newValue;
Simon Cooksey 0:fb7af294d5d9 279 core_util_critical_section_exit();
Simon Cooksey 0:fb7af294d5d9 280 return newValue;
Simon Cooksey 0:fb7af294d5d9 281 }
Simon Cooksey 0:fb7af294d5d9 282
Simon Cooksey 0:fb7af294d5d9 283 uint16_t core_util_atomic_decr_u16(uint16_t *valuePtr, uint16_t delta)
Simon Cooksey 0:fb7af294d5d9 284 {
Simon Cooksey 0:fb7af294d5d9 285 uint16_t newValue;
Simon Cooksey 0:fb7af294d5d9 286 core_util_critical_section_enter();
Simon Cooksey 0:fb7af294d5d9 287 newValue = *valuePtr - delta;
Simon Cooksey 0:fb7af294d5d9 288 *valuePtr = newValue;
Simon Cooksey 0:fb7af294d5d9 289 core_util_critical_section_exit();
Simon Cooksey 0:fb7af294d5d9 290 return newValue;
Simon Cooksey 0:fb7af294d5d9 291 }
Simon Cooksey 0:fb7af294d5d9 292
Simon Cooksey 0:fb7af294d5d9 293 uint32_t core_util_atomic_decr_u32(uint32_t *valuePtr, uint32_t delta)
Simon Cooksey 0:fb7af294d5d9 294 {
Simon Cooksey 0:fb7af294d5d9 295 uint32_t newValue;
Simon Cooksey 0:fb7af294d5d9 296 core_util_critical_section_enter();
Simon Cooksey 0:fb7af294d5d9 297 newValue = *valuePtr - delta;
Simon Cooksey 0:fb7af294d5d9 298 *valuePtr = newValue;
Simon Cooksey 0:fb7af294d5d9 299 core_util_critical_section_exit();
Simon Cooksey 0:fb7af294d5d9 300 return newValue;
Simon Cooksey 0:fb7af294d5d9 301 }
Simon Cooksey 0:fb7af294d5d9 302
Simon Cooksey 0:fb7af294d5d9 303 #endif
Simon Cooksey 0:fb7af294d5d9 304
Simon Cooksey 0:fb7af294d5d9 305
Simon Cooksey 0:fb7af294d5d9 306 bool core_util_atomic_cas_ptr(void **ptr, void **expectedCurrentValue, void *desiredValue) {
Simon Cooksey 0:fb7af294d5d9 307 return core_util_atomic_cas_u32(
Simon Cooksey 0:fb7af294d5d9 308 (uint32_t *)ptr,
Simon Cooksey 0:fb7af294d5d9 309 (uint32_t *)expectedCurrentValue,
Simon Cooksey 0:fb7af294d5d9 310 (uint32_t)desiredValue);
Simon Cooksey 0:fb7af294d5d9 311 }
Simon Cooksey 0:fb7af294d5d9 312
Simon Cooksey 0:fb7af294d5d9 313 void *core_util_atomic_incr_ptr(void **valuePtr, ptrdiff_t delta) {
Simon Cooksey 0:fb7af294d5d9 314 return (void *)core_util_atomic_incr_u32((uint32_t *)valuePtr, (uint32_t)delta);
Simon Cooksey 0:fb7af294d5d9 315 }
Simon Cooksey 0:fb7af294d5d9 316
Simon Cooksey 0:fb7af294d5d9 317 void *core_util_atomic_decr_ptr(void **valuePtr, ptrdiff_t delta) {
Simon Cooksey 0:fb7af294d5d9 318 return (void *)core_util_atomic_decr_u32((uint32_t *)valuePtr, (uint32_t)delta);
Simon Cooksey 0:fb7af294d5d9 319 }
Simon Cooksey 0:fb7af294d5d9 320