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.
arm_hal_interrupt.c
00001 /* 00002 * Copyright (c) 2016-2018 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * 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, WITHOUT 00012 * 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 00017 #include "arm_hal_interrupt.h" 00018 #include "arm_hal_interrupt_private.h" 00019 00020 #if MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT 00021 #include "platform/mbed_critical.h" 00022 #else 00023 #include "cmsis_os2.h" 00024 #include "mbed_rtos_storage.h" 00025 #endif 00026 00027 #include <mbed_assert.h> 00028 00029 00030 // The critical section has two alternative implementations, the default which uses mutex 00031 // as locking primitive and the optional, which will bluntly disable interrupts 00032 // for the critical section. The mutex version will not cause issues by delaying 00033 // interrupts, but it has a down side that it can not be used from the interrupt 00034 // service routines. The IRQ-safe version will do the mutual exclusion by temporarily 00035 // disabling the interrupts, so it will have effect on interrupt latency. 00036 #if !MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT 00037 00038 static uint8_t sys_irq_disable_counter; 00039 00040 static mbed_rtos_storage_mutex_t critical_mutex; 00041 static const osMutexAttr_t critical_mutex_attr = { 00042 .name = "nanostack_critical_mutex", 00043 .attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust, 00044 .cb_mem = &critical_mutex, 00045 .cb_size = sizeof critical_mutex, 00046 }; 00047 static osMutexId_t critical_mutex_id; 00048 00049 #endif 00050 00051 void platform_critical_init(void) 00052 { 00053 #if MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT 00054 // nothing to do here 00055 #else 00056 critical_mutex_id = osMutexNew(&critical_mutex_attr); 00057 MBED_ASSERT(critical_mutex_id); 00058 #endif 00059 } 00060 00061 void platform_enter_critical(void) 00062 { 00063 #if MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT 00064 core_util_critical_section_enter(); 00065 #else 00066 osMutexAcquire(critical_mutex_id, osWaitForever); 00067 sys_irq_disable_counter++; 00068 #endif 00069 } 00070 00071 void platform_exit_critical(void) 00072 { 00073 #if MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT 00074 core_util_critical_section_exit(); 00075 #else 00076 --sys_irq_disable_counter; 00077 osMutexRelease(critical_mutex_id); 00078 #endif 00079 }
Generated on Tue Aug 9 2022 00:37:02 by
1.7.2