mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
ScopedRamExecutionLock.h
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 #ifndef MBED_SCOPEDRAMEXECUTIONLOCK_H 00017 #define MBED_SCOPEDRAMEXECUTIONLOCK_H 00018 00019 #include "platform/mbed_mpu_mgmt.h" 00020 #include "platform/NonCopyable.h" 00021 00022 namespace mbed { 00023 00024 /** \addtogroup platform */ 00025 /** @{*/ 00026 00027 /** RAII object for disabling, then restoring RAM execute never mode 00028 * Usage: 00029 * @code 00030 * 00031 * void f() { 00032 * // some code here 00033 * { 00034 * ScopedRamExecutionLock make_ram_executable; 00035 * // Code in this block is allowed to call functions in RAM 00036 * } 00037 * // Execution from RAM is no longer allowed 00038 * } 00039 * @endcode 00040 */ 00041 class ScopedRamExecutionLock : private mbed::NonCopyable<ScopedRamExecutionLock> { 00042 public: 00043 00044 /** 00045 * Allow execution from RAM 00046 * 00047 * Increment the execute never lock to ensure code can 00048 * be executed from RAM. This class uses RAII to allow 00049 * execution from ram while it is in scope. 00050 */ 00051 ScopedRamExecutionLock() 00052 { 00053 mbed_mpu_manager_lock_ram_execution(); 00054 } 00055 00056 /** 00057 * Restore previous execution from RAM settings 00058 * 00059 * Decrement the execute never lock to return execute from RAM 00060 * to its prior state. 00061 */ 00062 ~ScopedRamExecutionLock() 00063 { 00064 mbed_mpu_manager_unlock_ram_execution(); 00065 } 00066 }; 00067 00068 /**@}*/ 00069 00070 } 00071 00072 #endif
Generated on Tue Jul 12 2022 20:41:15 by 1.7.2