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 "mpu_hal.h"
28 
37 /*******************************************************************************
38  * Variables
39  ******************************************************************************/
41 extern MPU_Type * const g_mpuBase[MPU_INSTANCE_COUNT];
42 
43 /*******************************************************************************
44  * Definitions
45  *******************************************************************************/
46 #define MPU_USER_MASK (0x07U)
47 #define MPU_USER_SHIFT (0U)
48 #define MPU_SUPERVISOR_MASK (0x18U)
49 #define MPU_SUPERVISOR_SHIFT (3U)
50 #define MPU_W_MASK (0x20U)
51 #define MPU_W_SHIFT (5U)
52 #define MPU_R_MASK (0x40U)
53 #define MPU_R_SHIFT (6U)
54 
101 typedef enum
102 {
103  /* Format: M_R_W_SS_UUU
104  * M : 1 bit - Specify that access right is for masters which have separated
105  * privilege rights for user and supervisor mode accesses (e.g. master0~3)
106  * R : 1 bit - Read access permission
107  * W : 1 bit - Write access permission
108  * SS : 2 bits - Supervisor Mode Access Control
109  * UUU: 3 bits - User Mode Access Control
110  */
143  MPU_NONE = 0x80U,
144  MPU_W = 0xA0U,
145  MPU_R = 0xC0U,
146  MPU_RW = 0xE0U
148 
153 typedef struct
154 {
155  uint8_t masterNum;
157 #if FEATURE_MPU_HAS_PROCESS_IDENTIFIER
158  bool processIdentifierEnable;
159 #endif
161 
167 typedef struct
168 {
169  uint32_t startAddr;
170  uint32_t endAddr;
172 #if FEATURE_MPU_HAS_PROCESS_IDENTIFIER
173  uint8_t processIdentifier;
174  uint8_t processIdMask;
176 #endif /* FEATURE_MPU_HAS_PROCESS_IDENTIFIER */
178 
179 /*******************************************************************************
180  * API
181  *******************************************************************************/
186 #if defined(__cplusplus)
187 extern "C" {
188 #endif
189 
204 status_t MPU_DRV_Init(uint32_t instance,
205  uint8_t regionCnt,
206  const mpu_user_config_t *userConfigArr);
207 
213 void MPU_DRV_Deinit(uint32_t instance);
214 
223 void MPU_DRV_SetRegionAddr(uint32_t instance,
224  uint8_t regionNum,
225  uint32_t startAddr,
226  uint32_t endAddr);
227 
238 status_t MPU_DRV_SetRegionConfig(uint32_t instance,
239  uint8_t regionNum,
240  const mpu_user_config_t *userConfigPtr);
241 
252 status_t MPU_DRV_SetMasterAccessRights(uint32_t instance,
253  uint8_t regionNum,
254  const mpu_master_access_right_t *accessRightsPtr);
255 
263 void MPU_DRV_GetDetailErrorAccessInfo(uint32_t instance,
264  uint8_t slavePortNum,
265  mpu_access_err_info_t *errInfoPtr);
266 
269 #if defined(__cplusplus)
270 }
271 #endif
272 
275 #endif /* MPU_DRIVER_H */
276 /*******************************************************************************
277  * EOF
278  *******************************************************************************/
MPU master access rights. Implements : mpu_master_access_right_t_Class.
Definition: mpu_driver.h:153
const mpu_master_access_right_t * masterAccRight
Definition: mpu_driver.h:171
void MPU_DRV_Deinit(uint32_t instance)
De-initializes the MPU region by resetting and disabling MPU module.
Definition: mpu_driver.c:149
uint32_t startAddr
Definition: mpu_driver.h:169
void MPU_DRV_GetDetailErrorAccessInfo(uint32_t instance, uint8_t slavePortNum, mpu_access_err_info_t *errInfoPtr)
Gets the MPU access error detail information for a slave port.
Definition: mpu_driver.c:325
uint32_t endAddr
Definition: mpu_driver.h:170
MPU_Type *const g_mpuBase[MPU_INSTANCE_COUNT]
Table of base addresses for MPU instances.
Definition: mpu_driver.c:69
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:101
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:85
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:273
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:31
MPU user region configuration structure. This structure is used when calling the MPU_DRV_Init functio...
Definition: mpu_driver.h:167
MPU detail error access info Implements : mpu_access_err_info_t_Class.
Definition: mpu_hal.h:97
mpu_access_rights_t accessRight
Definition: mpu_driver.h:156
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:195
#define MPU_INSTANCE_COUNT
Definition: S32K144.h:7560
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:168