mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mpu_api.h Source File

mpu_api.h

00001 
00002 /** \addtogroup hal */
00003 /** @{*/
00004 /* mbed Microcontroller Library
00005  * Copyright (c) 2018-2018 ARM Limited
00006  *
00007  * Licensed under the Apache License, Version 2.0 (the "License");
00008  * you may not use this file except in compliance with the License.
00009  * You may obtain a copy of the License at
00010  *
00011  *     http://www.apache.org/licenses/LICENSE-2.0
00012  *
00013  * Unless required by applicable law or agreed to in writing, software
00014  * distributed under the License is distributed on an "AS IS" BASIS,
00015  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016  * See the License for the specific language governing permissions and
00017  * limitations under the License.
00018  */
00019 #ifndef MBED_MPU_API_H
00020 #define MBED_MPU_API_H
00021 
00022 #include "device.h"
00023 #include <stdbool.h>
00024 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 #if DEVICE_MPU
00030 
00031 /**
00032  * \defgroup hal_mpu MPU hal
00033  *
00034  * The MPU hal provides a simple MPU API to enhance device security by preventing
00035  * execution from ram.
00036  *
00037  * # Defined behavior
00038  * * The function ::mbed_mpu_init is safe to call repeatedly - Verified by ::mpu_init_test
00039  * * The function ::mbed_mpu_free disables MPU protection - Verified by ::mpu_free_test
00040  * * Execution from RAM results in a fault when execute never is enabled.
00041  *      This RAM includes heap, stack, data and zero init - Verified  by ::mpu_fault_test_data,
00042  *      ::mpu_fault_test_bss, ::mpu_fault_test_stack and ::mpu_fault_test_heap.
00043  * * Writing to ROM results in a fault when write never is enabled - Not verified
00044  *
00045  * # Undefined behavior
00046  * * Calling any function other than ::mbed_mpu_init before the initialization of the MPU.
00047  *
00048  * @see hal_mpu_tests
00049  *
00050  * @{
00051  */
00052 
00053 /**
00054  * \defgroup hal_mpu_tests MPU hal tests
00055  * The MPU test validates proper implementation of the MPU hal.
00056  *
00057  * To run the MPU hal tests use the command:
00058  *
00059  *     mbed test -t <toolchain> -m <target> -n tests-mbed_hal-mpu*
00060  */
00061 
00062 
00063 /**
00064  * Initialize the MPU
00065  *
00066  * Initialize or re-initialize the memory protection unit.
00067  * After initialization or re-initialization, ROM and RAM protection
00068  * are both enabled.
00069  */
00070 void mbed_mpu_init(void);
00071 
00072 /**
00073  * Enable or disable ROM MPU protection
00074  *
00075  * This function is used to mark all of ROM as read and execute only.
00076  * When enabled writes to ROM cause a fault.
00077  *
00078  * By default writes to ROM are disabled.
00079  *
00080  * @param enable true to disable writes to ROM, false otherwise
00081  */
00082 void mbed_mpu_enable_rom_wn(bool enable);
00083 
00084 /**
00085  * Enable or disable ram MPU protection
00086  *
00087  * This function is used to mark all of RAM as execute never.
00088  * When enabled code is only allowed to execute from flash.
00089  *
00090  * By default execution from RAM is disabled.
00091  *
00092  * @param enable true to disable execution from RAM, false otherwise
00093  */
00094 void mbed_mpu_enable_ram_xn(bool enable);
00095 
00096 /** Deinitialize the MPU
00097  *
00098  * Powerdown the MPU in preparation for powerdown, reset or jumping to another application.
00099  */
00100 void mbed_mpu_free(void);
00101 
00102 /**@}*/
00103 
00104 #else
00105 
00106 #define mbed_mpu_init()
00107 
00108 #define mbed_mpu_enable_rom_wn(enable) (void)enable
00109 
00110 #define mbed_mpu_enable_ram_xn(enable) (void)enable
00111 
00112 #define mbed_mpu_free()
00113 
00114 #endif
00115 
00116 #ifdef __cplusplus
00117 }
00118 #endif
00119 
00120 #endif
00121 
00122 /** @}*/