]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/driverlib/mpu.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / driverlib / mpu.c
1 /*
2  * -------------------------------------------
3  *    MSP432 DriverLib - v01_04_00_18 
4  * -------------------------------------------
5  *
6  * --COPYRIGHT--,BSD,BSD
7  * Copyright (c) 2015, Texas Instruments Incorporated
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * *  Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  *
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.
20  *
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.
24  *
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.
36  * --/COPYRIGHT--*/
37 #include <debug.h>
38 #include <interrupt.h>
39 #include <mpu.h>
40
41 void MPU_enableModule(uint32_t mpuConfig)
42 {
43     //
44     // Check the arguments.
45     //
46     ASSERT(!(mpuConfig & ~(MPU_CONFIG_PRIV_DEFAULT | MPU_CONFIG_HARDFLT_NMI)));
47
48     //
49     // Set the MPU control bits according to the flags passed by the user,
50     // and also set the enable bit.
51     //
52     MPU->CTRL = mpuConfig | MPU_CTRL_ENABLE;
53 }
54
55 void MPU_disableModule(void)
56 {
57     //
58     // Turn off the MPU enable bit.
59     //
60     MPU->CTRL &= ~MPU_CTRL_ENABLE;
61
62 }
63
64 uint32_t MPU_getRegionCount(void)
65 {
66     //
67     // Read the DREGION field of the MPU type register and mask off
68     // the bits of interest to get the count of regions.
69     //
70     return ((MPU->TYPE & MPU_TYPE_DREGION_M) >> NVIC_MPU_TYPE_DREGION_S);
71 }
72
73 void MPU_enableRegion(uint32_t region)
74 {
75     //
76     // Check the arguments.
77     //
78     ASSERT(region < 8);
79
80     //
81     // Select the region to modify.
82     //
83     MPU->RNR = region;
84
85     //
86     // Modify the enable bit in the region attributes.
87     //
88     MPU->RASR |= MPU_RASR_ENABLE;
89 }
90
91 void MPU_disableRegion(uint32_t region)
92 {
93     //
94     // Check the arguments.
95     //
96     ASSERT(region < 8);
97
98     //
99     // Select the region to modify.
100     //
101     MPU->RNR = region;
102
103     //
104     // Modify the enable bit in the region attributes.
105     //
106     MPU->RASR &= ~MPU_RASR_ENABLE;
107 }
108
109 void MPU_setRegion(uint32_t region, uint32_t addr, uint32_t flags)
110 {
111     //
112     // Check the arguments.
113     //
114     ASSERT(region < 8);
115
116     //
117     // Program the base address, use the region field to select the
118     // region at the same time.
119     //
120     MPU->RBAR = addr | region | MPU_RBAR_VALID;
121
122     //
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
125     // memory.
126     //
127     MPU->RASR = (flags & ~(MPU_RASR_TEX_M | MPU_RASR_C)) | MPU_RASR_S
128             | MPU_RASR_B;
129 }
130
131 void MPU_getRegion(uint32_t region, uint32_t *addr, uint32_t *pflags)
132 {
133     //
134     // Check the arguments.
135     //
136     ASSERT(region < 8);
137     ASSERT(addr);
138     ASSERT(pflags);
139
140     //
141     // Select the region to get.
142     //
143     MPU->RNR = region;
144
145     //
146     // Read and store the base address for the region.
147     //
148     *addr = MPU->RBAR & MPU_RBAR_ADDR_M;
149
150     //
151     // Read and store the region attributes.
152     //
153     *pflags = MPU->RASR;
154 }
155
156 void MPU_registerInterrupt(void (*intHandler)(void))
157 {
158     //
159     // Check the arguments.
160     //
161     ASSERT(intHandler);
162
163     //
164     // Register the interrupt handler.
165     //
166     Interrupt_registerInterrupt(FAULT_MPU, intHandler);
167
168 }
169
170 void MPU_unregisterInterrupt(void)
171 {
172     //
173     // Unregister the interrupt handler.
174     //
175     Interrupt_unregisterInterrupt(FAULT_MPU);
176 }
177
178 void MPU_enableInterrupt(void)
179 {
180
181     //
182     // Enable the memory management fault.
183     //
184     Interrupt_enableInterrupt(FAULT_MPU);
185
186 }
187
188 void MPU_disableInterrupt(void)
189 {
190     //
191     // Disable the interrupt.
192     //
193     Interrupt_disableInterrupt(FAULT_MPU);
194 }