mpu.c
Go to the documentation of this file.
1 
33 /*
34  * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
35  */
36 
37 #include "mpu.h"
38 
78 /*----------------------------------------------------------------------------
79  * Exported functions
80 
81  *----------------------------------------------------------------------------*/
87 void mpu_enable(uint32_t dw_mpu_enable)
88 {
89  MPU->CTRL = dw_mpu_enable ;
90 }
91 
97 void mpu_set_region_num(uint32_t dw_region_num)
98 {
99  MPU->RNR = dw_region_num;
100 }
101 
106 {
107  MPU->RASR &= 0xfffffffe;
108 }
109 
116 void mpu_set_region(uint32_t dw_region_base_addr, uint32_t dw_region_attr)
117 {
118  MPU->RBAR = dw_region_base_addr;
119  MPU->RASR = dw_region_attr;
120 }
121 
122 
126 uint32_t mpu_cal_mpu_region_size(uint32_t dw_actual_size_in_bytes)
127 {
128  uint32_t dwRegionSize = 32;
129  uint32_t dwReturnValue = 4;
130 
131  while( dwReturnValue < 31 ) {
132  if( dw_actual_size_in_bytes <= dwRegionSize ) {
133  break;
134  } else {
135  dwReturnValue++;
136  }
137  dwRegionSize <<= 1;
138  }
139 
140  return ( dwReturnValue << 1 );
141 }
142 
143 
149 void mpu_update_regions(uint32_t dw_region_num, uint32_t dw_region_base_addr, uint32_t dw_region_attr)
150 {
151  volatile irqflags_t flags;
152 
153  /* Get and clear the global interrupt flags */
154  flags = cpu_irq_save();
155 
156  /* Clean up data and instruction buffer */
157  __DSB();
158  __ISB();
159 
160  /* Set active region */
161  mpu_set_region_num(dw_region_num);
162 
163  /* Disable region */
165 
166  /* Update region attribute */
167  mpu_set_region( dw_region_base_addr, dw_region_attr);
168 
169  /* Clean up data and instruction buffer to make the new region taking
170  effect at once */
171  __DSB();
172  __ISB();
173 
174  /* Restore global interrupt flags */
175  cpu_irq_restore(flags);
176 }
177 
void mpu_update_regions(uint32_t dw_region_num, uint32_t dw_region_base_addr, uint32_t dw_region_attr)
Update MPU regions.
Definition: mpu.c:149
SAMV70/SAMV71/SAME70/SAMS70-XULTRA board mpu config.
static irqflags_t cpu_irq_save(void)
Get and clear the global interrupt flags.
void mpu_disable_region(void)
Disable the current active region.
Definition: mpu.c:105
void mpu_set_region(uint32_t dw_region_base_addr, uint32_t dw_region_attr)
Setup a memory region.
Definition: mpu.c:116
static void cpu_irq_restore(irqflags_t flags)
Restore global interrupt flags.
uint32_t mpu_cal_mpu_region_size(uint32_t dw_actual_size_in_bytes)
Calculate region size for the RASR.
Definition: mpu.c:126
void mpu_enable(uint32_t dw_mpu_enable)
Enables the MPU module.
Definition: mpu.c:87
void mpu_set_region_num(uint32_t dw_region_num)
Set active memory region.
Definition: mpu.c:97
uint32_t irqflags_t
Type used for holding state of interrupt flag.


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:58