DIY Logging Volt/Ampmeter
mpu_armv8.h File Reference

Go to the source code of this file.

Data Structures

struct  ARM_MPU_Region_t
 

Macros

#define ARM_MPU_ARMV8_H
 
#define ARM_MPU_ATTR_DEVICE   ( 0U )
 Attribute for device memory (outer only) More...
 
#define ARM_MPU_ATTR_NON_CACHEABLE   ( 4U )
 Attribute for non-cacheable, normal memory. More...
 
#define ARM_MPU_ATTR_MEMORY_(NT, WB, RA, WA)   (((NT & 1U) << 3U) | ((WB & 1U) << 2U) | ((RA & 1U) << 1U) | (WA & 1U))
 Attribute for normal memory (outer and inner) More...
 
#define ARM_MPU_ATTR_DEVICE_nGnRnE   (0U)
 Device memory type non Gathering, non Re-ordering, non Early Write Acknowledgement. More...
 
#define ARM_MPU_ATTR_DEVICE_nGnRE   (1U)
 Device memory type non Gathering, non Re-ordering, Early Write Acknowledgement. More...
 
#define ARM_MPU_ATTR_DEVICE_nGRE   (2U)
 Device memory type non Gathering, Re-ordering, Early Write Acknowledgement. More...
 
#define ARM_MPU_ATTR_DEVICE_GRE   (3U)
 Device memory type Gathering, Re-ordering, Early Write Acknowledgement. More...
 
#define ARM_MPU_ATTR(O, I)   (((O & 0xFU) << 4U) | (((O & 0xFU) != 0U) ? (I & 0xFU) : ((I & 0x3U) << 2U)))
 Memory Attribute. More...
 
#define ARM_MPU_SH_NON   (0U)
 Normal memory non-shareable
More...
 
#define ARM_MPU_SH_OUTER   (2U)
 Normal memory outer shareable
More...
 
#define ARM_MPU_SH_INNER   (3U)
 Normal memory inner shareable
More...
 
#define ARM_MPU_AP_(RO, NP)   (((RO & 1U) << 1U) | (NP & 1U))
 Memory access permissions. More...
 
#define ARM_MPU_RBAR(BASE, SH, RO, NP, XN)
 Region Base Address Register value. More...
 
#define ARM_MPU_RLAR(LIMIT, IDX)
 Region Limit Address Register value. More...
 

Functions

__STATIC_INLINE void ARM_MPU_Enable (uint32_t MPU_Control)
 
__STATIC_INLINE void ARM_MPU_Disable (void)
 
__STATIC_INLINE void ARM_MPU_SetMemAttrEx (MPU_Type *mpu, uint8_t idx, uint8_t attr)
 
__STATIC_INLINE void ARM_MPU_SetMemAttr (uint8_t idx, uint8_t attr)
 
__STATIC_INLINE void ARM_MPU_ClrRegionEx (MPU_Type *mpu, uint32_t rnr)
 
__STATIC_INLINE void ARM_MPU_ClrRegion (uint32_t rnr)
 
__STATIC_INLINE void ARM_MPU_SetRegionEx (MPU_Type *mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar)
 
__STATIC_INLINE void ARM_MPU_SetRegion (uint32_t rnr, uint32_t rbar, uint32_t rlar)
 
__STATIC_INLINE void orderedCpy (volatile uint32_t *dst, const uint32_t *__RESTRICT src, uint32_t len)
 
__STATIC_INLINE void ARM_MPU_LoadEx (MPU_Type *mpu, uint32_t rnr, ARM_MPU_Region_t const *table, uint32_t cnt)
 
__STATIC_INLINE void ARM_MPU_Load (uint32_t rnr, ARM_MPU_Region_t const *table, uint32_t cnt)
 

Macro Definition Documentation

◆ ARM_MPU_AP_

#define ARM_MPU_AP_ (   RO,
  NP 
)    (((RO & 1U) << 1U) | (NP & 1U))

Memory access permissions.

Parameters
RORead-Only: Set to 1 for read-only memory.
NPNon-Privileged: Set to 1 for non-privileged memory.

Definition at line 80 of file mpu_armv8.h.

◆ ARM_MPU_ARMV8_H

#define ARM_MPU_ARMV8_H

Definition at line 32 of file mpu_armv8.h.

◆ ARM_MPU_ATTR

