The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 23 11:44:04 2017 +0000
Revision:
158:1c57384330a6
Parent:
156:ff21514d8981
Child:
160:5571c4ff569f
mbed library. Release version 156

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 156:ff21514d8981 1
AnnaBridge 156:ff21514d8981 2 /*
AnnaBridge 156:ff21514d8981 3 * Copyright (c) 2015-2016, ARM Limited, All Rights Reserved
AnnaBridge 156:ff21514d8981 4 * SPDX-License-Identifier: Apache-2.0
AnnaBridge 156:ff21514d8981 5 *
AnnaBridge 156:ff21514d8981 6 * Licensed under the Apache License, Version 2.0 (the "License"); you may
AnnaBridge 156:ff21514d8981 7 * not use this file except in compliance with the License.
AnnaBridge 156:ff21514d8981 8 * You may obtain a copy of the License at
AnnaBridge 156:ff21514d8981 9 *
AnnaBridge 156:ff21514d8981 10 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 156:ff21514d8981 11 *
AnnaBridge 156:ff21514d8981 12 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 156:ff21514d8981 13 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
AnnaBridge 156:ff21514d8981 14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 156:ff21514d8981 15 * See the License for the specific language governing permissions and
AnnaBridge 156:ff21514d8981 16 * limitations under the License.
AnnaBridge 156:ff21514d8981 17 */
AnnaBridge 156:ff21514d8981 18
AnnaBridge 156:ff21514d8981 19 #ifndef __MBED_UTIL_CRITICAL_H__
AnnaBridge 156:ff21514d8981 20 #define __MBED_UTIL_CRITICAL_H__
AnnaBridge 156:ff21514d8981 21
AnnaBridge 156:ff21514d8981 22 #include <stdbool.h>
AnnaBridge 156:ff21514d8981 23 #include <stdint.h>
AnnaBridge 156:ff21514d8981 24 #include <stddef.h>
AnnaBridge 156:ff21514d8981 25
AnnaBridge 156:ff21514d8981 26 #ifdef __cplusplus
AnnaBridge 156:ff21514d8981 27 extern "C" {
AnnaBridge 156:ff21514d8981 28 #endif
AnnaBridge 156:ff21514d8981 29
AnnaBridge 158:1c57384330a6 30 /** \addtogroup platform */
AnnaBridge 158:1c57384330a6 31 /** @{*/
AnnaBridge 158:1c57384330a6 32 /**
AnnaBridge 158:1c57384330a6 33 * \defgroup platform_critical critical section function
AnnaBridge 158:1c57384330a6 34 * @{
AnnaBridge 158:1c57384330a6 35 */
AnnaBridge 156:ff21514d8981 36
AnnaBridge 156:ff21514d8981 37 /** Determine the current interrupts enabled state
AnnaBridge 156:ff21514d8981 38 *
AnnaBridge 156:ff21514d8981 39 * This function can be called to determine whether or not interrupts are currently enabled.
AnnaBridge 156:ff21514d8981 40 * @note
AnnaBridge 156:ff21514d8981 41 * NOTE:
AnnaBridge 156:ff21514d8981 42 * This function works for both cortex-A and cortex-M, although the underlyng implementation
AnnaBridge 156:ff21514d8981 43 * differs.
AnnaBridge 156:ff21514d8981 44 * @return true if interrupts are enabled, false otherwise
AnnaBridge 156:ff21514d8981 45 */
AnnaBridge 156:ff21514d8981 46 bool core_util_are_interrupts_enabled(void);
AnnaBridge 156:ff21514d8981 47
AnnaBridge 156:ff21514d8981 48 /** Determine if this code is executing from an interrupt
AnnaBridge 156:ff21514d8981 49 *
AnnaBridge 156:ff21514d8981 50 * This function can be called to determine if the code is running on interrupt context.
AnnaBridge 156:ff21514d8981 51 * @note
AnnaBridge 156:ff21514d8981 52 * NOTE:
AnnaBridge 156:ff21514d8981 53 * This function works for both cortex-A and cortex-M, although the underlyng implementation
AnnaBridge 156:ff21514d8981 54 * differs.
AnnaBridge 156:ff21514d8981 55 * @return true if in an isr, false otherwise
AnnaBridge 156:ff21514d8981 56 */
AnnaBridge 156:ff21514d8981 57 bool core_util_is_isr_active(void);
AnnaBridge 156:ff21514d8981 58
AnnaBridge 156:ff21514d8981 59 /** Mark the start of a critical section
AnnaBridge 156:ff21514d8981 60 *
AnnaBridge 156:ff21514d8981 61 * This function should be called to mark the start of a critical section of code.
AnnaBridge 156:ff21514d8981 62 * @note
AnnaBridge 156:ff21514d8981 63 * NOTES:
AnnaBridge 156:ff21514d8981 64 * 1) The use of this style of critical section is targetted at C based implementations.
AnnaBridge 156:ff21514d8981 65 * 2) These critical sections can be nested.
AnnaBridge 156:ff21514d8981 66 * 3) The interrupt enable state on entry to the first critical section (of a nested set, or single
AnnaBridge 156:ff21514d8981 67 * section) will be preserved on exit from the section.
AnnaBridge 156:ff21514d8981 68 * 4) This implementation will currently only work on code running in privileged mode.
AnnaBridge 156:ff21514d8981 69 */
AnnaBridge 156:ff21514d8981 70 void core_util_critical_section_enter(void);
AnnaBridge 156:ff21514d8981 71
AnnaBridge 156:ff21514d8981 72 /** Mark the end of a critical section
AnnaBridge 156:ff21514d8981 73 *
AnnaBridge 156:ff21514d8981 74 * This function should be called to mark the end of a critical section of code.
AnnaBridge 156:ff21514d8981 75 * @note
AnnaBridge 156:ff21514d8981 76 * NOTES:
AnnaBridge 156:ff21514d8981 77 * 1) The use of this style of critical section is targetted at C based implementations.
AnnaBridge 156:ff21514d8981 78 * 2) These critical sections can be nested.
AnnaBridge 156:ff21514d8981 79 * 3) The interrupt enable state on entry to the first critical section (of a nested set, or single
AnnaBridge 156:ff21514d8981 80 * section) will be preserved on exit from the section.
AnnaBridge 156:ff21514d8981 81 * 4) This implementation will currently only work on code running in privileged mode.
AnnaBridge 156:ff21514d8981 82 */
AnnaBridge 156:ff21514d8981 83 void core_util_critical_section_exit(void);
AnnaBridge 156:ff21514d8981 84
AnnaBridge 156:ff21514d8981 85 /**
AnnaBridge 156:ff21514d8981 86 * Atomic compare and set. It compares the contents of a memory location to a
AnnaBridge 156:ff21514d8981 87 * given value and, only if they are the same, modifies the contents of that
AnnaBridge 156:ff21514d8981 88 * memory location to a given new value. This is done as a single atomic
AnnaBridge 156:ff21514d8981 89 * operation. The atomicity guarantees that the new value is calculated based on
AnnaBridge 156:ff21514d8981 90 * up-to-date information; if the value had been updated by another thread in
AnnaBridge 156:ff21514d8981 91 * the meantime, the write would fail due to a mismatched expectedCurrentValue.
AnnaBridge 156:ff21514d8981 92 *
AnnaBridge 156:ff21514d8981 93 * Refer to https://en.wikipedia.org/wiki/Compare-and-set [which may redirect
AnnaBridge 156:ff21514d8981 94 * you to the article on compare-and swap].
AnnaBridge 156:ff21514d8981 95 *
AnnaBridge 156:ff21514d8981 96 * @param ptr The target memory location.
AnnaBridge 156:ff21514d8981 97 * @param[in,out] expectedCurrentValue A pointer to some location holding the
AnnaBridge 156:ff21514d8981 98 * expected current value of the data being set atomically.
AnnaBridge 156:ff21514d8981 99 * The computed 'desiredValue' should be a function of this current value.
AnnaBridge 156:ff21514d8981 100 * @note: This is an in-out parameter. In the
AnnaBridge 156:ff21514d8981 101 * failure case of atomic_cas (where the
AnnaBridge 156:ff21514d8981 102 * destination isn't set), the pointee of expectedCurrentValue is
AnnaBridge 156:ff21514d8981 103 * updated with the current value.
AnnaBridge 156:ff21514d8981 104 * @param[in] desiredValue The new value computed based on '*expectedCurrentValue'.
AnnaBridge 156:ff21514d8981 105 *
AnnaBridge 156:ff21514d8981 106 * @return true if the memory location was atomically
AnnaBridge 156:ff21514d8981 107 * updated with the desired value (after verifying
AnnaBridge 156:ff21514d8981 108 * that it contained the expectedCurrentValue),
AnnaBridge 156:ff21514d8981 109 * false otherwise. In the failure case,
AnnaBridge 156:ff21514d8981 110 * exepctedCurrentValue is updated with the new
AnnaBridge 156:ff21514d8981 111 * value of the target memory location.
AnnaBridge 156:ff21514d8981 112 *
AnnaBridge 156:ff21514d8981 113 * pseudocode:
AnnaBridge 156:ff21514d8981 114 * function cas(p : pointer to int, old : pointer to int, new : int) returns bool {
AnnaBridge 156:ff21514d8981 115 * if *p != *old {
AnnaBridge 156:ff21514d8981 116 * *old = *p
AnnaBridge 156:ff21514d8981 117 * return false
AnnaBridge 156:ff21514d8981 118 * }
AnnaBridge 156:ff21514d8981 119 * *p = new
AnnaBridge 156:ff21514d8981 120 * return true
AnnaBridge 156:ff21514d8981 121 * }
AnnaBridge 156:ff21514d8981 122 *
AnnaBridge 156:ff21514d8981 123 * @note: In the failure case (where the destination isn't set), the value
AnnaBridge 156:ff21514d8981 124 * pointed to by expectedCurrentValue is still updated with the current value.
AnnaBridge 156:ff21514d8981 125 * This property helps writing concise code for the following incr:
AnnaBridge 156:ff21514d8981 126 *
AnnaBridge 156:ff21514d8981 127 * function incr(p : pointer to int, a : int) returns int {
AnnaBridge 156:ff21514d8981 128 * done = false
AnnaBridge 156:ff21514d8981 129 * value = *p // This fetch operation need not be atomic.
AnnaBridge 156:ff21514d8981 130 * while not done {
AnnaBridge 156:ff21514d8981 131 * done = atomic_cas(p, &value, value + a) // *value gets updated automatically until success
AnnaBridge 156:ff21514d8981 132 * }
AnnaBridge 156:ff21514d8981 133 * return value + a
AnnaBridge 156:ff21514d8981 134 * }
AnnaBridge 156:ff21514d8981 135 */
AnnaBridge 156:ff21514d8981 136 bool core_util_atomic_cas_u8(uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue);
AnnaBridge 156:ff21514d8981 137
AnnaBridge 156:ff21514d8981 138 /**
AnnaBridge 156:ff21514d8981 139 * Atomic compare and set. It compares the contents of a memory location to a
AnnaBridge 156:ff21514d8981 140 * given value and, only if they are the same, modifies the contents of that
AnnaBridge 156:ff21514d8981 141 * memory location to a given new value. This is done as a single atomic
AnnaBridge 156:ff21514d8981 142 * operation. The atomicity guarantees that the new value is calculated based on
AnnaBridge 156:ff21514d8981 143 * up-to-date information; if the value had been updated by another thread in
AnnaBridge 156:ff21514d8981 144 * the meantime, the write would fail due to a mismatched expectedCurrentValue.
AnnaBridge 156:ff21514d8981 145 *
AnnaBridge 156:ff21514d8981 146 * Refer to https://en.wikipedia.org/wiki/Compare-and-set [which may redirect
AnnaBridge 156:ff21514d8981 147 * you to the article on compare-and swap].
AnnaBridge 156:ff21514d8981 148 *
AnnaBridge 156:ff21514d8981 149 * @param ptr The target memory location.
AnnaBridge 156:ff21514d8981 150 * @param[in,out] expectedCurrentValue A pointer to some location holding the
AnnaBridge 156:ff21514d8981 151 * expected current value of the data being set atomically.
AnnaBridge 156:ff21514d8981 152 * The computed 'desiredValue' should be a function of this current value.
AnnaBridge 156:ff21514d8981 153 * @note: This is an in-out parameter. In the
AnnaBridge 156:ff21514d8981 154 * failure case of atomic_cas (where the
AnnaBridge 156:ff21514d8981 155 * destination isn't set), the pointee of expectedCurrentValue is
AnnaBridge 156:ff21514d8981 156 * updated with the current value.
AnnaBridge 156:ff21514d8981 157 * @param[in] desiredValue The new value computed based on '*expectedCurrentValue'.
AnnaBridge 156:ff21514d8981 158 *
AnnaBridge 156:ff21514d8981 159 * @return true if the memory location was atomically
AnnaBridge 156:ff21514d8981 160 * updated with the desired value (after verifying
AnnaBridge 156:ff21514d8981 161 * that it contained the expectedCurrentValue),
AnnaBridge 156:ff21514d8981 162 * false otherwise. In the failure case,
AnnaBridge 156:ff21514d8981 163 * exepctedCurrentValue is updated with the new
AnnaBridge 156:ff21514d8981 164 * value of the target memory location.
AnnaBridge 156:ff21514d8981 165 *
AnnaBridge 156:ff21514d8981 166 * pseudocode:
AnnaBridge 156:ff21514d8981 167 * function cas(p : pointer to int, old : pointer to int, new : int) returns bool {
AnnaBridge 156:ff21514d8981 168 * if *p != *old {
AnnaBridge 156:ff21514d8981 169 * *old = *p
AnnaBridge 156:ff21514d8981 170 * return false
AnnaBridge 156:ff21514d8981 171 * }
AnnaBridge 156:ff21514d8981 172 * *p = new
AnnaBridge 156:ff21514d8981 173 * return true
AnnaBridge 156:ff21514d8981 174 * }
AnnaBridge 156:ff21514d8981 175 *
AnnaBridge 156:ff21514d8981 176 * @note: In the failure case (where the destination isn't set), the value
AnnaBridge 156:ff21514d8981 177 * pointed to by expectedCurrentValue is still updated with the current value.
AnnaBridge 156:ff21514d8981 178 * This property helps writing concise code for the following incr:
AnnaBridge 156:ff21514d8981 179 *
AnnaBridge 156:ff21514d8981 180 * function incr(p : pointer to int, a : int) returns int {
AnnaBridge 156:ff21514d8981 181 * done = false
AnnaBridge 156:ff21514d8981 182 * value = *p // This fetch operation need not be atomic.
AnnaBridge 156:ff21514d8981 183 * while not done {
AnnaBridge 156:ff21514d8981 184 * done = atomic_cas(p, &value, value + a) // *value gets updated automatically until success
AnnaBridge 156:ff21514d8981 185 * }
AnnaBridge 156:ff21514d8981 186 * return value + a
AnnaBridge 156:ff21514d8981 187 * }
AnnaBridge 156:ff21514d8981 188 */
AnnaBridge 156:ff21514d8981 189 bool core_util_atomic_cas_u16(uint16_t *ptr, uint16_t *expectedCurrentValue, uint16_t desiredValue);
AnnaBridge 156:ff21514d8981 190
AnnaBridge 156:ff21514d8981 191 /**
AnnaBridge 156:ff21514d8981 192 * Atomic compare and set. It compares the contents of a memory location to a
AnnaBridge 156:ff21514d8981 193 * given value and, only if they are the same, modifies the contents of that
AnnaBridge 156:ff21514d8981 194 * memory location to a given new value. This is done as a single atomic
AnnaBridge 156:ff21514d8981 195 * operation. The atomicity guarantees that the new value is calculated based on
AnnaBridge 156:ff21514d8981 196 * up-to-date information; if the value had been updated by another thread in
AnnaBridge 156:ff21514d8981 197 * the meantime, the write would fail due to a mismatched expectedCurrentValue.
AnnaBridge 156:ff21514d8981 198 *
AnnaBridge 156:ff21514d8981 199 * Refer to https://en.wikipedia.org/wiki/Compare-and-set [which may redirect
AnnaBridge 156:ff21514d8981 200 * you to the article on compare-and swap].
AnnaBridge 156:ff21514d8981 201 *
AnnaBridge 156:ff21514d8981 202 * @param ptr The target memory location.
AnnaBridge 156:ff21514d8981 203 * @param[in,out] expectedCurrentValue A pointer to some location holding the
AnnaBridge 156:ff21514d8981 204 * expected current value of the data being set atomically.
AnnaBridge 156:ff21514d8981 205 * The computed 'desiredValue' should be a function of this current value.
AnnaBridge 156:ff21514d8981 206 * @note: This is an in-out parameter. In the
AnnaBridge 156:ff21514d8981 207 * failure case of atomic_cas (where the
AnnaBridge 156:ff21514d8981 208 * destination isn't set), the pointee of expectedCurrentValue is
AnnaBridge 156:ff21514d8981 209 * updated with the current value.
AnnaBridge 156:ff21514d8981 210 * @param[in] desiredValue The new value computed based on '*expectedCurrentValue'.
AnnaBridge 156:ff21514d8981 211 *
AnnaBridge 156:ff21514d8981 212 * @return true if the memory location was atomically
AnnaBridge 156:ff21514d8981 213 * updated with the desired value (after verifying
AnnaBridge 156:ff21514d8981 214 * that it contained the expectedCurrentValue),
AnnaBridge 156:ff21514d8981 215 * false otherwise. In the failure case,
AnnaBridge 156:ff21514d8981 216 * exepctedCurrentValue is updated with the new
AnnaBridge 156:ff21514d8981 217 * value of the target memory location.
AnnaBridge 156:ff21514d8981 218 *
AnnaBridge 156:ff21514d8981 219 * pseudocode:
AnnaBridge 156:ff21514d8981 220 * function cas(p : pointer to int, old : pointer to int, new : int) returns bool {
AnnaBridge 156:ff21514d8981 221 * if *p != *old {
AnnaBridge 156:ff21514d8981 222 * *old = *p
AnnaBridge 156:ff21514d8981 223 * return false
AnnaBridge 156:ff21514d8981 224 * }
AnnaBridge 156:ff21514d8981 225 * *p = new
AnnaBridge 156:ff21514d8981 226 * return true
AnnaBridge 156:ff21514d8981 227 * }
AnnaBridge 156:ff21514d8981 228 *
AnnaBridge 156:ff21514d8981 229 * @note: In the failure case (where the destination isn't set), the value
AnnaBridge 156:ff21514d8981 230 * pointed to by expectedCurrentValue is still updated with the current value.
AnnaBridge 156:ff21514d8981 231 * This property helps writing concise code for the following incr:
AnnaBridge 156:ff21514d8981 232 *
AnnaBridge 156:ff21514d8981 233 * function incr(p : pointer to int, a : int) returns int {
AnnaBridge 156:ff21514d8981 234 * done = false
AnnaBridge 156:ff21514d8981 235 * value = *p // This fetch operation need not be atomic.
AnnaBridge 156:ff21514d8981 236 * while not done {
AnnaBridge 156:ff21514d8981 237 * done = atomic_cas(p, &value, value + a) // *value gets updated automatically until success
AnnaBridge 156:ff21514d8981 238 * }
AnnaBridge 156:ff21514d8981 239 * return value + a
AnnaBridge 156:ff21514d8981 240 * }
AnnaBridge 156:ff21514d8981 241 */
AnnaBridge 156:ff21514d8981 242 bool core_util_atomic_cas_u32(uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue);
AnnaBridge 156:ff21514d8981 243
AnnaBridge 156:ff21514d8981 244 /**
AnnaBridge 156:ff21514d8981 245 * Atomic compare and set. It compares the contents of a memory location to a
AnnaBridge 156:ff21514d8981 246 * given value and, only if they are the same, modifies the contents of that
AnnaBridge 156:ff21514d8981 247 * memory location to a given new value. This is done as a single atomic
AnnaBridge 156:ff21514d8981 248 * operation. The atomicity guarantees that the new value is calculated based on
AnnaBridge 156:ff21514d8981 249 * up-to-date information; if the value had been updated by another thread in
AnnaBridge 156:ff21514d8981 250 * the meantime, the write would fail due to a mismatched expectedCurrentValue.
AnnaBridge 156:ff21514d8981 251 *
AnnaBridge 156:ff21514d8981 252 * Refer to https://en.wikipedia.org/wiki/Compare-and-set [which may redirect
AnnaBridge 156:ff21514d8981 253 * you to the article on compare-and swap].
AnnaBridge 156:ff21514d8981 254 *
AnnaBridge 156:ff21514d8981 255 * @param ptr The target memory location.
AnnaBridge 156:ff21514d8981 256 * @param[in,out] expectedCurrentValue A pointer to some location holding the
AnnaBridge 156:ff21514d8981 257 * expected current value of the data being set atomically.
AnnaBridge 156:ff21514d8981 258 * The computed 'desiredValue' should be a function of this current value.
AnnaBridge 156:ff21514d8981 259 * @note: This is an in-out parameter. In the
AnnaBridge 156:ff21514d8981 260 * failure case of atomic_cas (where the
AnnaBridge 156:ff21514d8981 261 * destination isn't set), the pointee of expectedCurrentValue is
AnnaBridge 156:ff21514d8981 262 * updated with the current value.
AnnaBridge 156:ff21514d8981 263 * @param[in] desiredValue The new value computed based on '*expectedCurrentValue'.
AnnaBridge 156:ff21514d8981 264 *
AnnaBridge 156:ff21514d8981 265 * @return true if the memory location was atomically
AnnaBridge 156:ff21514d8981 266 * updated with the desired value (after verifying
AnnaBridge 156:ff21514d8981 267 * that it contained the expectedCurrentValue),
AnnaBridge 156:ff21514d8981 268 * false otherwise. In the failure case,
AnnaBridge 156:ff21514d8981 269 * exepctedCurrentValue is updated with the new
AnnaBridge 156:ff21514d8981 270 * value of the target memory location.
AnnaBridge 156:ff21514d8981 271 *
AnnaBridge 156:ff21514d8981 272 * pseudocode:
AnnaBridge 156:ff21514d8981 273 * function cas(p : pointer to int, old : pointer to int, new : int) returns bool {
AnnaBridge 156:ff21514d8981 274 * if *p != *old {
AnnaBridge 156:ff21514d8981 275 * *old = *p
AnnaBridge 156:ff21514d8981 276 * return false
AnnaBridge 156:ff21514d8981 277 * }
AnnaBridge 156:ff21514d8981 278 * *p = new
AnnaBridge 156:ff21514d8981 279 * return true
AnnaBridge 156:ff21514d8981 280 * }
AnnaBridge 156:ff21514d8981 281 *
AnnaBridge 156:ff21514d8981 282 * @note: In the failure case (where the destination isn't set), the value
AnnaBridge 156:ff21514d8981 283 * pointed to by expectedCurrentValue is still updated with the current value.
AnnaBridge 156:ff21514d8981 284 * This property helps writing concise code for the following incr:
AnnaBridge 156:ff21514d8981 285 *
AnnaBridge 156:ff21514d8981 286 * function incr(p : pointer to int, a : int) returns int {
AnnaBridge 156:ff21514d8981 287 * done = false
AnnaBridge 156:ff21514d8981 288 * value = *p // This fetch operation need not be atomic.
AnnaBridge 156:ff21514d8981 289 * while not done {
AnnaBridge 156:ff21514d8981 290 * done = atomic_cas(p, &value, value + a) // *value gets updated automatically until success
AnnaBridge 156:ff21514d8981 291 * }
AnnaBridge 156:ff21514d8981 292 * return value + a
AnnaBridge 156:ff21514d8981 293 * }
AnnaBridge 156:ff21514d8981 294 */
AnnaBridge 156:ff21514d8981 295 bool core_util_atomic_cas_ptr(void **ptr, void **expectedCurrentValue, void *desiredValue);
AnnaBridge 156:ff21514d8981 296
AnnaBridge 156:ff21514d8981 297 /**
AnnaBridge 156:ff21514d8981 298 * Atomic increment.
AnnaBridge 156:ff21514d8981 299 * @param valuePtr Target memory location being incremented.
AnnaBridge 156:ff21514d8981 300 * @param delta The amount being incremented.
AnnaBridge 156:ff21514d8981 301 * @return The new incremented value.
AnnaBridge 156:ff21514d8981 302 */
AnnaBridge 156:ff21514d8981 303 uint8_t core_util_atomic_incr_u8(uint8_t *valuePtr, uint8_t delta);
AnnaBridge 156:ff21514d8981 304
AnnaBridge 156:ff21514d8981 305 /**
AnnaBridge 156:ff21514d8981 306 * Atomic increment.
AnnaBridge 156:ff21514d8981 307 * @param valuePtr Target memory location being incremented.
AnnaBridge 156:ff21514d8981 308 * @param delta The amount being incremented.
AnnaBridge 156:ff21514d8981 309 * @return The new incremented value.
AnnaBridge 156:ff21514d8981 310 */
AnnaBridge 156:ff21514d8981 311 uint16_t core_util_atomic_incr_u16(uint16_t *valuePtr, uint16_t delta);
AnnaBridge 156:ff21514d8981 312
AnnaBridge 156:ff21514d8981 313 /**
AnnaBridge 156:ff21514d8981 314 * Atomic increment.
AnnaBridge 156:ff21514d8981 315 * @param valuePtr Target memory location being incremented.
AnnaBridge 156:ff21514d8981 316 * @param delta The amount being incremented.
AnnaBridge 156:ff21514d8981 317 * @return The new incremented value.
AnnaBridge 156:ff21514d8981 318 */
AnnaBridge 156:ff21514d8981 319 uint32_t core_util_atomic_incr_u32(uint32_t *valuePtr, uint32_t delta);
AnnaBridge 156:ff21514d8981 320
AnnaBridge 156:ff21514d8981 321 /**
AnnaBridge 156:ff21514d8981 322 * Atomic increment.
AnnaBridge 156:ff21514d8981 323 * @param valuePtr Target memory location being incremented.
AnnaBridge 156:ff21514d8981 324 * @param delta The amount being incremented in bytes.
AnnaBridge 156:ff21514d8981 325 * @return The new incremented value.
AnnaBridge 156:ff21514d8981 326 *
AnnaBridge 156:ff21514d8981 327 * @note The type of the pointer argument is not taken into account
AnnaBridge 156:ff21514d8981 328 * and the pointer is incremented by bytes.
AnnaBridge 156:ff21514d8981 329 */
AnnaBridge 156:ff21514d8981 330 void *core_util_atomic_incr_ptr(void **valuePtr, ptrdiff_t delta);
AnnaBridge 156:ff21514d8981 331
AnnaBridge 156:ff21514d8981 332 /**
AnnaBridge 156:ff21514d8981 333 * Atomic decrement.
AnnaBridge 156:ff21514d8981 334 * @param valuePtr Target memory location being decremented.
AnnaBridge 156:ff21514d8981 335 * @param delta The amount being decremented.
AnnaBridge 156:ff21514d8981 336 * @return The new decremented value.
AnnaBridge 156:ff21514d8981 337 */
AnnaBridge 156:ff21514d8981 338 uint8_t core_util_atomic_decr_u8(uint8_t *valuePtr, uint8_t delta);
AnnaBridge 156:ff21514d8981 339
AnnaBridge 156:ff21514d8981 340 /**
AnnaBridge 156:ff21514d8981 341 * Atomic decrement.
AnnaBridge 156:ff21514d8981 342 * @param valuePtr Target memory location being decremented.
AnnaBridge 156:ff21514d8981 343 * @param delta The amount being decremented.
AnnaBridge 156:ff21514d8981 344 * @return The new decremented value.
AnnaBridge 156:ff21514d8981 345 */
AnnaBridge 156:ff21514d8981 346 uint16_t core_util_atomic_decr_u16(uint16_t *valuePtr, uint16_t delta);
AnnaBridge 156:ff21514d8981 347
AnnaBridge 156:ff21514d8981 348 /**
AnnaBridge 156:ff21514d8981 349 * Atomic decrement.
AnnaBridge 156:ff21514d8981 350 * @param valuePtr Target memory location being decremented.
AnnaBridge 156:ff21514d8981 351 * @param delta The amount being decremented.
AnnaBridge 156:ff21514d8981 352 * @return The new decremented value.
AnnaBridge 156:ff21514d8981 353 */
AnnaBridge 156:ff21514d8981 354 uint32_t core_util_atomic_decr_u32(uint32_t *valuePtr, uint32_t delta);
AnnaBridge 156:ff21514d8981 355
AnnaBridge 156:ff21514d8981 356 /**
AnnaBridge 156:ff21514d8981 357 * Atomic decrement.
AnnaBridge 156:ff21514d8981 358 * @param valuePtr Target memory location being decremented.
AnnaBridge 156:ff21514d8981 359 * @param delta The amount being decremented in bytes.
AnnaBridge 156:ff21514d8981 360 * @return The new decremented value.
AnnaBridge 156:ff21514d8981 361 *
AnnaBridge 156:ff21514d8981 362 * @note The type of the pointer argument is not taken into account
AnnaBridge 156:ff21514d8981 363 * and the pointer is decremented by bytes
AnnaBridge 156:ff21514d8981 364 */
AnnaBridge 156:ff21514d8981 365 void *core_util_atomic_decr_ptr(void **valuePtr, ptrdiff_t delta);
AnnaBridge 156:ff21514d8981 366
AnnaBridge 156:ff21514d8981 367 #ifdef __cplusplus
AnnaBridge 156:ff21514d8981 368 } // extern "C"
AnnaBridge 156:ff21514d8981 369 #endif
AnnaBridge 158:1c57384330a6 370 /**@}*/
AnnaBridge 156:ff21514d8981 371
AnnaBridge 158:1c57384330a6 372 /**@}*/
AnnaBridge 156:ff21514d8981 373
AnnaBridge 156:ff21514d8981 374 #endif // __MBED_UTIL_CRITICAL_H__
AnnaBridge 156:ff21514d8981 375
AnnaBridge 158:1c57384330a6 376
AnnaBridge 158:1c57384330a6 377