S32 SDK
mpu_driver.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
23 #ifndef MPU_DRIVER_H
24 #define MPU_DRIVER_H
25 
26 #include "status.h"
27 #include "device_registers.h"
28 
37 /*******************************************************************************
38  * Definitions
39  *******************************************************************************/
44 typedef enum
45 {
49 
54 typedef enum
55 {
61 
66 typedef struct
67 {
68  uint8_t master;
71  uint16_t accessCtr;
72  uint32_t addr;
73 #if FEATURE_MPU_HAS_PROCESS_IDENTIFIER
74  uint8_t processorIdentification;
75 #endif
77 
124 typedef enum
125 {
126  /* Format: M_R_W_SS_UUU
127  * M : 1 bit - Specify that access right is for masters which have separated
128  * privilege rights for user and supervisor mode accesses (e.g. master0~3)
129  * R : 1 bit - Read access permission
130  * W : 1 bit - Write access permission
131  * SS : 2 bits - Supervisor Mode Access Control
132  * UUU: 3 bits - User Mode Access Control
133  */
166  MPU_NONE = 0x80U,
167  MPU_W = 0xA0U,
168  MPU_R = 0xC0U,
169  MPU_RW = 0xE0U
171 
176 typedef struct
177 {
178  uint8_t masterNum;
180 #if FEATURE_MPU_HAS_PROCESS_IDENTIFIER
181  bool processIdentifierEnable;
182 #endif
184 
190 typedef struct
191 {
192  uint32_t startAddr;
193  uint32_t endAddr;
195 #if FEATURE_MPU_HAS_PROCESS_IDENTIFIER
196  uint8_t processIdentifier;
197  uint8_t processIdMask;
199 #endif /* FEATURE_MPU_HAS_PROCESS_IDENTIFIER */
201 
202 /*******************************************************************************
203  * API
204  *******************************************************************************/
209 #if defined(__cplusplus)
210 extern "C" {
211 #endif
212 
227 status_t MPU_DRV_Init(uint32_t instance,
228  uint8_t regionCnt,
229  const mpu_user_config_t *userConfigArr);
230 
236 void MPU_DRV_Deinit(uint32_t instance);
237 
246 void MPU_DRV_SetRegionAddr(uint32_t instance,
247  uint8_t regionNum,
248  uint32_t startAddr,
249  uint32_t endAddr);
250 
261 status_t MPU_DRV_SetRegionConfig(uint32_t instance,
262  uint8_t regionNum,
263  const mpu_user_config_t *userConfigPtr);
264 
275 status_t MPU_DRV_SetMasterAccessRights(uint32_t instance,
276  uint8_t regionNum,
277  const mpu_master_access_right_t *accessRightsPtr);
278 
289 bool MPU_DRV_GetDetailErrorAccessInfo(uint32_t instance,
290  uint8_t slavePortNum,
291  mpu_access_err_info_t *errInfoPtr);
292 
302 
313 void MPU_DRV_EnableRegion(uint32_t instance,
314  uint8_t regionNum,
315  bool enable);
316 
319 #if defined(__cplusplus)
320 }
321 #endif
322 
325 #endif /* MPU_DRIVER_H */
326 /*******************************************************************************
327  * EOF
328  *******************************************************************************/
MPU master access rights. Implements : mpu_master_access_right_t_Class.
Definition: mpu_driver.h:176
mpu_err_access_type_t
MPU access error Implements : mpu_err_access_type_t_Class.
Definition: mpu_driver.h:44
const mpu_master_access_right_t * masterAccRight
Definition: mpu_driver.h:194
void MPU_DRV_Deinit(uint32_t instance)
De-initializes the MPU region by resetting and disabling MPU module.
Definition: mpu_driver.c:105
uint32_t startAddr
Definition: mpu_driver.h:192
mpu_user_config_t MPU_DRV_GetDefaultRegionConfig(mpu_master_access_right_t *masterAccRight)
Gets default region configuration.
Definition: mpu_driver.c:286
uint32_t endAddr
Definition: mpu_driver.h:193
mpu_err_access_type_t accessType
Definition: mpu_driver.h:70
bool MPU_DRV_GetDetailErrorAccessInfo(uint32_t instance, uint8_t slavePortNum, mpu_access_err_info_t *errInfoPtr)
Checks and gets the MPU access error detail information for a slave port.
Definition: mpu_driver.c:254
mpu_access_rights_t
MPU access rights. Code Supervisor User Description MPU_SUPERVISOR_RWX_USER_NONE r w x - - - Allow R...
Definition: mpu_driver.h:124
status_t MPU_DRV_Init(uint32_t instance, uint8_t regionCnt, const mpu_user_config_t *userConfigArr)
The function sets the MPU regions according to user input and then enables the MPU. Please note that access rights for region 0 will always be configured and regionCnt takes values between 1 and the maximum region count supported by the hardware. e.g. In S32K144 the number of supported regions is 8. The user must make sure that the clock is enabled.
Definition: mpu_driver.c:63
status_t MPU_DRV_SetMasterAccessRights(uint32_t instance, uint8_t regionNum, const mpu_master_access_right_t *accessRightsPtr)
Configures access permission.
Definition: mpu_driver.c:222
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:44
mpu_err_attributes_t
MPU access error attributes Implements : mpu_err_attributes_t_Class.
Definition: mpu_driver.h:54
MPU user region configuration structure. This structure is used when calling the MPU_DRV_Init functio...
Definition: mpu_driver.h:190
mpu_err_attributes_t attributes
Definition: mpu_driver.h:69
MPU detail error access info Implements : mpu_access_err_info_t_Class.
Definition: mpu_driver.h:66
mpu_access_rights_t accessRight
Definition: mpu_driver.h:179
status_t MPU_DRV_SetRegionConfig(uint32_t instance, uint8_t regionNum, const mpu_user_config_t *userConfigPtr)
Sets the region configuration.
Definition: mpu_driver.c:162
void MPU_DRV_EnableRegion(uint32_t instance, uint8_t regionNum, bool enable)
Enables/Disables region descriptor. Please note that region 0 should not be disabled.
Definition: mpu_driver.c:322
void MPU_DRV_SetRegionAddr(uint32_t instance, uint8_t regionNum, uint32_t startAddr, uint32_t endAddr)
Sets the region start and end address.
Definition: mpu_driver.c:137