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.
Fork of mbed-dev by
mbed_critical_section_api.c
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2017 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "cmsis.h" 00017 #include "hal/critical_section_api.h" 00018 #include "platform/mbed_assert.h" 00019 #include "platform/mbed_toolchain.h" 00020 00021 #include <stdbool.h> 00022 00023 static volatile bool critical_interrupts_enabled = false; 00024 static volatile bool state_saved = false; 00025 00026 static bool are_interrupts_enabled(void) 00027 { 00028 #if defined(__CORTEX_A9) 00029 return ((__get_CPSR() & 0x80) == 0); 00030 #else 00031 return ((__get_PRIMASK() & 0x1) == 0); 00032 #endif 00033 } 00034 00035 00036 MBED_WEAK void hal_critical_section_enter(void) 00037 { 00038 const bool interrupt_state = are_interrupts_enabled(); 00039 00040 __disable_irq(); 00041 00042 if (state_saved == true) { 00043 return; 00044 } 00045 00046 critical_interrupts_enabled = interrupt_state; 00047 state_saved = true; 00048 } 00049 00050 MBED_WEAK void hal_critical_section_exit(void) 00051 { 00052 #ifndef FEATURE_UVISOR 00053 // Interrupts must be disabled on invoking an exit from a critical section 00054 MBED_ASSERT(!are_interrupts_enabled()); 00055 #endif 00056 state_saved = false; 00057 00058 // Restore the IRQs to their state prior to entering the critical section 00059 if (critical_interrupts_enabled == true) { 00060 __enable_irq(); 00061 } 00062 } 00063 00064 MBED_WEAK bool hal_in_critical_section(void) 00065 { 00066 return (state_saved == true); 00067 }
Generated on Tue Jul 12 2022 12:59:33 by
1.7.2
