SmartSnippets DA1459x SDK
hw_mpu.h
Go to the documentation of this file.
1 
47 #ifndef HW_MPU_H_
48 #define HW_MPU_H_
49 
50 
51 #if dg_configUSE_HW_MPU
52 
53 #include <stdbool.h>
54 #include "sdk_defs.h"
55 
56 #define MPU_START_ADDRESS_MASK (~MPU_END_ADDRESS_MASK) /* Due to the 32-byte alignment of MPU-protected segments
57  * described in the ARM M33 documentation,
58  * all Start Addresses must be ANDed with this Mask */
59 
60 #define MPU_END_ADDRESS_MASK (0x1F) /* Due to the 32-byte alignment of MPU-protected segments
61  * and the MPU region size must be a multiple of 32 bytes
62  * described in the ARM M33 documentation,
63  * all End Addresses must be ORed with this Mask */
64 
73 typedef enum {
74  HW_MPU_REGION_NONE = MPU_REGION_NONE,
75  HW_MPU_REGION_0 = MPU_REGION_0,
76  HW_MPU_REGION_1 = MPU_REGION_1,
77  HW_MPU_REGION_2 = MPU_REGION_2,
78  HW_MPU_REGION_3 = MPU_REGION_3,
79  HW_MPU_REGION_4 = MPU_REGION_4,
80  HW_MPU_REGION_5 = MPU_REGION_5,
81  HW_MPU_REGION_6 = MPU_REGION_6,
82  HW_MPU_REGION_7 = MPU_REGION_7,
92 typedef enum {
93  HW_MPU_XN_FALSE = 0x00,
94  HW_MPU_XN_TRUE = 0x01,
95 } HW_MPU_XN;
96 
103 typedef enum {
106 } HW_MPU_APH_RO;
107 
115 typedef enum {
118 } HW_MPU_APL_NP;
119 
131 typedef enum {
136 } HW_MPU_AP;
137 
141 typedef enum {
151 
173 typedef enum {
174  HW_MPU_SH_NS = ARM_MPU_SH_NON,
175  HW_MPU_SH_OS = ARM_MPU_SH_OUTER,
176  HW_MPU_SH_IS = ARM_MPU_SH_INNER,
177 } HW_MPU_SH;
178 
189 typedef enum {
192 } HW_MPU_ATTR;
193 
197 typedef struct {
198  uint32_t start_addr;
199  uint32_t end_addr;
205 
216 __STATIC_FORCEINLINE void hw_mpu_hardfault_nmi_handlers_enable(bool hfnmiena)
217 {
218  REG_SETF(MPU, CTRL, HFNMIENA, hfnmiena);
219 }
220 
238 __STATIC_FORCEINLINE void hw_mpu_privileged_background_access_enable(bool privdefena)
239 {
240  REG_SETF(MPU, CTRL, PRIVDEFENA, privdefena);
241 }
242 
260 __STATIC_FORCEINLINE void hw_mpu_enable(bool privdefena)
261 {
262  uint32_t MPU_Control = (privdefena ? REG_MSK(MPU, CTRL, PRIVDEFENA) : 0);
263  ARM_MPU_Enable(MPU_Control);
264 }
265 
270 __STATIC_FORCEINLINE void hw_mpu_disable(void)
271 {
272  ARM_MPU_Disable();
273  __ISB();
274 }
275 
281 __STATIC_FORCEINLINE bool hw_mpu_is_enabled(void)
282 {
283  return (!!REG_GETF(MPU, CTRL, ENABLE));
284 }
285 
294 
299 
319 
327 
328 #endif /* dg_configUSE_HW_MPU */
329 
330 
331 #endif /* HW_MPU_H_ */
332 
mpu_region_config::attributes
HW_MPU_ATTR attributes
Definition: hw_mpu.h:203
HW_MPU_APL_NP_RW
Definition: hw_mpu.h:117
REG_SETF
#define REG_SETF(base, reg, field, new_val)
Set the value of a register field.
Definition: sdk_defs.h:738
HW_MPU_XN
HW_MPU_XN
Executable Region.
Definition: hw_mpu.h:92
mpu_region_config::execute_never
HW_MPU_XN execute_never
Definition: hw_mpu.h:202
mpu_region_config::access_permissions
HW_MPU_AP access_permissions
Definition: hw_mpu.h:200
HW_MPU_ATTR_INDEX_3
Definition: hw_mpu.h:145
HW_MPU_APL_NP
HW_MPU_APL_NP
Privileged or Non-Privileged access.
Definition: hw_mpu.h:115
HW_MPU_REGION_1
Definition: hw_mpu.h:76
HW_MPU_ATTR_INDEX_5
Definition: hw_mpu.h:147
hw_mpu_is_enabled
__STATIC_FORCEINLINE bool hw_mpu_is_enabled(void)
Checks if MPU is enabled.
Definition: hw_mpu.h:281
__ISB
__STATIC_FORCEINLINE void __ISB(void)
Instruction Synchronization Barrier.
Definition: cmsis_gcc.h:874
hw_mpu_disable
__STATIC_FORCEINLINE void hw_mpu_disable(void)
Disables the MPU.
Definition: hw_mpu.h:270
HW_MPU_AP_PRIVRW
Definition: hw_mpu.h:132
HW_MPU_REGION_0
Definition: hw_mpu.h:75
mpu_region_config::end_addr
uint32_t end_addr
Definition: hw_mpu.h:199
HW_MPU_SH
HW_MPU_SH
Shareability.
Definition: hw_mpu.h:173
HW_MPU_ATTR_INDEX_2
Definition: hw_mpu.h:144
HW_MPU_ATTR_INDEX
HW_MPU_ATTR_INDEX
Memory attributes.
Definition: hw_mpu.h:141
HW_MPU_REGION_2
Definition: hw_mpu.h:77
sdk_defs.h
Central include header file with platform definitions.
mpu_region_config
Memory Region Configuration.
Definition: hw_mpu.h:197
HW_MPU_SH_OS
Definition: hw_mpu.h:175
HW_MPU_ATTR_INDEX_6
Definition: hw_mpu.h:148
HW_MPU_REGION_4
Definition: hw_mpu.h:79
hw_mpu_reset_attribute_indirections
void hw_mpu_reset_attribute_indirections()
Resets all MPU attribute indirections. MPU Attribute Index pattern is returned to one-to-one configur...
hw_mpu_config_region
void hw_mpu_config_region(HW_MPU_REGION_NUM region_num, mpu_region_config *cfg)
Configures an MPU region. Region's start and end addresses will be aligned to 32 byte boundary....
HW_MPU_AP_RO
Definition: hw_mpu.h:135
mpu_region_config::shareability
HW_MPU_SH shareability
Definition: hw_mpu.h:201
hw_mpu_hardfault_nmi_handlers_enable
__STATIC_FORCEINLINE void hw_mpu_hardfault_nmi_handlers_enable(bool hfnmiena)
Enables/Disables the operation of MPU during hard fault, NMI, and FAULTMASK handlers.
Definition: hw_mpu.h:216
HW_MPU_REGION_NONE
Definition: hw_mpu.h:74
HW_MPU_ATTR_INDEX_0
Definition: hw_mpu.h:142
HW_MPU_APH_RO
HW_MPU_APH_RO
Region Read/Write or Read Only.
Definition: hw_mpu.h:103
REG_MSK
#define REG_MSK(base, reg, field)
Access register field mask.
Definition: sdk_defs.h:583
HW_MPU_AP_RW
Definition: hw_mpu.h:133
hw_mpu_privileged_background_access_enable
__STATIC_FORCEINLINE void hw_mpu_privileged_background_access_enable(bool privdefena)
Enables/Disables Privileged Background Access.
Definition: hw_mpu.h:238
HW_MPU_ATTR_DEVICE
Definition: hw_mpu.h:190
mpu_region_config::start_addr
uint32_t start_addr
Definition: hw_mpu.h:198
HW_MPU_APH_RO_RW
Definition: hw_mpu.h:104
HW_MPU_ATTR
HW_MPU_ATTR
Memory Type.
Definition: hw_mpu.h:189
HW_MPU_XN_FALSE
Definition: hw_mpu.h:93
HW_MPU_REGION_3
Definition: hw_mpu.h:78
HW_MPU_ATTR_INDEX_1
Definition: hw_mpu.h:143
hw_mpu_fetch_region_configuration
void hw_mpu_fetch_region_configuration(HW_MPU_REGION_NUM region_num, mpu_region_config *cfg)
Fetches the configuration of an MPU region.
HW_MPU_REGION_7
Definition: hw_mpu.h:82
REG_GETF
#define REG_GETF(base, reg, field)
Return the value of a register field.
Definition: sdk_defs.h:711
HW_MPU_ATTR_INDEX_7
Definition: hw_mpu.h:149
HW_MPU_SH_NS
Definition: hw_mpu.h:174
HW_MPU_APH_RO_RO
Definition: hw_mpu.h:105
HW_MPU_AP_PRIVRO
Definition: hw_mpu.h:134
HW_MPU_AP
HW_MPU_AP
Access Permissions.
Definition: hw_mpu.h:131
HW_MPU_APL_NP_PRIVRW
Definition: hw_mpu.h:116
HW_MPU_REGION_5
Definition: hw_mpu.h:80
hw_mpu_enable
__STATIC_FORCEINLINE void hw_mpu_enable(bool privdefena)
Initializes the MPU by disabling its operation during faults, defining the background region privileg...
Definition: hw_mpu.h:260
HW_MPU_REGION_NUM
HW_MPU_REGION_NUM
Region Definitions.
Definition: hw_mpu.h:73
HW_MPU_ATTR_NORMAL
Definition: hw_mpu.h:191
HW_MPU_REGION_6
Definition: hw_mpu.h:81
HW_MPU_SH_IS
Definition: hw_mpu.h:176
HW_MPU_XN_TRUE
Definition: hw_mpu.h:94
HW_MPU_ATTR_INDEX_4
Definition: hw_mpu.h:146
hw_mpu_set_attribute_indirection
void hw_mpu_set_attribute_indirection(HW_MPU_REGION_NUM region_num, HW_MPU_ATTR_INDEX attr)
Configures an MPU attribute indirection.