#define ARM_MPU_ATTR (   O,
 
)    (((O & 0xFU) << 4U) | (((O & 0xFU) != 0U) ? (I & 0xFU) : ((I & 0x3U) << 2U)))

Memory Attribute.

Parameters
OOuter memory attributes
IO == ARM_MPU_ATTR_DEVICE: Device memory attributes, else: Inner memory attributes

Definition at line 65 of file mpu_armv8.h.

◆ ARM_MPU_ATTR_DEVICE

#define ARM_MPU_ATTR_DEVICE   ( 0U )

Attribute for device memory (outer only)

Definition at line 35 of file mpu_armv8.h.

◆ ARM_MPU_ATTR_DEVICE_GRE

#define ARM_MPU_ATTR_DEVICE_GRE   (3U)

Device memory type Gathering, Re-ordering, Early Write Acknowledgement.

Definition at line 59 of file mpu_armv8.h.

◆ ARM_MPU_ATTR_DEVICE_nGnRE

#define ARM_MPU_ATTR_DEVICE_nGnRE   (1U)

Device memory type non Gathering, non Re-ordering, Early Write Acknowledgement.

Definition at line 53 of file mpu_armv8.h.

◆ ARM_MPU_ATTR_DEVICE_nGnRnE

#define ARM_MPU_ATTR_DEVICE_nGnRnE   (0U)

Device memory type non Gathering, non Re-ordering, non Early Write Acknowledgement.

Definition at line 50 of file mpu_armv8.h.

◆ ARM_MPU_ATTR_DEVICE_nGRE

#define ARM_MPU_ATTR_DEVICE_nGRE   (2U)

Device memory type non Gathering, Re-ordering, Early Write Acknowledgement.

Definition at line 56 of file mpu_armv8.h.

◆ ARM_MPU_ATTR_MEMORY_

#define ARM_MPU_ATTR_MEMORY_ (   NT,
  WB,
  RA,
  WA 
)    (((NT & 1U) << 3U) | ((WB & 1U) << 2U) | ((RA & 1U) << 1U) | (WA & 1U))

Attribute for normal memory (outer and inner)

Parameters
NTNon-Transient: Set to 1 for non-transient data.
WBWrite-Back: Set to 1 to use write-back update policy.
RARead Allocation: Set to 1 to use cache allocation on read miss.
WAWrite Allocation: Set to 1 to use cache allocation on write miss.

Definition at line 46 of file mpu_armv8.h.

◆ ARM_MPU_ATTR_NON_CACHEABLE

#define ARM_MPU_ATTR_NON_CACHEABLE   ( 4U )

Attribute for non-cacheable, normal memory.

Definition at line 38 of file mpu_armv8.h.

◆ ARM_MPU_RBAR

