mbed-os5 only for TYBLE16
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
Diff: platform/source/mbed_mpu_mgmt.c
- Revision:
- 1:9db0e321a9f4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/platform/source/mbed_mpu_mgmt.c Tue Dec 31 06:02:27 2019 +0000 @@ -0,0 +1,72 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018-2019 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "platform/mbed_mpu_mgmt.h" +#include "platform/mbed_critical.h" +#include "platform/mbed_assert.h" +#include <limits.h> +#include <stdbool.h> + +#if DEVICE_MPU && MBED_CONF_PLATFORM_USE_MPU + +static uint16_t mem_xn_lock; +static uint16_t mem_wn_lock; + +void mbed_mpu_manager_lock_ram_execution() +{ + core_util_critical_section_enter(); + MBED_ASSERT(mem_xn_lock != USHRT_MAX); + if (mem_xn_lock == 0) { + mbed_mpu_enable_ram_xn(false); + } + mem_xn_lock++; + core_util_critical_section_exit(); +} + +void mbed_mpu_manager_unlock_ram_execution() +{ + core_util_critical_section_enter(); + MBED_ASSERT(mem_xn_lock != 0); + mem_xn_lock--; + if (mem_xn_lock == 0) { + mbed_mpu_enable_ram_xn(true); + } + core_util_critical_section_exit(); +} + +void mbed_mpu_manager_lock_rom_write() +{ + core_util_critical_section_enter(); + MBED_ASSERT(mem_wn_lock != USHRT_MAX); + if (mem_wn_lock == 0) { + mbed_mpu_enable_rom_wn(false); + } + mem_wn_lock++; + core_util_critical_section_exit(); +} + +void mbed_mpu_manager_unlock_rom_write() +{ + core_util_critical_section_enter(); + MBED_ASSERT(mem_wn_lock != 0); + mem_wn_lock--; + if (mem_wn_lock == 0) { + mbed_mpu_enable_rom_wn(true); + } + core_util_critical_section_exit(); +} + +#endif