The prosthetic control(MIT)

Committer:
ganlikun
Date:
Thu Jun 23 05:23:34 2022 +0000
Revision:
0:20e0c61e0684
01

Who changed what in which revision?

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