#define ARM_MPU_RBAR (   BASE,
  SH,
  RO,
  NP,
  XN 
)
Value:
((BASE & MPU_RBAR_BASE_Msk) | \
((SH << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk) | \
((ARM_MPU_AP_(RO, NP) << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk) | \
((XN << MPU_RBAR_XN_Pos) & MPU_RBAR_XN_Msk))

Region Base Address Register value.

Parameters
BASEThe base address bits [31:5] of a memory region. The value is zero extended. Effective address gets 32 byte aligned.
SHDefines the Shareability domain for this memory region.
RORead-Only: Set to 1 for a read-only memory region.
NPNon-Privileged: Set to 1 for a non-privileged memory region. \oaram XN eXecute Never: Set to 1 for a non-executable memory region.

Definition at line 89 of file mpu_armv8.h.

◆ ARM_MPU_RLAR

#define ARM_MPU_RLAR (   LIMIT,
  IDX 
)
Value:
((LIMIT & MPU_RLAR_LIMIT_Msk) | \
((IDX << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \
(MPU_RLAR_EN_Msk))

Region Limit Address Register value.

Parameters
LIMITThe limit address bits [31:5] for this memory region. The value is one extended.
IDXThe attribute index to be associated with this memory region.

Definition at line 99 of file mpu_armv8.h.

◆ ARM_MPU_SH_INNER

#define ARM_MPU_SH_INNER   (3U)

Normal memory inner shareable

Definition at line 74 of file mpu_armv8.h.

◆ ARM_MPU_SH_NON

#define ARM_MPU_SH_NON   (0U)

Normal memory non-shareable

Definition at line 68 of file mpu_armv8.h.

◆ ARM_MPU_SH_OUTER

#define ARM_MPU_SH_OUTER   (2U)

Normal memory outer shareable

Definition at line 71 of file mpu_armv8.h.

Function Documentation

◆ ARM_MPU_ClrRegion()

__STATIC_INLINE void ARM_MPU_ClrRegion ( uint32_t  rnr)

Clear and disable the given MPU region.

Parameters
rnrRegion number to be cleared.

Definition at line 215 of file mpu_armv8.h.

216 {
217  ARM_MPU_ClrRegionEx(MPU, rnr);
218 }

◆ ARM_MPU_ClrRegionEx()

__STATIC_INLINE void ARM_MPU_ClrRegionEx ( MPU_Type *  mpu,
uint32_t  rnr 
)

Clear and disable the given MPU region of the given MPU.

Parameters
mpuPointer to MPU to be used.
rnrRegion number to be cleared.

Definition at line 206 of file mpu_armv8.h.

207 {
208  mpu->RNR = rnr;
209  mpu->RLAR = 0U;
210 }

◆ ARM_MPU_Disable()

__STATIC_INLINE void ARM_MPU_Disable ( void  )

Disable the MPU.

Definition at line 127 of file mpu_armv8.h.

128 {
129  __DSB();
130  __ISB();
131 #ifdef SCB_SHCSR_MEMFAULTENA_Msk
132  SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
133 #endif
134  MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
135 }

◆ ARM_MPU_Enable()

__STATIC_INLINE void ARM_MPU_Enable ( uint32_t  MPU_Control)

Enable the MPU.

Parameters
MPU_ControlDefault access permissions for unconfigured regions.

Definition at line 115 of file mpu_armv8.h.

116 {
117  __DSB();
118  __ISB();
119  MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
120 #ifdef SCB_SHCSR_MEMFAULTENA_Msk
121  SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
122 #endif
123 }

◆ ARM_MPU_Load()

__STATIC_INLINE void ARM_MPU_Load ( uint32_t  rnr,
ARM_MPU_Region_t const *  table,
uint32_t  cnt 
)

Load the given number of MPU regions from a table.

Parameters
rnrFirst region number to be configured.
tablePointer to the MPU configuration table.
cntAmount of regions to be configured.

Definition at line 315 of file mpu_armv8.h.

316 {
317  ARM_MPU_LoadEx(MPU, rnr, table, cnt);
318 }

◆ ARM_MPU_LoadEx()

__STATIC_INLINE void ARM_MPU_LoadEx ( MPU_Type *  mpu,
uint32_t  rnr,
ARM_MPU_Region_t const *  table,
uint32_t  cnt 
)

Load the given number of MPU regions from a table to the given MPU.

Parameters
mpuPointer to the MPU registers to be used.
rnrFirst region number to be configured.
tablePointer to the MPU configuration table.
cntAmount of regions to be configured.

Definition at line 285 of file mpu_armv8.h.

286 {
287  const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U;
288  if (cnt == 1U) {
289  mpu->RNR = rnr;
290  orderedCpy(&(mpu->RBAR), &(table->RBAR), rowWordSize);
291  } else {
292  uint32_t rnrBase = rnr & ~(MPU_TYPE_RALIASES-1U);
293  uint32_t rnrOffset = rnr % MPU_TYPE_RALIASES;
294 
295  mpu->RNR = rnrBase;
296  while ((rnrOffset + cnt) > MPU_TYPE_RALIASES) {
297  uint32_t c = MPU_TYPE_RALIASES - rnrOffset;
298  orderedCpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), c*rowWordSize);
299  table += c;
300  cnt -= c;
301  rnrOffset = 0U;
302  rnrBase += MPU_TYPE_RALIASES;
303  mpu->RNR = rnrBase;
304  }
305 
306  orderedCpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), cnt*rowWordSize);
307  }
308 }

◆ ARM_MPU_SetMemAttr()

__STATIC_INLINE void ARM_MPU_SetMemAttr ( uint8_t  idx,
uint8_t  attr 
)

Set the memory attribute encoding.

Parameters
idxThe attribute index to be set [0-7]
attrThe attribute value to be set.

Definition at line 186 of file mpu_armv8.h.

187 {
188  ARM_MPU_SetMemAttrEx(MPU, idx, attr);
189 }

