]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MSP430FR5969_LaunchPad/driverlib/MSP430FR5xx_6xx/mpu.h
Complete large memory model MSP430FR5969 demo - including CLI and run-time stats.
[freertos] / FreeRTOS / Demo / MSP430FR5969_LaunchPad / driverlib / MSP430FR5xx_6xx / mpu.h
1 /* --COPYRIGHT--,BSD\r
2  * Copyright (c) 2014, Texas Instruments Incorporated\r
3  * All rights reserved.\r
4  *\r
5  * Redistribution and use in source and binary forms, with or without\r
6  * modification, are permitted provided that the following conditions\r
7  * are met:\r
8  *\r
9  * *  Redistributions of source code must retain the above copyright\r
10  *    notice, this list of conditions and the following disclaimer.\r
11  *\r
12  * *  Redistributions in binary form must reproduce the above copyright\r
13  *    notice, this list of conditions and the following disclaimer in the\r
14  *    documentation and/or other materials provided with the distribution.\r
15  *\r
16  * *  Neither the name of Texas Instruments Incorporated nor the names of\r
17  *    its contributors may be used to endorse or promote products derived\r
18  *    from this software without specific prior written permission.\r
19  *\r
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\r
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,\r
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;\r
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\r
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
31  * --/COPYRIGHT--*/\r
32 //*****************************************************************************\r
33 //\r
34 // mpu.h - Driver for the MPU Module.\r
35 //\r
36 //*****************************************************************************\r
37 \r
38 #ifndef __MSP430WARE_MPU_H__\r
39 #define __MSP430WARE_MPU_H__\r
40 \r
41 #include "inc/hw_memmap.h"\r
42 \r
43 #ifdef __MSP430_HAS_MPU__\r
44 \r
45 //*****************************************************************************\r
46 //\r
47 // If building with a C++ compiler, make all of the definitions in this header\r
48 // have a C binding.\r
49 //\r
50 //*****************************************************************************\r
51 #ifdef __cplusplus\r
52 extern "C"\r
53 {\r
54 #endif\r
55 \r
56 #include "inc/hw_regaccess.h"\r
57 //*****************************************************************************\r
58 //\r
59 //! \brief Used in the MPU_initThreeSegments() function as the param parameter.\r
60 //\r
61 //*****************************************************************************\r
62 typedef struct MPU_initThreeSegmentsParam\r
63 {\r
64     //! Valid values can be found in the Family User's Guide\r
65     uint16_t seg1boundary;\r
66     //! Valid values can be found in the Family User's Guide\r
67     uint16_t seg2boundary;\r
68     //! Is the bit mask of access right for memory segment 1.\r
69     //! \n Logical OR of any of the following:\r
70     //! - \b MPU_READ\r
71     //! - \b MPU_WRITE\r
72     //! - \b MPU_EXEC\r
73     //! - \b MPU_NO_READ_WRITE_EXEC\r
74     uint8_t seg1accmask;\r
75     //! Is the bit mask of access right for memory segment 2.\r
76     //! \n Logical OR of any of the following:\r
77     //! - \b MPU_READ\r
78     //! - \b MPU_WRITE\r
79     //! - \b MPU_EXEC\r
80     //! - \b MPU_NO_READ_WRITE_EXEC\r
81     uint8_t seg2accmask;\r
82     //! Is the bit mask of access right for memory segment 3.\r
83     //! \n Logical OR of any of the following:\r
84     //! - \b MPU_READ\r
85     //! - \b MPU_WRITE\r
86     //! - \b MPU_EXEC\r
87     //! - \b MPU_NO_READ_WRITE_EXEC\r
88     uint8_t seg3accmask;\r
89 } MPU_initThreeSegmentsParam;\r
90 \r
91 //*****************************************************************************\r
92 //\r
93 // The following are values that can be passed to the accmask parameter for\r
94 // functions: MPU_initInfoSegment(); the seg2accmask parameter for functions:\r
95 // MPU_initTwoSegments(); the seg1accmask parameter for functions:\r
96 // MPU_initTwoSegments(); the param parameter for functions:\r
97 // MPU_initThreeSegments(), MPU_initThreeSegments(), and\r
98 // MPU_initThreeSegments().\r
99 //\r
100 //*****************************************************************************\r
101 #define MPU_READ                                                      MPUSEG1RE\r
102 #define MPU_WRITE                                                     MPUSEG1WE\r
103 #define MPU_EXEC                                                      MPUSEG1XE\r
104 #define MPU_NO_READ_WRITE_EXEC                                         (0x0000)\r
105 \r
106 //*****************************************************************************\r
107 //\r
108 // The following are values that can be passed to the segment parameter for\r
109 // functions: MPU_enablePUCOnViolation(), and MPU_disablePUCOnViolation().\r
110 //\r
111 //*****************************************************************************\r
112 #define MPU_FIRST_SEG                                                 MPUSEG1VS\r
113 #define MPU_SECOND_SEG                                                MPUSEG2VS\r
114 #define MPU_THIRD_SEG                                                 MPUSEG3VS\r
115 #define MPU_INFO_SEG                                                  MPUSEGIVS\r
116 \r
117 //*****************************************************************************\r
118 //\r
119 // The following are values that can be passed to the memAccFlag parameter for\r
120 // functions: MPU_getInterruptStatus(), and MPU_clearInterrupt() as well as\r
121 // returned by the MPU_getInterruptStatus() function, the\r
122 // MPU_clearAllInterrupts() function and the MPU_clearInterrupt() function.\r
123 //\r
124 //*****************************************************************************\r
125 #define MPU_SEG_1_ACCESS_VIOLATION                                   MPUSEG1IFG\r
126 #define MPU_SEG_2_ACCESS_VIOLATION                                   MPUSEG2IFG\r
127 #define MPU_SEG_3_ACCESS_VIOLATION                                   MPUSEG3IFG\r
128 #define MPU_SEG_INFO_ACCESS_VIOLATION                                MPUSEGIIFG\r
129 \r
130 //*****************************************************************************\r
131 //\r
132 // Prototypes for the APIs.\r
133 //\r
134 //*****************************************************************************\r
135 \r
136 //*****************************************************************************\r
137 //\r
138 //! \brief Initializes MPU with two memory segments\r
139 //!\r
140 //! This function creates two memory segments in FRAM allowing the user to set\r
141 //! access right to each segment. To set the correct value for seg1boundary,\r
142 //! the user must consult the Device Family User's Guide and provide the MPUSBx\r
143 //! value corresponding to the memory address where the user wants to create\r
144 //! the partition. Consult the "Segment Border Setting" section in the User's\r
145 //! Guide to find the options available for MPUSBx.\r
146 //!\r
147 //! \param baseAddress is the base address of the MPU module.\r
148 //! \param seg1boundary Valid values can be found in the Family User's Guide\r
149 //! \param seg1accmask is the bit mask of access right for memory segment 1.\r
150 //!        Mask value is the logical OR of any of the following:\r
151 //!        - \b MPU_READ - Read rights\r
152 //!        - \b MPU_WRITE - Write rights\r
153 //!        - \b MPU_EXEC - Execute rights\r
154 //!        - \b MPU_NO_READ_WRITE_EXEC - no read/write/execute rights\r
155 //! \param seg2accmask is the bit mask of access right for memory segment 2\r
156 //!        Mask value is the logical OR of any of the following:\r
157 //!        - \b MPU_READ - Read rights\r
158 //!        - \b MPU_WRITE - Write rights\r
159 //!        - \b MPU_EXEC - Execute rights\r
160 //!        - \b MPU_NO_READ_WRITE_EXEC - no read/write/execute rights\r
161 //!\r
162 //! Modified bits of \b MPUSAM register, bits of \b MPUSEG register and bits of\r
163 //! \b MPUCTL0 register.\r
164 //!\r
165 //! \return None\r
166 //\r
167 //*****************************************************************************\r
168 extern void MPU_initTwoSegments(uint16_t baseAddress,\r
169                                 uint16_t seg1boundary,\r
170                                 uint8_t seg1accmask,\r
171                                 uint8_t seg2accmask);\r
172 \r
173 //*****************************************************************************\r
174 //\r
175 //! \brief Initializes MPU with three memory segments\r
176 //!\r
177 //! This function creates three memory segments in FRAM allowing the user to\r
178 //! set access right to each segment. To set the correct value for\r
179 //! seg1boundary, the user must consult the Device Family User's Guide and\r
180 //! provide the MPUSBx value corresponding to the memory address where the user\r
181 //! wants to create the partition. Consult the "Segment Border Setting" section\r
182 //! in the User's Guide to find the options available for MPUSBx.\r
183 //!\r
184 //! \param baseAddress is the base address of the MPU module.\r
185 //! \param param is the pointer to struct for initializing three segments.\r
186 //!\r
187 //! Modified bits of \b MPUSAM register, bits of \b MPUSEG register and bits of\r
188 //! \b MPUCTL0 register.\r
189 //!\r
190 //! \return None\r
191 //\r
192 //*****************************************************************************\r
193 extern void MPU_initThreeSegments(uint16_t baseAddress,\r
194                                   MPU_initThreeSegmentsParam *param);\r
195 \r
196 //*****************************************************************************\r
197 //\r
198 //! \brief Initializes user information memory segment\r
199 //!\r
200 //! This function initializes user information memory segment with specified\r
201 //! access rights.\r
202 //!\r
203 //! \param baseAddress is the base address of the MPU module.\r
204 //! \param accmask is the bit mask of access right for user information memory\r
205 //!        segment.\r
206 //!        Mask value is the logical OR of any of the following:\r
207 //!        - \b MPU_READ - Read rights\r
208 //!        - \b MPU_WRITE - Write rights\r
209 //!        - \b MPU_EXEC - Execute rights\r
210 //!        - \b MPU_NO_READ_WRITE_EXEC - no read/write/execute rights\r
211 //!\r
212 //! Modified bits of \b MPUSAM register and bits of \b MPUCTL0 register.\r
213 //!\r
214 //! \return None\r
215 //\r
216 //*****************************************************************************\r
217 extern void MPU_initInfoSegment(uint16_t baseAddress,\r
218                                 uint8_t accmask);\r
219 \r
220 //*****************************************************************************\r
221 //\r
222 //! \brief The following function enables the NMI Event if a Segment violation\r
223 //! has occurred.\r
224 //!\r
225 //! \param baseAddress is the base address of the MPU module.\r
226 //!\r
227 //! Modified bits of \b MPUCTL0 register.\r
228 //!\r
229 //! \return None\r
230 //\r
231 //*****************************************************************************\r
232 extern void MPU_enableNMIevent(uint16_t baseAddress);\r
233 \r
234 //*****************************************************************************\r
235 //\r
236 //! \brief The following function enables the MPU module in the device.\r
237 //!\r
238 //! This function needs to be called once all memory segmentation has been\r
239 //! done. If this function is not called the MPU module will not be activated.\r
240 //!\r
241 //! \param baseAddress is the base address of the MPU module.\r
242 //!\r
243 //! Modified bits of \b MPUCTL0 register.\r
244 //!\r
245 //! \return None\r
246 //\r
247 //*****************************************************************************\r
248 extern void MPU_start(uint16_t baseAddress);\r
249 \r
250 //*****************************************************************************\r
251 //\r
252 //! \brief The following function enables PUC generation when an access\r
253 //! violation has occurred on the memory segment selected by the user.\r
254 //!\r
255 //! Note that only specified segments for PUC generation are enabled. Other\r
256 //! segments for PUC generation are left untouched. Users may call\r
257 //! MPU_enablePUCOnViolation() and MPU_disablePUCOnViolation() to assure that\r
258 //! all the bits will be set and/or cleared.\r
259 //!\r
260 //! \param baseAddress is the base address of the MPU module.\r
261 //! \param segment is the bit mask of memory segment that will generate a PUC\r
262 //!        when an access violation occurs.\r
263 //!        Mask value is the logical OR of any of the following:\r
264 //!        - \b MPU_FIRST_SEG - PUC generation on first memory segment\r
265 //!        - \b MPU_SECOND_SEG - PUC generation on second memory segment\r
266 //!        - \b MPU_THIRD_SEG - PUC generation on third memory segment\r
267 //!        - \b MPU_INFO_SEG - PUC generation on user information memory\r
268 //!           segment\r
269 //!\r
270 //! Modified bits of \b MPUSAM register and bits of \b MPUCTL0 register.\r
271 //!\r
272 //! \return None\r
273 //\r
274 //*****************************************************************************\r
275 extern void MPU_enablePUCOnViolation(uint16_t baseAddress,\r
276                                      uint16_t segment);\r
277 \r
278 //*****************************************************************************\r
279 //\r
280 //! \brief The following function disables PUC generation when an access\r
281 //! violation has occurred on the memory segment selected by the user.\r
282 //!\r
283 //! Note that only specified segments for PUC generation are disabled. Other\r
284 //! segments for PUC generation are left untouched. Users may call\r
285 //! MPU_enablePUCOnViolation() and MPU_disablePUCOnViolation() to assure that\r
286 //! all the bits will be set and/or cleared.\r
287 //!\r
288 //! \param baseAddress is the base address of the MPU module.\r
289 //! \param segment is the bit mask of memory segment that will NOT generate a\r
290 //!        PUC when an access violation occurs.\r
291 //!        Mask value is the logical OR of any of the following:\r
292 //!        - \b MPU_FIRST_SEG - PUC generation on first memory segment\r
293 //!        - \b MPU_SECOND_SEG - PUC generation on second memory segment\r
294 //!        - \b MPU_THIRD_SEG - PUC generation on third memory segment\r
295 //!        - \b MPU_INFO_SEG - PUC generation on user information memory\r
296 //!           segment\r
297 //!\r
298 //! Modified bits of \b MPUSAM register and bits of \b MPUCTL0 register.\r
299 //!\r
300 //! \return None\r
301 //\r
302 //*****************************************************************************\r
303 extern void MPU_disablePUCOnViolation(uint16_t baseAddress,\r
304                                       uint16_t segment);\r
305 \r
306 //*****************************************************************************\r
307 //\r
308 //! \brief Returns the memory segment violation flag status requested by the\r
309 //! user.\r
310 //!\r
311 //! \param baseAddress is the base address of the MPU module.\r
312 //! \param memAccFlag is the is the memory access violation flag.\r
313 //!        Mask value is the logical OR of any of the following:\r
314 //!        - \b MPU_SEG_1_ACCESS_VIOLATION - is set if an access violation in\r
315 //!           Main Memory Segment 1 is detected\r
316 //!        - \b MPU_SEG_2_ACCESS_VIOLATION - is set if an access violation in\r
317 //!           Main Memory Segment 2 is detected\r
318 //!        - \b MPU_SEG_3_ACCESS_VIOLATION - is set if an access violation in\r
319 //!           Main Memory Segment 3 is detected\r
320 //!        - \b MPU_SEG_INFO_ACCESS_VIOLATION - is set if an access violation\r
321 //!           in User Information Memory Segment is detected\r
322 //!\r
323 //! \return Logical OR of any of the following:\r
324 //!         - \b MPU_SEG_1_ACCESS_VIOLATION is set if an access violation in\r
325 //!         Main Memory Segment 1 is detected\r
326 //!         - \b MPU_SEG_2_ACCESS_VIOLATION is set if an access violation in\r
327 //!         Main Memory Segment 2 is detected\r
328 //!         - \b MPU_SEG_3_ACCESS_VIOLATION is set if an access violation in\r
329 //!         Main Memory Segment 3 is detected\r
330 //!         - \b MPU_SEG_INFO_ACCESS_VIOLATION is set if an access violation in\r
331 //!         User Information Memory Segment is detected\r
332 //!         \n indicating the status of the masked flags.\r
333 //\r
334 //*****************************************************************************\r
335 extern uint16_t MPU_getInterruptStatus(uint16_t baseAddress,\r
336                                        uint16_t memAccFlag);\r
337 \r
338 //*****************************************************************************\r
339 //\r
340 //! \brief Clears the masked interrupt flags\r
341 //!\r
342 //! Returns the memory segment violation flag status requested by the user or\r
343 //! if user is providing a bit mask value, the function will return a value\r
344 //! indicating if all flags were cleared.\r
345 //!\r
346 //! \param baseAddress is the base address of the MPU module.\r
347 //! \param memAccFlag is the is the memory access violation flag.\r
348 //!        Mask value is the logical OR of any of the following:\r
349 //!        - \b MPU_SEG_1_ACCESS_VIOLATION - is set if an access violation in\r
350 //!           Main Memory Segment 1 is detected\r
351 //!        - \b MPU_SEG_2_ACCESS_VIOLATION - is set if an access violation in\r
352 //!           Main Memory Segment 2 is detected\r
353 //!        - \b MPU_SEG_3_ACCESS_VIOLATION - is set if an access violation in\r
354 //!           Main Memory Segment 3 is detected\r
355 //!        - \b MPU_SEG_INFO_ACCESS_VIOLATION - is set if an access violation\r
356 //!           in User Information Memory Segment is detected\r
357 //!\r
358 //! \return Logical OR of any of the following:\r
359 //!         - \b MPU_SEG_1_ACCESS_VIOLATION is set if an access violation in\r
360 //!         Main Memory Segment 1 is detected\r
361 //!         - \b MPU_SEG_2_ACCESS_VIOLATION is set if an access violation in\r
362 //!         Main Memory Segment 2 is detected\r
363 //!         - \b MPU_SEG_3_ACCESS_VIOLATION is set if an access violation in\r
364 //!         Main Memory Segment 3 is detected\r
365 //!         - \b MPU_SEG_INFO_ACCESS_VIOLATION is set if an access violation in\r
366 //!         User Information Memory Segment is detected\r
367 //!         \n indicating the status of the masked flags.\r
368 //\r
369 //*****************************************************************************\r
370 extern uint16_t MPU_clearInterrupt(uint16_t baseAddress,\r
371                                    uint16_t memAccFlag);\r
372 \r
373 //*****************************************************************************\r
374 //\r
375 //! \brief Clears all Memory Segment Access Violation Interrupt Flags.\r
376 //!\r
377 //! \param baseAddress is the base address of the MPU module.\r
378 //!\r
379 //! Modified bits of \b MPUCTL1 register.\r
380 //!\r
381 //! \return Logical OR of any of the following:\r
382 //!         - \b MPU_SEG_1_ACCESS_VIOLATION is set if an access violation in\r
383 //!         Main Memory Segment 1 is detected\r
384 //!         - \b MPU_SEG_2_ACCESS_VIOLATION is set if an access violation in\r
385 //!         Main Memory Segment 2 is detected\r
386 //!         - \b MPU_SEG_3_ACCESS_VIOLATION is set if an access violation in\r
387 //!         Main Memory Segment 3 is detected\r
388 //!         - \b MPU_SEG_INFO_ACCESS_VIOLATION is set if an access violation in\r
389 //!         User Information Memory Segment is detected\r
390 //!         \n indicating the status of the interrupt flags.\r
391 //\r
392 //*****************************************************************************\r
393 extern uint16_t MPU_clearAllInterrupts(uint16_t baseAddress);\r
394 \r
395 //*****************************************************************************\r
396 //\r
397 //! \brief Lock MPU to protect from write access.\r
398 //!\r
399 //! Sets MPULOCK to protect MPU from write access on all MPU registers except\r
400 //! MPUCTL1, MPUIPC0 and MPUIPSEGBx until a BOR occurs. MPULOCK bit cannot be\r
401 //! cleared manually. MPU_clearInterrupt() and MPU_clearAllInterrupts() still\r
402 //! can be used after this API is called.\r
403 //!\r
404 //! \param baseAddress is the base address of the MPU module.\r
405 //!\r
406 //! Modified bits are \b MPULOCK of \b MPUCTL1 register.\r
407 //!\r
408 //! \return None\r
409 //\r
410 //*****************************************************************************\r
411 extern void MPU_lockMPU(uint16_t baseAddress);\r
412 \r
413 //*****************************************************************************\r
414 //\r
415 // Mark the end of the C bindings section for C++ compilers.\r
416 //\r
417 //*****************************************************************************\r
418 #ifdef __cplusplus\r
419 }\r
420 #endif\r
421 \r
422 #endif\r
423 #endif // __MSP430WARE_MPU_H__\r