2018-11-06 15:42:44 +00:00
|
|
|
/* mbed Microcontroller Library
|
2019-06-27 08:49:22 +00:00
|
|
|
* Copyright (c) 2018-2019 ARM Limited
|
2018-11-06 15:42:44 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-11-08 22:38:24 +00:00
|
|
|
#ifndef MBED_SCOPEDROMWRITELOCK_H
|
|
|
|
#define MBED_SCOPEDROMWRITELOCK_H
|
2018-11-06 15:42:44 +00:00
|
|
|
|
|
|
|
#include "platform/mbed_mpu_mgmt.h"
|
|
|
|
#include "platform/NonCopyable.h"
|
|
|
|
|
|
|
|
namespace mbed {
|
|
|
|
|
2019-07-24 15:59:40 +00:00
|
|
|
/** \ingroup mbed-os-public */
|
2019-06-27 08:49:22 +00:00
|
|
|
/** \addtogroup platform-public-api */
|
2018-11-06 15:42:44 +00:00
|
|
|
/** @{*/
|
|
|
|
|
|
|
|
/** RAII object for disabling, then restoring ROM write never mode
|
|
|
|
* Usage:
|
|
|
|
* @code
|
|
|
|
*
|
|
|
|
* void f() {
|
|
|
|
* // some code here
|
|
|
|
* {
|
2018-11-08 22:38:24 +00:00
|
|
|
* ScopedRomWriteLock make_ram_executable;
|
|
|
|
* // Code in this block is allowed to write to ROM
|
2018-11-06 15:42:44 +00:00
|
|
|
* }
|
2018-11-08 22:38:24 +00:00
|
|
|
* // Writing to ROM is no longer allowed
|
2018-11-06 15:42:44 +00:00
|
|
|
* }
|
|
|
|
* @endcode
|
|
|
|
*/
|
2018-11-08 22:38:24 +00:00
|
|
|
class ScopedRomWriteLock : private mbed::NonCopyable<ScopedRomWriteLock> {
|
2018-11-06 15:42:44 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
2018-11-08 22:38:24 +00:00
|
|
|
* Allow writing to ROM
|
2018-11-06 15:42:44 +00:00
|
|
|
*
|
2018-11-08 22:38:24 +00:00
|
|
|
* Increment the ROM write lock to ensure code can
|
|
|
|
* write to ROM. This class uses RAII to allow
|
|
|
|
* writing to ROM while it is in scope.
|
2018-11-06 15:42:44 +00:00
|
|
|
*/
|
2018-11-08 22:38:24 +00:00
|
|
|
ScopedRomWriteLock()
|
2018-11-06 15:42:44 +00:00
|
|
|
{
|
2018-11-08 22:38:24 +00:00
|
|
|
mbed_mpu_manager_lock_rom_write();
|
2018-11-06 15:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-11-08 22:38:24 +00:00
|
|
|
* Restore previous write to ROM settings
|
2018-11-06 15:42:44 +00:00
|
|
|
*
|
2018-11-08 22:38:24 +00:00
|
|
|
* Decrement the ROM write lock to return ROM write
|
2018-11-06 15:42:44 +00:00
|
|
|
* to its prior state.
|
|
|
|
*/
|
2018-11-08 22:38:24 +00:00
|
|
|
~ScopedRomWriteLock()
|
2018-11-06 15:42:44 +00:00
|
|
|
{
|
2018-11-08 22:38:24 +00:00
|
|
|
mbed_mpu_manager_unlock_rom_write();
|
2018-11-06 15:42:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|