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