diff --git a/TESTS/mbed_hal/flash/functional_tests/main.cpp b/TESTS/mbed_hal/flash/functional_tests/main.cpp index 498e666..06c876d 100644 --- a/TESTS/mbed_hal/flash/functional_tests/main.cpp +++ b/TESTS/mbed_hal/flash/functional_tests/main.cpp @@ -252,8 +252,8 @@ utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { - mbed_mpu_manager_lock_ram_xn(); - mbed_mpu_manager_lock_rom_wn(); + mbed_mpu_manager_lock_ram_execution(); + mbed_mpu_manager_lock_rom_write(); GREENTEA_SETUP(20, "default_auto"); return greentea_test_setup_handler(number_of_cases); @@ -261,8 +261,8 @@ 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_rom_wn(); + mbed_mpu_manager_unlock_ram_execution(); + mbed_mpu_manager_unlock_rom_write(); greentea_test_teardown_handler(passed, failed, failure); } diff --git a/drivers/FlashIAP.cpp b/drivers/FlashIAP.cpp index dcac66c..8ef6f6e 100644 --- a/drivers/FlashIAP.cpp +++ b/drivers/FlashIAP.cpp @@ -25,8 +25,8 @@ #include #include "FlashIAP.h" #include "platform/mbed_assert.h" -#include "platform/ScopedMpuXnLock.h" -#include "platform/ScopedMpuWnLock.h" +#include "platform/ScopedRamExecutionLock.h" +#include "platform/ScopedRomWriteLock.h" #ifdef DEVICE_FLASH @@ -59,8 +59,8 @@ int ret = 0; _mutex->lock(); { - ScopedMpuXnLock make_ram_executable; - ScopedMpuWnLock make_rom_writable; + ScopedRamExecutionLock make_ram_executable; + ScopedRomWriteLock make_rom_writable; if (flash_init(&_flash)) { ret = -1; } @@ -77,8 +77,8 @@ int ret = 0; _mutex->lock(); { - ScopedMpuXnLock make_ram_executable; - ScopedMpuWnLock make_rom_writable; + ScopedRamExecutionLock make_ram_executable; + ScopedRomWriteLock make_rom_writable; if (flash_free(&_flash)) { ret = -1; } @@ -94,8 +94,8 @@ int32_t ret = -1; _mutex->lock(); { - ScopedMpuXnLock make_ram_executable; - ScopedMpuWnLock make_rom_writable; + ScopedRamExecutionLock make_ram_executable; + ScopedRomWriteLock make_rom_writable; ret = flash_read(&_flash, addr, (uint8_t *) buffer, size); } _mutex->unlock(); @@ -141,8 +141,8 @@ prog_size = chunk; } { - ScopedMpuXnLock make_ram_executable; - ScopedMpuWnLock make_rom_writable; + ScopedRamExecutionLock make_ram_executable; + ScopedRomWriteLock make_rom_writable; if (flash_program_page(&_flash, addr, prog_buf, prog_size)) { ret = -1; break; @@ -189,8 +189,8 @@ _mutex->lock(); while (size) { { - ScopedMpuXnLock make_ram_executable; - ScopedMpuWnLock make_rom_writable; + ScopedRamExecutionLock make_ram_executable; + ScopedRomWriteLock make_rom_writable; ret = flash_erase_sector(&_flash, addr); } if (ret != 0) { diff --git a/mbed.h b/mbed.h index acdc548..e247e1d 100644 --- a/mbed.h +++ b/mbed.h @@ -95,8 +95,8 @@ #include "platform/DirHandle.h" #include "platform/CriticalSectionLock.h" #include "platform/DeepSleepLock.h" -#include "platform/ScopedMpuWnLock.h" -#include "platform/ScopedMpuXnLock.h" +#include "platform/ScopedRomWriteLock.h" +#include "platform/ScopedRamExecutionLock.h" #include "platform/mbed_stats.h" // mbed Non-hardware components diff --git a/platform/ScopedMpuWnLock.h b/platform/ScopedMpuWnLock.h deleted file mode 100644 index 33309ac..0000000 --- a/platform/ScopedMpuWnLock.h +++ /dev/null @@ -1,72 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2018 ARM Limited - * - * 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. - */ -#ifndef MBED_SCOPEDMPUWNLOCK_H -#define MBED_SCOPEDMPUWNLOCK_H - -#include "platform/mbed_mpu_mgmt.h" -#include "platform/NonCopyable.h" - -namespace mbed { - -/** \addtogroup platform */ -/** @{*/ - -/** RAII object for disabling, then restoring ROM write never mode - * Usage: - * @code - * - * void f() { - * // some code here - * { - * ScopedMpuXnLock xn; - * // Code in this block is allowed to call functions in RAM - * } - * // Execution from RAM is no longer allowed - * } - * @endcode - */ -class ScopedMpuWnLock : private mbed::NonCopyable { -public: - - /** - * Allow execution from RAM - * - * Increment the execute never lock to ensure code can - * be executed from RAM. This class uses RAII to allow - * execution from ram while it is in scope. - */ - ScopedMpuWnLock() - { - mbed_mpu_manager_lock_rom_wn(); - } - - /** - * Restore previous execution from RAM settings - * - * Decrement the execute never lock to return execute from RAM - * to its prior state. - */ - ~ScopedMpuWnLock() - { - mbed_mpu_manager_unlock_rom_wn(); - } -}; - -/**@}*/ - -} - -#endif diff --git a/platform/ScopedMpuXnLock.h b/platform/ScopedMpuXnLock.h deleted file mode 100644 index 2b286fb..0000000 --- a/platform/ScopedMpuXnLock.h +++ /dev/null @@ -1,72 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2018 ARM Limited - * - * 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. - */ -#ifndef MBED_SCOPEDMPUXNLOCK_H -#define MBED_SCOPEDMPUXNLOCK_H - -#include "platform/mbed_mpu_mgmt.h" -#include "platform/NonCopyable.h" - -namespace mbed { - -/** \addtogroup platform */ -/** @{*/ - -/** RAII object for disabling, then restoring RAM execute never mode - * Usage: - * @code - * - * void f() { - * // some code here - * { - * ScopedMpuXnLock xn; - * // Code in this block is allowed to call functions in RAM - * } - * // Execution from RAM is no longer allowed - * } - * @endcode - */ -class ScopedMpuXnLock : private mbed::NonCopyable { -public: - - /** - * Allow execution from RAM - * - * Increment the execute never lock to ensure code can - * be executed from RAM. This class uses RAII to allow - * execution from ram while it is in scope. - */ - ScopedMpuXnLock() - { - mbed_mpu_manager_lock_ram_xn(); - } - - /** - * Restore previous execution from RAM settings - * - * Decrement the execute never lock to return execute from RAM - * to its prior state. - */ - ~ScopedMpuXnLock() - { - mbed_mpu_manager_unlock_ram_xn(); - } -}; - -/**@}*/ - -} - -#endif diff --git a/platform/ScopedRamExecutionLock.h b/platform/ScopedRamExecutionLock.h new file mode 100644 index 0000000..d45b3f9 --- /dev/null +++ b/platform/ScopedRamExecutionLock.h @@ -0,0 +1,72 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * 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. + */ +#ifndef MBED_SCOPEDRAMEXECUTIONLOCK_H +#define MBED_SCOPEDRAMEXECUTIONLOCK_H + +#include "platform/mbed_mpu_mgmt.h" +#include "platform/NonCopyable.h" + +namespace mbed { + +/** \addtogroup platform */ +/** @{*/ + +/** RAII object for disabling, then restoring RAM execute never mode + * Usage: + * @code + * + * void f() { + * // some code here + * { + * ScopedRamExecutionLock make_ram_executable; + * // Code in this block is allowed to call functions in RAM + * } + * // Execution from RAM is no longer allowed + * } + * @endcode + */ +class ScopedRamExecutionLock : private mbed::NonCopyable { +public: + + /** + * Allow execution from RAM + * + * Increment the execute never lock to ensure code can + * be executed from RAM. This class uses RAII to allow + * execution from ram while it is in scope. + */ + ScopedRamExecutionLock() + { + mbed_mpu_manager_lock_ram_execution(); + } + + /** + * Restore previous execution from RAM settings + * + * Decrement the execute never lock to return execute from RAM + * to its prior state. + */ + ~ScopedRamExecutionLock() + { + mbed_mpu_manager_unlock_ram_execution(); + } +}; + +/**@}*/ + +} + +#endif diff --git a/platform/ScopedRomWriteLock.h b/platform/ScopedRomWriteLock.h new file mode 100644 index 0000000..7cd6d5f --- /dev/null +++ b/platform/ScopedRomWriteLock.h @@ -0,0 +1,72 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * 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. + */ +#ifndef MBED_SCOPEDROMWRITELOCK_H +#define MBED_SCOPEDROMWRITELOCK_H + +#include "platform/mbed_mpu_mgmt.h" +#include "platform/NonCopyable.h" + +namespace mbed { + +/** \addtogroup platform */ +/** @{*/ + +/** RAII object for disabling, then restoring ROM write never mode + * Usage: + * @code + * + * void f() { + * // some code here + * { + * ScopedRomWriteLock make_ram_executable; + * // Code in this block is allowed to write to ROM + * } + * // Writing to ROM is no longer allowed + * } + * @endcode + */ +class ScopedRomWriteLock : private mbed::NonCopyable { +public: + + /** + * Allow writing to ROM + * + * 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. + */ + ScopedRomWriteLock() + { + mbed_mpu_manager_lock_rom_write(); + } + + /** + * Restore previous write to ROM settings + * + * Decrement the ROM write lock to return ROM write + * to its prior state. + */ + ~ScopedRomWriteLock() + { + mbed_mpu_manager_unlock_rom_write(); + } +}; + +/**@}*/ + +} + +#endif diff --git a/platform/mbed_mpu_mgmt.c b/platform/mbed_mpu_mgmt.c index 39369b7..fa8bc54 100644 --- a/platform/mbed_mpu_mgmt.c +++ b/platform/mbed_mpu_mgmt.c @@ -23,7 +23,7 @@ static uint16_t mem_xn_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(); if (mem_xn_lock == USHRT_MAX) { @@ -37,7 +37,7 @@ core_util_critical_section_exit(); } -void mbed_mpu_manager_unlock_ram_xn() +void mbed_mpu_manager_unlock_ram_execution() { core_util_critical_section_enter(); if (mem_xn_lock == 0) { @@ -51,7 +51,7 @@ core_util_critical_section_exit(); } -void mbed_mpu_manager_lock_rom_wn() +void mbed_mpu_manager_lock_rom_write() { core_util_critical_section_enter(); if (mem_wn_lock == USHRT_MAX) { @@ -65,7 +65,7 @@ core_util_critical_section_exit(); } -void mbed_mpu_manager_unlock_rom_wn() +void mbed_mpu_manager_unlock_rom_write() { core_util_critical_section_enter(); if (mem_wn_lock == 0) { diff --git a/platform/mbed_mpu_mgmt.h b/platform/mbed_mpu_mgmt.h index 071cfef..7af043f 100644 --- a/platform/mbed_mpu_mgmt.h +++ b/platform/mbed_mpu_mgmt.h @@ -36,7 +36,7 @@ * * This disables the MPU's execute never ram protection and allows * functions to run from RAM. Execution directly from ram will be - * allowed if this function is invoked at least once(the internal + * allowed if this function is invoked at least once (the internal * counter is non-zero). * * Use this locking mechanism for code which needs to execute from @@ -45,22 +45,22 @@ * The lock is a counter, can be locked up to USHRT_MAX * 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 * - * 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 * 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 * - * 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 - * 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). * * Use this locking mechanism for code which needs to write to @@ -69,16 +69,16 @@ * The lock is a counter, can be locked up to USHRT_MAX * 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 * - * 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 * 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 }