![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/platform/mbed_critical.c@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /* |
kadonotakashi | 0:8fdf9a60065b | 2 | * Copyright (c) 2015-2016, ARM Limited, All Rights Reserved |
kadonotakashi | 0:8fdf9a60065b | 3 | * SPDX-License-Identifier: Apache-2.0 |
kadonotakashi | 0:8fdf9a60065b | 4 | * |
kadonotakashi | 0:8fdf9a60065b | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
kadonotakashi | 0:8fdf9a60065b | 6 | * not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 7 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 8 | * |
kadonotakashi | 0:8fdf9a60065b | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 10 | * |
kadonotakashi | 0:8fdf9a60065b | 11 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
kadonotakashi | 0:8fdf9a60065b | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 14 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 15 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 16 | */ |
kadonotakashi | 0:8fdf9a60065b | 17 | |
kadonotakashi | 0:8fdf9a60065b | 18 | /* Declare __STDC_LIMIT_MACROS so stdint.h defines UINT32_MAX when using C++ */ |
kadonotakashi | 0:8fdf9a60065b | 19 | #define __STDC_LIMIT_MACROS |
kadonotakashi | 0:8fdf9a60065b | 20 | #include "hal/critical_section_api.h" |
kadonotakashi | 0:8fdf9a60065b | 21 | |
kadonotakashi | 0:8fdf9a60065b | 22 | #include "cmsis.h" |
kadonotakashi | 0:8fdf9a60065b | 23 | #include "platform/mbed_assert.h" |
kadonotakashi | 0:8fdf9a60065b | 24 | #include "platform/mbed_critical.h" |
kadonotakashi | 0:8fdf9a60065b | 25 | #include "platform/mbed_toolchain.h" |
kadonotakashi | 0:8fdf9a60065b | 26 | |
kadonotakashi | 0:8fdf9a60065b | 27 | // if __EXCLUSIVE_ACCESS rtx macro not defined, we need to get this via own-set architecture macros |
kadonotakashi | 0:8fdf9a60065b | 28 | #ifndef MBED_EXCLUSIVE_ACCESS |
kadonotakashi | 0:8fdf9a60065b | 29 | #ifndef __EXCLUSIVE_ACCESS |
kadonotakashi | 0:8fdf9a60065b | 30 | #if ((__ARM_ARCH_7M__ == 1U) || \ |
kadonotakashi | 0:8fdf9a60065b | 31 | (__ARM_ARCH_7EM__ == 1U) || \ |
kadonotakashi | 0:8fdf9a60065b | 32 | (__ARM_ARCH_8M_BASE__ == 1U) || \ |
kadonotakashi | 0:8fdf9a60065b | 33 | (__ARM_ARCH_8M_MAIN__ == 1U)) || \ |
kadonotakashi | 0:8fdf9a60065b | 34 | (__ARM_ARCH_7A__ == 1U) |
kadonotakashi | 0:8fdf9a60065b | 35 | #define MBED_EXCLUSIVE_ACCESS 1U |
kadonotakashi | 0:8fdf9a60065b | 36 | #elif (__ARM_ARCH_6M__ == 1U) |
kadonotakashi | 0:8fdf9a60065b | 37 | #define MBED_EXCLUSIVE_ACCESS 0U |
kadonotakashi | 0:8fdf9a60065b | 38 | #else |
kadonotakashi | 0:8fdf9a60065b | 39 | #error "Unknown architecture for exclusive access" |
kadonotakashi | 0:8fdf9a60065b | 40 | #endif |
kadonotakashi | 0:8fdf9a60065b | 41 | #else |
kadonotakashi | 0:8fdf9a60065b | 42 | #define MBED_EXCLUSIVE_ACCESS __EXCLUSIVE_ACCESS |
kadonotakashi | 0:8fdf9a60065b | 43 | #endif |
kadonotakashi | 0:8fdf9a60065b | 44 | #endif |
kadonotakashi | 0:8fdf9a60065b | 45 | |
kadonotakashi | 0:8fdf9a60065b | 46 | static volatile uint32_t critical_section_reentrancy_counter = 0; |
kadonotakashi | 0:8fdf9a60065b | 47 | |
kadonotakashi | 0:8fdf9a60065b | 48 | bool core_util_are_interrupts_enabled(void) |
kadonotakashi | 0:8fdf9a60065b | 49 | { |
kadonotakashi | 0:8fdf9a60065b | 50 | #if defined(__CORTEX_A9) |
kadonotakashi | 0:8fdf9a60065b | 51 | return ((__get_CPSR() & 0x80) == 0); |
kadonotakashi | 0:8fdf9a60065b | 52 | #else |
kadonotakashi | 0:8fdf9a60065b | 53 | return ((__get_PRIMASK() & 0x1) == 0); |
kadonotakashi | 0:8fdf9a60065b | 54 | #endif |
kadonotakashi | 0:8fdf9a60065b | 55 | } |
kadonotakashi | 0:8fdf9a60065b | 56 | |
kadonotakashi | 0:8fdf9a60065b | 57 | bool core_util_is_isr_active(void) |
kadonotakashi | 0:8fdf9a60065b | 58 | { |
kadonotakashi | 0:8fdf9a60065b | 59 | #if defined(__CORTEX_A9) |
kadonotakashi | 0:8fdf9a60065b | 60 | switch (__get_CPSR() & 0x1FU) { |
kadonotakashi | 0:8fdf9a60065b | 61 | case CPSR_M_USR: |
kadonotakashi | 0:8fdf9a60065b | 62 | case CPSR_M_SYS: |
kadonotakashi | 0:8fdf9a60065b | 63 | return false; |
kadonotakashi | 0:8fdf9a60065b | 64 | case CPSR_M_SVC: |
kadonotakashi | 0:8fdf9a60065b | 65 | default: |
kadonotakashi | 0:8fdf9a60065b | 66 | return true; |
kadonotakashi | 0:8fdf9a60065b | 67 | } |
kadonotakashi | 0:8fdf9a60065b | 68 | #else |
kadonotakashi | 0:8fdf9a60065b | 69 | return (__get_IPSR() != 0U); |
kadonotakashi | 0:8fdf9a60065b | 70 | #endif |
kadonotakashi | 0:8fdf9a60065b | 71 | } |
kadonotakashi | 0:8fdf9a60065b | 72 | |
kadonotakashi | 0:8fdf9a60065b | 73 | bool core_util_in_critical_section(void) |
kadonotakashi | 0:8fdf9a60065b | 74 | { |
kadonotakashi | 0:8fdf9a60065b | 75 | return hal_in_critical_section(); |
kadonotakashi | 0:8fdf9a60065b | 76 | } |
kadonotakashi | 0:8fdf9a60065b | 77 | |
kadonotakashi | 0:8fdf9a60065b | 78 | void core_util_critical_section_enter(void) |
kadonotakashi | 0:8fdf9a60065b | 79 | { |
kadonotakashi | 0:8fdf9a60065b | 80 | // If the reentrancy counter overflows something has gone badly wrong. |
kadonotakashi | 0:8fdf9a60065b | 81 | MBED_ASSERT(critical_section_reentrancy_counter < UINT32_MAX); |
kadonotakashi | 0:8fdf9a60065b | 82 | |
kadonotakashi | 0:8fdf9a60065b | 83 | hal_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 84 | |
kadonotakashi | 0:8fdf9a60065b | 85 | ++critical_section_reentrancy_counter; |
kadonotakashi | 0:8fdf9a60065b | 86 | } |
kadonotakashi | 0:8fdf9a60065b | 87 | |
kadonotakashi | 0:8fdf9a60065b | 88 | void core_util_critical_section_exit(void) |
kadonotakashi | 0:8fdf9a60065b | 89 | { |
kadonotakashi | 0:8fdf9a60065b | 90 | |
kadonotakashi | 0:8fdf9a60065b | 91 | // If critical_section_enter has not previously been called, do nothing |
kadonotakashi | 0:8fdf9a60065b | 92 | if (critical_section_reentrancy_counter == 0) { |
kadonotakashi | 0:8fdf9a60065b | 93 | return; |
kadonotakashi | 0:8fdf9a60065b | 94 | } |
kadonotakashi | 0:8fdf9a60065b | 95 | |
kadonotakashi | 0:8fdf9a60065b | 96 | --critical_section_reentrancy_counter; |
kadonotakashi | 0:8fdf9a60065b | 97 | |
kadonotakashi | 0:8fdf9a60065b | 98 | if (critical_section_reentrancy_counter == 0) { |
kadonotakashi | 0:8fdf9a60065b | 99 | hal_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 100 | } |
kadonotakashi | 0:8fdf9a60065b | 101 | } |
kadonotakashi | 0:8fdf9a60065b | 102 | |
kadonotakashi | 0:8fdf9a60065b | 103 | #if MBED_EXCLUSIVE_ACCESS |
kadonotakashi | 0:8fdf9a60065b | 104 | |
kadonotakashi | 0:8fdf9a60065b | 105 | /* Supress __ldrex and __strex deprecated warnings - "#3731-D: intrinsic is deprecated" */ |
kadonotakashi | 0:8fdf9a60065b | 106 | #if defined (__CC_ARM) |
kadonotakashi | 0:8fdf9a60065b | 107 | #pragma diag_suppress 3731 |
kadonotakashi | 0:8fdf9a60065b | 108 | #endif |
kadonotakashi | 0:8fdf9a60065b | 109 | |
kadonotakashi | 0:8fdf9a60065b | 110 | bool core_util_atomic_cas_u8(volatile uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue) |
kadonotakashi | 0:8fdf9a60065b | 111 | { |
kadonotakashi | 0:8fdf9a60065b | 112 | do { |
kadonotakashi | 0:8fdf9a60065b | 113 | uint8_t currentValue = __LDREXB(ptr); |
kadonotakashi | 0:8fdf9a60065b | 114 | if (currentValue != *expectedCurrentValue) { |
kadonotakashi | 0:8fdf9a60065b | 115 | *expectedCurrentValue = currentValue; |
kadonotakashi | 0:8fdf9a60065b | 116 | __CLREX(); |
kadonotakashi | 0:8fdf9a60065b | 117 | return false; |
kadonotakashi | 0:8fdf9a60065b | 118 | } |
kadonotakashi | 0:8fdf9a60065b | 119 | } while (__STREXB(desiredValue, ptr)); |
kadonotakashi | 0:8fdf9a60065b | 120 | return true; |
kadonotakashi | 0:8fdf9a60065b | 121 | } |
kadonotakashi | 0:8fdf9a60065b | 122 | |
kadonotakashi | 0:8fdf9a60065b | 123 | bool core_util_atomic_cas_u16(volatile uint16_t *ptr, uint16_t *expectedCurrentValue, uint16_t desiredValue) |
kadonotakashi | 0:8fdf9a60065b | 124 | { |
kadonotakashi | 0:8fdf9a60065b | 125 | do { |
kadonotakashi | 0:8fdf9a60065b | 126 | uint16_t currentValue = __LDREXH(ptr); |
kadonotakashi | 0:8fdf9a60065b | 127 | if (currentValue != *expectedCurrentValue) { |
kadonotakashi | 0:8fdf9a60065b | 128 | *expectedCurrentValue = currentValue; |
kadonotakashi | 0:8fdf9a60065b | 129 | __CLREX(); |
kadonotakashi | 0:8fdf9a60065b | 130 | return false; |
kadonotakashi | 0:8fdf9a60065b | 131 | } |
kadonotakashi | 0:8fdf9a60065b | 132 | } while (__STREXH(desiredValue, ptr)); |
kadonotakashi | 0:8fdf9a60065b | 133 | return true; |
kadonotakashi | 0:8fdf9a60065b | 134 | } |
kadonotakashi | 0:8fdf9a60065b | 135 | |
kadonotakashi | 0:8fdf9a60065b | 136 | |
kadonotakashi | 0:8fdf9a60065b | 137 | bool core_util_atomic_cas_u32(volatile uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue) |
kadonotakashi | 0:8fdf9a60065b | 138 | { |
kadonotakashi | 0:8fdf9a60065b | 139 | do { |
kadonotakashi | 0:8fdf9a60065b | 140 | uint32_t currentValue = __LDREXW(ptr); |
kadonotakashi | 0:8fdf9a60065b | 141 | if (currentValue != *expectedCurrentValue) { |
kadonotakashi | 0:8fdf9a60065b | 142 | *expectedCurrentValue = currentValue; |
kadonotakashi | 0:8fdf9a60065b | 143 | __CLREX(); |
kadonotakashi | 0:8fdf9a60065b | 144 | return false; |
kadonotakashi | 0:8fdf9a60065b | 145 | } |
kadonotakashi | 0:8fdf9a60065b | 146 | } while (__STREXW(desiredValue, ptr)); |
kadonotakashi | 0:8fdf9a60065b | 147 | return true; |
kadonotakashi | 0:8fdf9a60065b | 148 | } |
kadonotakashi | 0:8fdf9a60065b | 149 | |
kadonotakashi | 0:8fdf9a60065b | 150 | uint8_t core_util_atomic_incr_u8(volatile uint8_t *valuePtr, uint8_t delta) |
kadonotakashi | 0:8fdf9a60065b | 151 | { |
kadonotakashi | 0:8fdf9a60065b | 152 | uint8_t newValue; |
kadonotakashi | 0:8fdf9a60065b | 153 | do { |
kadonotakashi | 0:8fdf9a60065b | 154 | newValue = __LDREXB(valuePtr) + delta; |
kadonotakashi | 0:8fdf9a60065b | 155 | } while (__STREXB(newValue, valuePtr)); |
kadonotakashi | 0:8fdf9a60065b | 156 | return newValue; |
kadonotakashi | 0:8fdf9a60065b | 157 | } |
kadonotakashi | 0:8fdf9a60065b | 158 | |
kadonotakashi | 0:8fdf9a60065b | 159 | uint16_t core_util_atomic_incr_u16(volatile uint16_t *valuePtr, uint16_t delta) |
kadonotakashi | 0:8fdf9a60065b | 160 | { |
kadonotakashi | 0:8fdf9a60065b | 161 | uint16_t newValue; |
kadonotakashi | 0:8fdf9a60065b | 162 | do { |
kadonotakashi | 0:8fdf9a60065b | 163 | newValue = __LDREXH(valuePtr) + delta; |
kadonotakashi | 0:8fdf9a60065b | 164 | } while (__STREXH(newValue, valuePtr)); |
kadonotakashi | 0:8fdf9a60065b | 165 | return newValue; |
kadonotakashi | 0:8fdf9a60065b | 166 | } |
kadonotakashi | 0:8fdf9a60065b | 167 | |
kadonotakashi | 0:8fdf9a60065b | 168 | uint32_t core_util_atomic_incr_u32(volatile uint32_t *valuePtr, uint32_t delta) |
kadonotakashi | 0:8fdf9a60065b | 169 | { |
kadonotakashi | 0:8fdf9a60065b | 170 | uint32_t newValue; |
kadonotakashi | 0:8fdf9a60065b | 171 | do { |
kadonotakashi | 0:8fdf9a60065b | 172 | newValue = __LDREXW(valuePtr) + delta; |
kadonotakashi | 0:8fdf9a60065b | 173 | } while (__STREXW(newValue, valuePtr)); |
kadonotakashi | 0:8fdf9a60065b | 174 | return newValue; |
kadonotakashi | 0:8fdf9a60065b | 175 | } |
kadonotakashi | 0:8fdf9a60065b | 176 | |
kadonotakashi | 0:8fdf9a60065b | 177 | |
kadonotakashi | 0:8fdf9a60065b | 178 | uint8_t core_util_atomic_decr_u8(volatile uint8_t *valuePtr, uint8_t delta) |
kadonotakashi | 0:8fdf9a60065b | 179 | { |
kadonotakashi | 0:8fdf9a60065b | 180 | uint8_t newValue; |
kadonotakashi | 0:8fdf9a60065b | 181 | do { |
kadonotakashi | 0:8fdf9a60065b | 182 | newValue = __LDREXB(valuePtr) - delta; |
kadonotakashi | 0:8fdf9a60065b | 183 | } while (__STREXB(newValue, valuePtr)); |
kadonotakashi | 0:8fdf9a60065b | 184 | return newValue; |
kadonotakashi | 0:8fdf9a60065b | 185 | } |
kadonotakashi | 0:8fdf9a60065b | 186 | |
kadonotakashi | 0:8fdf9a60065b | 187 | uint16_t core_util_atomic_decr_u16(volatile uint16_t *valuePtr, uint16_t delta) |
kadonotakashi | 0:8fdf9a60065b | 188 | { |
kadonotakashi | 0:8fdf9a60065b | 189 | uint16_t newValue; |
kadonotakashi | 0:8fdf9a60065b | 190 | do { |
kadonotakashi | 0:8fdf9a60065b | 191 | newValue = __LDREXH(valuePtr) - delta; |
kadonotakashi | 0:8fdf9a60065b | 192 | } while (__STREXH(newValue, valuePtr)); |
kadonotakashi | 0:8fdf9a60065b | 193 | return newValue; |
kadonotakashi | 0:8fdf9a60065b | 194 | } |
kadonotakashi | 0:8fdf9a60065b | 195 | |
kadonotakashi | 0:8fdf9a60065b | 196 | uint32_t core_util_atomic_decr_u32(volatile uint32_t *valuePtr, uint32_t delta) |
kadonotakashi | 0:8fdf9a60065b | 197 | { |
kadonotakashi | 0:8fdf9a60065b | 198 | uint32_t newValue; |
kadonotakashi | 0:8fdf9a60065b | 199 | do { |
kadonotakashi | 0:8fdf9a60065b | 200 | newValue = __LDREXW(valuePtr) - delta; |
kadonotakashi | 0:8fdf9a60065b | 201 | } while (__STREXW(newValue, valuePtr)); |
kadonotakashi | 0:8fdf9a60065b | 202 | return newValue; |
kadonotakashi | 0:8fdf9a60065b | 203 | } |
kadonotakashi | 0:8fdf9a60065b | 204 | |
kadonotakashi | 0:8fdf9a60065b | 205 | #else |
kadonotakashi | 0:8fdf9a60065b | 206 | |
kadonotakashi | 0:8fdf9a60065b | 207 | bool core_util_atomic_cas_u8(volatile uint8_t *ptr, uint8_t *expectedCurrentValue, uint8_t desiredValue) |
kadonotakashi | 0:8fdf9a60065b | 208 | { |
kadonotakashi | 0:8fdf9a60065b | 209 | bool success; |
kadonotakashi | 0:8fdf9a60065b | 210 | uint8_t currentValue; |
kadonotakashi | 0:8fdf9a60065b | 211 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 212 | currentValue = *ptr; |
kadonotakashi | 0:8fdf9a60065b | 213 | if (currentValue == *expectedCurrentValue) { |
kadonotakashi | 0:8fdf9a60065b | 214 | *ptr = desiredValue; |
kadonotakashi | 0:8fdf9a60065b | 215 | success = true; |
kadonotakashi | 0:8fdf9a60065b | 216 | } else { |
kadonotakashi | 0:8fdf9a60065b | 217 | *expectedCurrentValue = currentValue; |
kadonotakashi | 0:8fdf9a60065b | 218 | success = false; |
kadonotakashi | 0:8fdf9a60065b | 219 | } |
kadonotakashi | 0:8fdf9a60065b | 220 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 221 | return success; |
kadonotakashi | 0:8fdf9a60065b | 222 | } |
kadonotakashi | 0:8fdf9a60065b | 223 | |
kadonotakashi | 0:8fdf9a60065b | 224 | bool core_util_atomic_cas_u16(volatile uint16_t *ptr, uint16_t *expectedCurrentValue, uint16_t desiredValue) |
kadonotakashi | 0:8fdf9a60065b | 225 | { |
kadonotakashi | 0:8fdf9a60065b | 226 | bool success; |
kadonotakashi | 0:8fdf9a60065b | 227 | uint16_t currentValue; |
kadonotakashi | 0:8fdf9a60065b | 228 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 229 | currentValue = *ptr; |
kadonotakashi | 0:8fdf9a60065b | 230 | if (currentValue == *expectedCurrentValue) { |
kadonotakashi | 0:8fdf9a60065b | 231 | *ptr = desiredValue; |
kadonotakashi | 0:8fdf9a60065b | 232 | success = true; |
kadonotakashi | 0:8fdf9a60065b | 233 | } else { |
kadonotakashi | 0:8fdf9a60065b | 234 | *expectedCurrentValue = currentValue; |
kadonotakashi | 0:8fdf9a60065b | 235 | success = false; |
kadonotakashi | 0:8fdf9a60065b | 236 | } |
kadonotakashi | 0:8fdf9a60065b | 237 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 238 | return success; |
kadonotakashi | 0:8fdf9a60065b | 239 | } |
kadonotakashi | 0:8fdf9a60065b | 240 | |
kadonotakashi | 0:8fdf9a60065b | 241 | |
kadonotakashi | 0:8fdf9a60065b | 242 | bool core_util_atomic_cas_u32(volatile uint32_t *ptr, uint32_t *expectedCurrentValue, uint32_t desiredValue) |
kadonotakashi | 0:8fdf9a60065b | 243 | { |
kadonotakashi | 0:8fdf9a60065b | 244 | bool success; |
kadonotakashi | 0:8fdf9a60065b | 245 | uint32_t currentValue; |
kadonotakashi | 0:8fdf9a60065b | 246 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 247 | currentValue = *ptr; |
kadonotakashi | 0:8fdf9a60065b | 248 | if (currentValue == *expectedCurrentValue) { |
kadonotakashi | 0:8fdf9a60065b | 249 | *ptr = desiredValue; |
kadonotakashi | 0:8fdf9a60065b | 250 | success = true; |
kadonotakashi | 0:8fdf9a60065b | 251 | } else { |
kadonotakashi | 0:8fdf9a60065b | 252 | *expectedCurrentValue = currentValue; |
kadonotakashi | 0:8fdf9a60065b | 253 | success = false; |
kadonotakashi | 0:8fdf9a60065b | 254 | } |
kadonotakashi | 0:8fdf9a60065b | 255 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 256 | return success; |
kadonotakashi | 0:8fdf9a60065b | 257 | } |
kadonotakashi | 0:8fdf9a60065b | 258 | |
kadonotakashi | 0:8fdf9a60065b | 259 | |
kadonotakashi | 0:8fdf9a60065b | 260 | uint8_t core_util_atomic_incr_u8(volatile uint8_t *valuePtr, uint8_t delta) |
kadonotakashi | 0:8fdf9a60065b | 261 | { |
kadonotakashi | 0:8fdf9a60065b | 262 | uint8_t newValue; |
kadonotakashi | 0:8fdf9a60065b | 263 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 264 | newValue = *valuePtr + delta; |
kadonotakashi | 0:8fdf9a60065b | 265 | *valuePtr = newValue; |
kadonotakashi | 0:8fdf9a60065b | 266 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 267 | return newValue; |
kadonotakashi | 0:8fdf9a60065b | 268 | } |
kadonotakashi | 0:8fdf9a60065b | 269 | |
kadonotakashi | 0:8fdf9a60065b | 270 | uint16_t core_util_atomic_incr_u16(volatile uint16_t *valuePtr, uint16_t delta) |
kadonotakashi | 0:8fdf9a60065b | 271 | { |
kadonotakashi | 0:8fdf9a60065b | 272 | uint16_t newValue; |
kadonotakashi | 0:8fdf9a60065b | 273 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 274 | newValue = *valuePtr + delta; |
kadonotakashi | 0:8fdf9a60065b | 275 | *valuePtr = newValue; |
kadonotakashi | 0:8fdf9a60065b | 276 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 277 | return newValue; |
kadonotakashi | 0:8fdf9a60065b | 278 | } |
kadonotakashi | 0:8fdf9a60065b | 279 | |
kadonotakashi | 0:8fdf9a60065b | 280 | uint32_t core_util_atomic_incr_u32(volatile uint32_t *valuePtr, uint32_t delta) |
kadonotakashi | 0:8fdf9a60065b | 281 | { |
kadonotakashi | 0:8fdf9a60065b | 282 | uint32_t newValue; |
kadonotakashi | 0:8fdf9a60065b | 283 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 284 | newValue = *valuePtr + delta; |
kadonotakashi | 0:8fdf9a60065b | 285 | *valuePtr = newValue; |
kadonotakashi | 0:8fdf9a60065b | 286 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 287 | return newValue; |
kadonotakashi | 0:8fdf9a60065b | 288 | } |
kadonotakashi | 0:8fdf9a60065b | 289 | |
kadonotakashi | 0:8fdf9a60065b | 290 | |
kadonotakashi | 0:8fdf9a60065b | 291 | uint8_t core_util_atomic_decr_u8(volatile uint8_t *valuePtr, uint8_t delta) |
kadonotakashi | 0:8fdf9a60065b | 292 | { |
kadonotakashi | 0:8fdf9a60065b | 293 | uint8_t newValue; |
kadonotakashi | 0:8fdf9a60065b | 294 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 295 | newValue = *valuePtr - delta; |
kadonotakashi | 0:8fdf9a60065b | 296 | *valuePtr = newValue; |
kadonotakashi | 0:8fdf9a60065b | 297 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 298 | return newValue; |
kadonotakashi | 0:8fdf9a60065b | 299 | } |
kadonotakashi | 0:8fdf9a60065b | 300 | |
kadonotakashi | 0:8fdf9a60065b | 301 | uint16_t core_util_atomic_decr_u16(volatile uint16_t *valuePtr, uint16_t delta) |
kadonotakashi | 0:8fdf9a60065b | 302 | { |
kadonotakashi | 0:8fdf9a60065b | 303 | uint16_t newValue; |
kadonotakashi | 0:8fdf9a60065b | 304 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 305 | newValue = *valuePtr - delta; |
kadonotakashi | 0:8fdf9a60065b | 306 | *valuePtr = newValue; |
kadonotakashi | 0:8fdf9a60065b | 307 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 308 | return newValue; |
kadonotakashi | 0:8fdf9a60065b | 309 | } |
kadonotakashi | 0:8fdf9a60065b | 310 | |
kadonotakashi | 0:8fdf9a60065b | 311 | uint32_t core_util_atomic_decr_u32(volatile uint32_t *valuePtr, uint32_t delta) |
kadonotakashi | 0:8fdf9a60065b | 312 | { |
kadonotakashi | 0:8fdf9a60065b | 313 | uint32_t newValue; |
kadonotakashi | 0:8fdf9a60065b | 314 | core_util_critical_section_enter(); |
kadonotakashi | 0:8fdf9a60065b | 315 | newValue = *valuePtr - delta; |
kadonotakashi | 0:8fdf9a60065b | 316 | *valuePtr = newValue; |
kadonotakashi | 0:8fdf9a60065b | 317 | core_util_critical_section_exit(); |
kadonotakashi | 0:8fdf9a60065b | 318 | return newValue; |
kadonotakashi | 0:8fdf9a60065b | 319 | } |
kadonotakashi | 0:8fdf9a60065b | 320 | |
kadonotakashi | 0:8fdf9a60065b | 321 | #endif |
kadonotakashi | 0:8fdf9a60065b | 322 | |
kadonotakashi | 0:8fdf9a60065b | 323 | |
kadonotakashi | 0:8fdf9a60065b | 324 | bool core_util_atomic_cas_ptr(void *volatile *ptr, void **expectedCurrentValue, void *desiredValue) |
kadonotakashi | 0:8fdf9a60065b | 325 | { |
kadonotakashi | 0:8fdf9a60065b | 326 | return core_util_atomic_cas_u32( |
kadonotakashi | 0:8fdf9a60065b | 327 | (volatile uint32_t *)ptr, |
kadonotakashi | 0:8fdf9a60065b | 328 | (uint32_t *)expectedCurrentValue, |
kadonotakashi | 0:8fdf9a60065b | 329 | (uint32_t)desiredValue); |
kadonotakashi | 0:8fdf9a60065b | 330 | } |
kadonotakashi | 0:8fdf9a60065b | 331 | |
kadonotakashi | 0:8fdf9a60065b | 332 | void *core_util_atomic_incr_ptr(void *volatile *valuePtr, ptrdiff_t delta) |
kadonotakashi | 0:8fdf9a60065b | 333 | { |
kadonotakashi | 0:8fdf9a60065b | 334 | return (void *)core_util_atomic_incr_u32((volatile uint32_t *)valuePtr, (uint32_t)delta); |
kadonotakashi | 0:8fdf9a60065b | 335 | } |
kadonotakashi | 0:8fdf9a60065b | 336 | |
kadonotakashi | 0:8fdf9a60065b | 337 | void *core_util_atomic_decr_ptr(void *volatile *valuePtr, ptrdiff_t delta) |
kadonotakashi | 0:8fdf9a60065b | 338 | { |
kadonotakashi | 0:8fdf9a60065b | 339 | return (void *)core_util_atomic_decr_u32((volatile uint32_t *)valuePtr, (uint32_t)delta); |
kadonotakashi | 0:8fdf9a60065b | 340 | } |
kadonotakashi | 0:8fdf9a60065b | 341 |