mbed-os5 only for TYBLE16
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
platform/source/mbed_critical.c@1:9db0e321a9f4, 2019-12-31 (annotated)
- Committer:
- kenjiArai
- Date:
- Tue Dec 31 06:02:27 2019 +0000
- Revision:
- 1:9db0e321a9f4
updated based on mbed-os5.15.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 1:9db0e321a9f4 | 1 | /* |
kenjiArai | 1:9db0e321a9f4 | 2 | * Copyright (c) 2015-2019, ARM Limited, All Rights Reserved |
kenjiArai | 1:9db0e321a9f4 | 3 | * SPDX-License-Identifier: Apache-2.0 |
kenjiArai | 1:9db0e321a9f4 | 4 | * |
kenjiArai | 1:9db0e321a9f4 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
kenjiArai | 1:9db0e321a9f4 | 6 | * not use this file except in compliance with the License. |
kenjiArai | 1:9db0e321a9f4 | 7 | * You may obtain a copy of the License at |
kenjiArai | 1:9db0e321a9f4 | 8 | * |
kenjiArai | 1:9db0e321a9f4 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 1:9db0e321a9f4 | 10 | * |
kenjiArai | 1:9db0e321a9f4 | 11 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 1:9db0e321a9f4 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
kenjiArai | 1:9db0e321a9f4 | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 1:9db0e321a9f4 | 14 | * See the License for the specific language governing permissions and |
kenjiArai | 1:9db0e321a9f4 | 15 | * limitations under the License. |
kenjiArai | 1:9db0e321a9f4 | 16 | */ |
kenjiArai | 1:9db0e321a9f4 | 17 | |
kenjiArai | 1:9db0e321a9f4 | 18 | /* Declare __STDC_LIMIT_MACROS so stdint.h defines UINT32_MAX when using C++ */ |
kenjiArai | 1:9db0e321a9f4 | 19 | #define __STDC_LIMIT_MACROS |
kenjiArai | 1:9db0e321a9f4 | 20 | #include "hal/critical_section_api.h" |
kenjiArai | 1:9db0e321a9f4 | 21 | |
kenjiArai | 1:9db0e321a9f4 | 22 | #include "cmsis.h" |
kenjiArai | 1:9db0e321a9f4 | 23 | #include "platform/mbed_assert.h" |
kenjiArai | 1:9db0e321a9f4 | 24 | #include "platform/mbed_critical.h" |
kenjiArai | 1:9db0e321a9f4 | 25 | |
kenjiArai | 1:9db0e321a9f4 | 26 | static uint32_t critical_section_reentrancy_counter = 0; |
kenjiArai | 1:9db0e321a9f4 | 27 | |
kenjiArai | 1:9db0e321a9f4 | 28 | bool core_util_are_interrupts_enabled(void) |
kenjiArai | 1:9db0e321a9f4 | 29 | { |
kenjiArai | 1:9db0e321a9f4 | 30 | #if defined(__CORTEX_A9) |
kenjiArai | 1:9db0e321a9f4 | 31 | return ((__get_CPSR() & 0x80) == 0); |
kenjiArai | 1:9db0e321a9f4 | 32 | #else |
kenjiArai | 1:9db0e321a9f4 | 33 | return ((__get_PRIMASK() & 0x1) == 0); |
kenjiArai | 1:9db0e321a9f4 | 34 | #endif |
kenjiArai | 1:9db0e321a9f4 | 35 | } |
kenjiArai | 1:9db0e321a9f4 | 36 | |
kenjiArai | 1:9db0e321a9f4 | 37 | bool core_util_is_isr_active(void) |
kenjiArai | 1:9db0e321a9f4 | 38 | { |
kenjiArai | 1:9db0e321a9f4 | 39 | #if defined(__CORTEX_A9) |
kenjiArai | 1:9db0e321a9f4 | 40 | switch (__get_CPSR() & 0x1FU) { |
kenjiArai | 1:9db0e321a9f4 | 41 | case CPSR_M_USR: |
kenjiArai | 1:9db0e321a9f4 | 42 | case CPSR_M_SYS: |
kenjiArai | 1:9db0e321a9f4 | 43 | return false; |
kenjiArai | 1:9db0e321a9f4 | 44 | case CPSR_M_SVC: |
kenjiArai | 1:9db0e321a9f4 | 45 | default: |
kenjiArai | 1:9db0e321a9f4 | 46 | return true; |
kenjiArai | 1:9db0e321a9f4 | 47 | } |
kenjiArai | 1:9db0e321a9f4 | 48 | #else |
kenjiArai | 1:9db0e321a9f4 | 49 | return (__get_IPSR() != 0U); |
kenjiArai | 1:9db0e321a9f4 | 50 | #endif |
kenjiArai | 1:9db0e321a9f4 | 51 | } |
kenjiArai | 1:9db0e321a9f4 | 52 | |
kenjiArai | 1:9db0e321a9f4 | 53 | bool core_util_in_critical_section(void) |
kenjiArai | 1:9db0e321a9f4 | 54 | { |
kenjiArai | 1:9db0e321a9f4 | 55 | return hal_in_critical_section(); |
kenjiArai | 1:9db0e321a9f4 | 56 | } |
kenjiArai | 1:9db0e321a9f4 | 57 | |
kenjiArai | 1:9db0e321a9f4 | 58 | void core_util_critical_section_enter(void) |
kenjiArai | 1:9db0e321a9f4 | 59 | { |
kenjiArai | 1:9db0e321a9f4 | 60 | hal_critical_section_enter(); |
kenjiArai | 1:9db0e321a9f4 | 61 | |
kenjiArai | 1:9db0e321a9f4 | 62 | // If the reentrancy counter overflows something has gone badly wrong. |
kenjiArai | 1:9db0e321a9f4 | 63 | MBED_ASSERT(critical_section_reentrancy_counter < UINT32_MAX); |
kenjiArai | 1:9db0e321a9f4 | 64 | |
kenjiArai | 1:9db0e321a9f4 | 65 | ++critical_section_reentrancy_counter; |
kenjiArai | 1:9db0e321a9f4 | 66 | } |
kenjiArai | 1:9db0e321a9f4 | 67 | |
kenjiArai | 1:9db0e321a9f4 | 68 | void core_util_critical_section_exit(void) |
kenjiArai | 1:9db0e321a9f4 | 69 | { |
kenjiArai | 1:9db0e321a9f4 | 70 | |
kenjiArai | 1:9db0e321a9f4 | 71 | // If critical_section_enter has not previously been called, do nothing |
kenjiArai | 1:9db0e321a9f4 | 72 | if (critical_section_reentrancy_counter == 0) { |
kenjiArai | 1:9db0e321a9f4 | 73 | return; |
kenjiArai | 1:9db0e321a9f4 | 74 | } |
kenjiArai | 1:9db0e321a9f4 | 75 | |
kenjiArai | 1:9db0e321a9f4 | 76 | --critical_section_reentrancy_counter; |
kenjiArai | 1:9db0e321a9f4 | 77 | |
kenjiArai | 1:9db0e321a9f4 | 78 | if (critical_section_reentrancy_counter == 0) { |
kenjiArai | 1:9db0e321a9f4 | 79 | hal_critical_section_exit(); |
kenjiArai | 1:9db0e321a9f4 | 80 | } |
kenjiArai | 1:9db0e321a9f4 | 81 | } |