CDY version that shares functionality with Counter

Dependencies:   SDFileSystem_HelloWorld mbed FATFileSystem

Committer:
Charles David Young
Date:
Mon Nov 05 09:52:17 2018 -0700
Revision:
3:c547dba5d39b
Parent:
0:aa13e1c335cd
debug

Who changed what in which revision?

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