mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mbed_mpu_mgmt.c Source File

mbed_mpu_mgmt.c

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2018 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 
00017 #include "platform/mbed_mpu_mgmt.h"
00018 #include "platform/mbed_critical.h"
00019 #include "platform/mbed_assert.h"
00020 #include "hal/mpu_api.h"
00021 #include <limits.h>
00022 
00023 #if DEVICE_MPU && MBED_CONF_PLATFORM_USE_MPU
00024 
00025 static uint16_t mem_xn_lock;
00026 static uint16_t mem_wn_lock;
00027 
00028 void mbed_mpu_manager_lock_ram_execution()
00029 {
00030     core_util_critical_section_enter();
00031     MBED_ASSERT(mem_xn_lock != USHRT_MAX);
00032     if (mem_xn_lock == 0) {
00033         mbed_mpu_enable_ram_xn(false);
00034     }
00035     mem_xn_lock++;
00036     core_util_critical_section_exit();
00037 }
00038 
00039 void mbed_mpu_manager_unlock_ram_execution()
00040 {
00041     core_util_critical_section_enter();
00042     MBED_ASSERT(mem_xn_lock != 0);
00043     mem_xn_lock--;
00044     if (mem_xn_lock == 0) {
00045         mbed_mpu_enable_ram_xn(true);
00046     }
00047     core_util_critical_section_exit();
00048 }
00049 
00050 void mbed_mpu_manager_lock_rom_write()
00051 {
00052     core_util_critical_section_enter();
00053     MBED_ASSERT(mem_wn_lock != USHRT_MAX);
00054     if (mem_wn_lock == 0) {
00055         mbed_mpu_enable_rom_wn(false);
00056     }
00057     mem_wn_lock++;
00058     core_util_critical_section_exit();
00059 }
00060 
00061 void mbed_mpu_manager_unlock_rom_write()
00062 {
00063     core_util_critical_section_enter();
00064     MBED_ASSERT(mem_wn_lock != 0);
00065     mem_wn_lock--;
00066     if (mem_wn_lock == 0) {
00067         mbed_mpu_enable_rom_wn(true);
00068     }
00069     core_util_critical_section_exit();
00070 }
00071 
00072 #endif