Mbed OS Reference
Loading...
Searching...
No Matches
ScopedRomWriteLock.h
1/* mbed Microcontroller Library
2 * Copyright (c) 2018-2019 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#ifndef MBED_SCOPEDROMWRITELOCK_H
18#define MBED_SCOPEDROMWRITELOCK_H
19
20#include "platform/mbed_mpu_mgmt.h"
21#include "platform/NonCopyable.h"
22
23namespace mbed {
24
25/** \addtogroup platform-public-api */
26/** @{*/
27
28/** RAII object for disabling, then restoring ROM write never mode
29 * Usage:
30 * @code
31 *
32 * void f() {
33 * // some code here
34 * {
35 * ScopedRomWriteLock make_ram_executable;
36 * // Code in this block is allowed to write to ROM
37 * }
38 * // Writing to ROM is no longer allowed
39 * }
40 * @endcode
41 */
42class ScopedRomWriteLock : private mbed::NonCopyable<ScopedRomWriteLock> {
43public:
44
45 /**
46 * Allow writing to ROM
47 *
48 * Increment the ROM write lock to ensure code can
49 * write to ROM. This class uses RAII to allow
50 * writing to ROM while it is in scope.
51 */
53 {
55 }
56
57 /**
58 * Restore previous write to ROM settings
59 *
60 * Decrement the ROM write lock to return ROM write
61 * to its prior state.
62 */
64 {
66 }
67};
68
69/**@}*/
70
71}
72
73#endif
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:162
RAII object for disabling, then restoring ROM write never mode Usage:
ScopedRomWriteLock()
Allow writing to ROM.
~ScopedRomWriteLock()
Restore previous write to ROM settings.
void mbed_mpu_manager_unlock_rom_write(void)
Unlock rom write never mode.
void mbed_mpu_manager_lock_rom_write(void)
Lock rom write never mode off.