Rename lock functions and classes

Invert the name of the lock functions and classes so you are not
locking a negative.
pull/8871/head
Russ Butler 2018-11-08 16:38:24 -06:00 committed by Martin Kojtal
parent a7bf312106
commit caa7b93921
7 changed files with 55 additions and 55 deletions

View File

@ -252,8 +252,8 @@ Case cases[] = {
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{ {
mbed_mpu_manager_lock_ram_xn(); mbed_mpu_manager_lock_ram_execution();
mbed_mpu_manager_lock_rom_wn(); mbed_mpu_manager_lock_rom_write();
GREENTEA_SETUP(20, "default_auto"); GREENTEA_SETUP(20, "default_auto");
return greentea_test_setup_handler(number_of_cases); return greentea_test_setup_handler(number_of_cases);
@ -261,8 +261,8 @@ utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
void greentea_test_teardown(const size_t passed, const size_t failed, const failure_t failure) void greentea_test_teardown(const size_t passed, const size_t failed, const failure_t failure)
{ {
mbed_mpu_manager_unlock_ram_xn(); mbed_mpu_manager_unlock_ram_execution();
mbed_mpu_manager_unlock_rom_wn(); mbed_mpu_manager_unlock_rom_write();
greentea_test_teardown_handler(passed, failed, failure); greentea_test_teardown_handler(passed, failed, failure);
} }

View File

@ -25,8 +25,8 @@
#include <algorithm> #include <algorithm>
#include "FlashIAP.h" #include "FlashIAP.h"
#include "platform/mbed_assert.h" #include "platform/mbed_assert.h"
#include "platform/ScopedMpuXnLock.h" #include "platform/ScopedRamExecutionLock.h"
#include "platform/ScopedMpuWnLock.h" #include "platform/ScopedRomWriteLock.h"
#ifdef DEVICE_FLASH #ifdef DEVICE_FLASH
@ -59,8 +59,8 @@ int FlashIAP::init()
int ret = 0; int ret = 0;
_mutex->lock(); _mutex->lock();
{ {
ScopedMpuXnLock make_ram_executable; ScopedRamExecutionLock make_ram_executable;
ScopedMpuWnLock make_rom_writable; ScopedRomWriteLock make_rom_writable;
if (flash_init(&_flash)) { if (flash_init(&_flash)) {
ret = -1; ret = -1;
} }
@ -77,8 +77,8 @@ int FlashIAP::deinit()
int ret = 0; int ret = 0;
_mutex->lock(); _mutex->lock();
{ {
ScopedMpuXnLock make_ram_executable; ScopedRamExecutionLock make_ram_executable;
ScopedMpuWnLock make_rom_writable; ScopedRomWriteLock make_rom_writable;
if (flash_free(&_flash)) { if (flash_free(&_flash)) {
ret = -1; ret = -1;
} }
@ -94,8 +94,8 @@ int FlashIAP::read(void *buffer, uint32_t addr, uint32_t size)
int32_t ret = -1; int32_t ret = -1;
_mutex->lock(); _mutex->lock();
{ {
ScopedMpuXnLock make_ram_executable; ScopedRamExecutionLock make_ram_executable;
ScopedMpuWnLock make_rom_writable; ScopedRomWriteLock make_rom_writable;
ret = flash_read(&_flash, addr, (uint8_t *) buffer, size); ret = flash_read(&_flash, addr, (uint8_t *) buffer, size);
} }
_mutex->unlock(); _mutex->unlock();
@ -141,8 +141,8 @@ int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size)
prog_size = chunk; prog_size = chunk;
} }
{ {
ScopedMpuXnLock make_ram_executable; ScopedRamExecutionLock make_ram_executable;
ScopedMpuWnLock make_rom_writable; ScopedRomWriteLock make_rom_writable;
if (flash_program_page(&_flash, addr, prog_buf, prog_size)) { if (flash_program_page(&_flash, addr, prog_buf, prog_size)) {
ret = -1; ret = -1;
break; break;
@ -189,8 +189,8 @@ int FlashIAP::erase(uint32_t addr, uint32_t size)
_mutex->lock(); _mutex->lock();
while (size) { while (size) {
{ {
ScopedMpuXnLock make_ram_executable; ScopedRamExecutionLock make_ram_executable;
ScopedMpuWnLock make_rom_writable; ScopedRomWriteLock make_rom_writable;
ret = flash_erase_sector(&_flash, addr); ret = flash_erase_sector(&_flash, addr);
} }
if (ret != 0) { if (ret != 0) {

4
mbed.h
View File

@ -95,8 +95,8 @@
#include "platform/DirHandle.h" #include "platform/DirHandle.h"
#include "platform/CriticalSectionLock.h" #include "platform/CriticalSectionLock.h"
#include "platform/DeepSleepLock.h" #include "platform/DeepSleepLock.h"
#include "platform/ScopedMpuWnLock.h" #include "platform/ScopedRomWriteLock.h"
#include "platform/ScopedMpuXnLock.h" #include "platform/ScopedRamExecutionLock.h"
#include "platform/mbed_stats.h" #include "platform/mbed_stats.h"
// mbed Non-hardware components // mbed Non-hardware components

View File

@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifndef MBED_SCOPEDMPUXNLOCK_H #ifndef MBED_SCOPEDRAMEXECUTIONLOCK_H
#define MBED_SCOPEDMPUXNLOCK_H #define MBED_SCOPEDRAMEXECUTIONLOCK_H
#include "platform/mbed_mpu_mgmt.h" #include "platform/mbed_mpu_mgmt.h"
#include "platform/NonCopyable.h" #include "platform/NonCopyable.h"
@ -31,14 +31,14 @@ namespace mbed {
* void f() { * void f() {
* // some code here * // some code here
* { * {
* ScopedMpuXnLock xn; * ScopedRamExecutionLock make_ram_executable;
* // Code in this block is allowed to call functions in RAM * // Code in this block is allowed to call functions in RAM
* } * }
* // Execution from RAM is no longer allowed * // Execution from RAM is no longer allowed
* } * }
* @endcode * @endcode
*/ */
class ScopedMpuXnLock : private mbed::NonCopyable<ScopedMpuXnLock> { class ScopedRamExecutionLock : private mbed::NonCopyable<ScopedRamExecutionLock> {
public: public:
/** /**
@ -48,9 +48,9 @@ public:
* be executed from RAM. This class uses RAII to allow * be executed from RAM. This class uses RAII to allow
* execution from ram while it is in scope. * execution from ram while it is in scope.
*/ */
ScopedMpuXnLock() ScopedRamExecutionLock()
{ {
mbed_mpu_manager_lock_ram_xn(); mbed_mpu_manager_lock_ram_execution();
} }
/** /**
@ -59,9 +59,9 @@ public:
* Decrement the execute never lock to return execute from RAM * Decrement the execute never lock to return execute from RAM
* to its prior state. * to its prior state.
*/ */
~ScopedMpuXnLock() ~ScopedRamExecutionLock()
{ {
mbed_mpu_manager_unlock_ram_xn(); mbed_mpu_manager_unlock_ram_execution();
} }
}; };

View File

@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifndef MBED_SCOPEDMPUWNLOCK_H #ifndef MBED_SCOPEDROMWRITELOCK_H
#define MBED_SCOPEDMPUWNLOCK_H #define MBED_SCOPEDROMWRITELOCK_H
#include "platform/mbed_mpu_mgmt.h" #include "platform/mbed_mpu_mgmt.h"
#include "platform/NonCopyable.h" #include "platform/NonCopyable.h"
@ -31,37 +31,37 @@ namespace mbed {
* void f() { * void f() {
* // some code here * // some code here
* { * {
* ScopedMpuXnLock xn; * ScopedRomWriteLock make_ram_executable;
* // Code in this block is allowed to call functions in RAM * // Code in this block is allowed to write to ROM
* } * }
* // Execution from RAM is no longer allowed * // Writing to ROM is no longer allowed
* } * }
* @endcode * @endcode
*/ */
class ScopedMpuWnLock : private mbed::NonCopyable<ScopedMpuWnLock> { class ScopedRomWriteLock : private mbed::NonCopyable<ScopedRomWriteLock> {
public: public:
/** /**
* Allow execution from RAM * Allow writing to ROM
* *
* Increment the execute never lock to ensure code can * Increment the ROM write lock to ensure code can
* be executed from RAM. This class uses RAII to allow * write to ROM. This class uses RAII to allow
* execution from ram while it is in scope. * writing to ROM while it is in scope.
*/ */
ScopedMpuWnLock() ScopedRomWriteLock()
{ {
mbed_mpu_manager_lock_rom_wn(); mbed_mpu_manager_lock_rom_write();
} }
/** /**
* Restore previous execution from RAM settings * Restore previous write to ROM settings
* *
* Decrement the execute never lock to return execute from RAM * Decrement the ROM write lock to return ROM write
* to its prior state. * to its prior state.
*/ */
~ScopedMpuWnLock() ~ScopedRomWriteLock()
{ {
mbed_mpu_manager_unlock_rom_wn(); mbed_mpu_manager_unlock_rom_write();
} }
}; };

View File

@ -23,7 +23,7 @@
static uint16_t mem_xn_lock; static uint16_t mem_xn_lock;
static uint16_t mem_wn_lock; static uint16_t mem_wn_lock;
void mbed_mpu_manager_lock_ram_xn() void mbed_mpu_manager_lock_ram_execution()
{ {
core_util_critical_section_enter(); core_util_critical_section_enter();
if (mem_xn_lock == USHRT_MAX) { if (mem_xn_lock == USHRT_MAX) {
@ -37,7 +37,7 @@ void mbed_mpu_manager_lock_ram_xn()
core_util_critical_section_exit(); core_util_critical_section_exit();
} }
void mbed_mpu_manager_unlock_ram_xn() void mbed_mpu_manager_unlock_ram_execution()
{ {
core_util_critical_section_enter(); core_util_critical_section_enter();
if (mem_xn_lock == 0) { if (mem_xn_lock == 0) {
@ -51,7 +51,7 @@ void mbed_mpu_manager_unlock_ram_xn()
core_util_critical_section_exit(); core_util_critical_section_exit();
} }
void mbed_mpu_manager_lock_rom_wn() void mbed_mpu_manager_lock_rom_write()
{ {
core_util_critical_section_enter(); core_util_critical_section_enter();
if (mem_wn_lock == USHRT_MAX) { if (mem_wn_lock == USHRT_MAX) {
@ -65,7 +65,7 @@ void mbed_mpu_manager_lock_rom_wn()
core_util_critical_section_exit(); core_util_critical_section_exit();
} }
void mbed_mpu_manager_unlock_rom_wn() void mbed_mpu_manager_unlock_rom_write()
{ {
core_util_critical_section_enter(); core_util_critical_section_enter();
if (mem_wn_lock == 0) { if (mem_wn_lock == 0) {

View File

@ -45,20 +45,20 @@ extern "C" {
* The lock is a counter, can be locked up to USHRT_MAX * The lock is a counter, can be locked up to USHRT_MAX
* This function is IRQ and thread safe * This function is IRQ and thread safe
*/ */
void mbed_mpu_manager_lock_ram_xn(void); void mbed_mpu_manager_lock_ram_execution(void);
/** Unlock ram execute never mode /** Unlock ram execute never mode
* *
* Use unlocking in pair with mbed_mpu_manager_lock_ram_xn(). * Use unlocking in pair with mbed_mpu_manager_lock_ram_execution().
* *
* The lock is a counter, should be equally unlocked as locked * The lock is a counter, should be equally unlocked as locked
* This function is IRQ and thread safe * This function is IRQ and thread safe
*/ */
void mbed_mpu_manager_unlock_ram_xn(void); void mbed_mpu_manager_unlock_ram_execution(void);
/** Lock rom write never mode off /** Lock rom write never mode off
* *
* This disables the MPU's write never ROM protection and allows * This disables the MPU's read only ROM protection and allows
* ROM to be written to. Writing to ROM will not result in an MPU * ROM to be written to. Writing to ROM will not result in an MPU
* fault if this function is invoked at least once (the internal * fault if this function is invoked at least once (the internal
* counter is non-zero). * counter is non-zero).
@ -69,16 +69,16 @@ void mbed_mpu_manager_unlock_ram_xn(void);
* The lock is a counter, can be locked up to USHRT_MAX * The lock is a counter, can be locked up to USHRT_MAX
* This function is IRQ and thread safe * This function is IRQ and thread safe
*/ */
void mbed_mpu_manager_lock_rom_wn(void); void mbed_mpu_manager_lock_rom_write(void);
/** Unlock rom write never mode /** Unlock rom write never mode
* *
* Use unlocking in pair with mbed_mpu_manager_lock_rom_wn(). * Use unlocking in pair with mbed_mpu_manager_lock_rom_write().
* *
* The lock is a counter, should be equally unlocked as locked * The lock is a counter, should be equally unlocked as locked
* This function is IRQ and thread safe * This function is IRQ and thread safe
*/ */
void mbed_mpu_manager_unlock_rom_wn(void); void mbed_mpu_manager_unlock_rom_write(void);
#ifdef __cplusplus #ifdef __cplusplus
} }