mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
ScopedRomWriteLock.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_SCOPEDROMWRITELOCK_H 00017 #define MBED_SCOPEDROMWRITELOCK_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 ROM write never mode 00028 * Usage: 00029 * @code 00030 * 00031 * void f() { 00032 * // some code here 00033 * { 00034 * ScopedRomWriteLock make_ram_executable; 00035 * // Code in this block is allowed to write to ROM 00036 * } 00037 * // Writing to ROM is no longer allowed 00038 * } 00039 * @endcode 00040 */ 00041 class ScopedRomWriteLock : private mbed::NonCopyable<ScopedRomWriteLock> { 00042 public: 00043 00044 /** 00045 * Allow writing to ROM 00046 * 00047 * Increment the ROM write lock to ensure code can 00048 * write to ROM. This class uses RAII to allow 00049 * writing to ROM while it is in scope. 00050 */ 00051 ScopedRomWriteLock() 00052 { 00053 mbed_mpu_manager_lock_rom_write(); 00054 } 00055 00056 /** 00057 * Restore previous write to ROM settings 00058 * 00059 * Decrement the ROM write lock to return ROM write 00060 * to its prior state. 00061 */ 00062 ~ScopedRomWriteLock() 00063 { 00064 mbed_mpu_manager_unlock_rom_write(); 00065 } 00066 }; 00067 00068 /**@}*/ 00069 00070 } 00071 00072 #endif
Generated on Tue Jul 12 2022 20:41:15 by 1.7.2