2 * -------------------------------------------
3 * MSP432 DriverLib - v01_04_00_18
4 * -------------------------------------------
6 * --COPYRIGHT--,BSD,BSD
7 * Copyright (c) 2015, Texas Instruments Incorporated
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <interrupt.h>
41 void MPU_enableModule(uint32_t mpuConfig)
44 // Check the arguments.
46 ASSERT(!(mpuConfig & ~(MPU_CONFIG_PRIV_DEFAULT | MPU_CONFIG_HARDFLT_NMI)));
49 // Set the MPU control bits according to the flags passed by the user,
50 // and also set the enable bit.
52 MPU->CTRL = mpuConfig | MPU_CTRL_ENABLE;
55 void MPU_disableModule(void)
58 // Turn off the MPU enable bit.
60 MPU->CTRL &= ~MPU_CTRL_ENABLE;
64 uint32_t MPU_getRegionCount(void)
67 // Read the DREGION field of the MPU type register and mask off
68 // the bits of interest to get the count of regions.
70 return ((MPU->TYPE & MPU_TYPE_DREGION_M) >> NVIC_MPU_TYPE_DREGION_S);
73 void MPU_enableRegion(uint32_t region)
76 // Check the arguments.
81 // Select the region to modify.
86 // Modify the enable bit in the region attributes.
88 MPU->RASR |= MPU_RASR_ENABLE;
91 void MPU_disableRegion(uint32_t region)
94 // Check the arguments.
99 // Select the region to modify.
104 // Modify the enable bit in the region attributes.
106 MPU->RASR &= ~MPU_RASR_ENABLE;
109 void MPU_setRegion(uint32_t region, uint32_t addr, uint32_t flags)
112 // Check the arguments.
117 // Program the base address, use the region field to select the
118 // region at the same time.
120 MPU->RBAR = addr | region | MPU_RBAR_VALID;
123 // Program the region attributes. Set the TEX field and the S, C,
124 // and B bits to fixed values that are suitable for all Stellaris
127 MPU->RASR = (flags & ~(MPU_RASR_TEX_M | MPU_RASR_C)) | MPU_RASR_S
131 void MPU_getRegion(uint32_t region, uint32_t *addr, uint32_t *pflags)
134 // Check the arguments.
141 // Select the region to get.
146 // Read and store the base address for the region.
148 *addr = MPU->RBAR & MPU_RBAR_ADDR_M;
151 // Read and store the region attributes.
156 void MPU_registerInterrupt(void (*intHandler)(void))
159 // Check the arguments.
164 // Register the interrupt handler.
166 Interrupt_registerInterrupt(FAULT_MPU, intHandler);
170 void MPU_unregisterInterrupt(void)
173 // Unregister the interrupt handler.
175 Interrupt_unregisterInterrupt(FAULT_MPU);
178 void MPU_enableInterrupt(void)
182 // Enable the memory management fault.
184 Interrupt_enableInterrupt(FAULT_MPU);
188 void MPU_disableInterrupt(void)
191 // Disable the interrupt.
193 Interrupt_disableInterrupt(FAULT_MPU);