◆ ARM_MPU_SetMemAttrEx()

__STATIC_INLINE void ARM_MPU_SetMemAttrEx ( MPU_Type *  mpu,
uint8_t  idx,
uint8_t  attr 
)

Set the memory attribute encoding to the given MPU.

Parameters
mpuPointer to the MPU to be configured.
idxThe attribute index to be set [0-7]
attrThe attribute value to be set.

Definition at line 169 of file mpu_armv8.h.

170 {
171  const uint8_t reg = idx / 4U;
172  const uint32_t pos = ((idx % 4U) * 8U);
173  const uint32_t mask = 0xFFU << pos;
174 
175  if (reg >= (sizeof(mpu->MAIR) / sizeof(mpu->MAIR[0]))) {
176  return; // invalid index
177  }
178 
179  mpu->MAIR[reg] = ((mpu->MAIR[reg] & ~mask) | ((attr << pos) & mask));
180 }

◆ ARM_MPU_SetRegion()

__STATIC_INLINE void ARM_MPU_SetRegion ( uint32_t  rnr,
uint32_t  rbar,
uint32_t  rlar 
)

Configure the given MPU region.

Parameters
rnrRegion number to be configured.
rbarValue for RBAR register.
rlarValue for RLAR register.

Definition at line 248 of file mpu_armv8.h.

249 {
250  ARM_MPU_SetRegionEx(MPU, rnr, rbar, rlar);
251 }

◆ ARM_MPU_SetRegionEx()

__STATIC_INLINE void ARM_MPU_SetRegionEx ( MPU_Type *  mpu,
uint32_t  rnr,
uint32_t  rbar,
uint32_t  rlar 
)

Configure the given MPU region of the given MPU.

Parameters
mpuPointer to MPU to be used.
rnrRegion number to be configured.
rbarValue for RBAR register.
rlarValue for RLAR register.

Definition at line 236 of file mpu_armv8.h.

237 {
238  mpu->RNR = rnr;
239  mpu->RBAR = rbar;
240  mpu->RLAR = rlar;
241 }

◆ orderedCpy()

__STATIC_INLINE void orderedCpy ( volatile uint32_t *  dst,
const uint32_t *__RESTRICT  src,
uint32_t  len 
)

Memcopy with strictly ordered memory access, e.g. for register targets.

Parameters
dstDestination data is copied to.
srcSource data is copied from.
lenAmount of data words to be copied.

Definition at line 270 of file mpu_armv8.h.

271 {
272  uint32_t i;
273  for (i = 0U; i < len; ++i)
274  {
275  dst[i] = src[i];
276  }
277 }
SCB
#define SCB
Definition: core_armv8mbl.h:1122
ARM_MPU_AP_
#define ARM_MPU_AP_(RO, NP)
Memory access permissions.
Definition: mpu_armv8.h:80
ARM_MPU_ClrRegionEx
__STATIC_INLINE void ARM_MPU_ClrRegionEx(MPU_Type *mpu, uint32_t rnr)
Definition: mpu_armv8.h:206
__ISB
#define __ISB()
Instruction Synchronization Barrier.
Definition: cmsis_armcc.h:418
ARM_MPU_LoadEx
__STATIC_INLINE void ARM_MPU_LoadEx(MPU_Type *mpu, uint32_t rnr, ARM_MPU_Region_t const *table, uint32_t cnt)
Definition: mpu_armv8.h:285
SCB_SHCSR_MEMFAULTENA_Msk
#define SCB_SHCSR_MEMFAULTENA_Msk
Definition: core_armv8mml.h:694
ARM_MPU_SetMemAttrEx
__STATIC_INLINE void ARM_MPU_SetMemAttrEx(MPU_Type *mpu, uint8_t idx, uint8_t attr)
Definition: mpu_armv8.h:169
ARM_MPU_Region_t
Definition: mpu_armv7.h:180
__DSB
#define __DSB()
Data Synchronization Barrier.
Definition: cmsis_armcc.h:429
ARM_MPU_SetRegionEx
__STATIC_INLINE void ARM_MPU_SetRegionEx(MPU_Type *mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar)
Definition: mpu_armv8.h:236
orderedCpy
__STATIC_INLINE void orderedCpy(volatile uint32_t *dst, const uint32_t *__RESTRICT src, uint32_t len)
Definition: mpu_armv8.h:270