Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
mbed_critical.c
00001 /* 00002 * Copyright (c) 2015-2019, ARM Limited, All Rights Reserved 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00006 * not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* Declare __STDC_LIMIT_MACROS so stdint.h defines UINT32_MAX when using C++ */ 00019 #define __STDC_LIMIT_MACROS 00020 #include "hal/critical_section_api.h" 00021 00022 #include "cmsis.h" 00023 #include "platform/mbed_assert.h" 00024 #include "platform/mbed_critical.h" 00025 00026 static uint32_t critical_section_reentrancy_counter = 0; 00027 00028 bool core_util_are_interrupts_enabled(void) 00029 { 00030 #if defined(__CORTEX_A9) 00031 return ((__get_CPSR() & 0x80) == 0); 00032 #else 00033 return ((__get_PRIMASK() & 0x1) == 0); 00034 #endif 00035 } 00036 00037 bool core_util_is_isr_active(void) 00038 { 00039 #if defined(__CORTEX_A9) 00040 switch (__get_CPSR() & 0x1FU) { 00041 case CPSR_M_USR: 00042 case CPSR_M_SYS: 00043 return false; 00044 case CPSR_M_SVC: 00045 default: 00046 return true; 00047 } 00048 #else 00049 return (__get_IPSR() != 0U); 00050 #endif 00051 } 00052 00053 bool core_util_in_critical_section(void) 00054 { 00055 return hal_in_critical_section(); 00056 } 00057 00058 void core_util_critical_section_enter(void) 00059 { 00060 hal_critical_section_enter(); 00061 00062 // If the reentrancy counter overflows something has gone badly wrong. 00063 MBED_ASSERT(critical_section_reentrancy_counter < UINT32_MAX); 00064 00065 ++critical_section_reentrancy_counter; 00066 } 00067 00068 void core_util_critical_section_exit(void) 00069 { 00070 00071 // If critical_section_enter has not previously been called, do nothing 00072 if (critical_section_reentrancy_counter == 0) { 00073 return; 00074 } 00075 00076 --critical_section_reentrancy_counter; 00077 00078 if (critical_section_reentrancy_counter == 0) { 00079 hal_critical_section_exit(); 00080 } 00081 }
Generated on Tue Jul 12 2022 13:54:33 by
