2 * Copyright (c) 2014, Texas Instruments Incorporated
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
9 * * Redistributions of source code must retain the above copyright
\r
10 * notice, this list of conditions and the following disclaimer.
\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
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
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
32 //*****************************************************************************
\r
34 // mpu.h - Driver for the MPU Module.
\r
36 //*****************************************************************************
\r
38 #ifndef __MSP430WARE_MPU_H__
\r
39 #define __MSP430WARE_MPU_H__
\r
41 #include "inc/hw_memmap.h"
\r
43 #ifdef __MSP430_HAS_MPU__
\r
45 //*****************************************************************************
\r
47 // If building with a C++ compiler, make all of the definitions in this header
\r
48 // have a C binding.
\r
50 //*****************************************************************************
\r
56 #include "inc/hw_regaccess.h"
\r
57 //*****************************************************************************
\r
59 //! \brief Used in the MPU_initThreeSegments() function as the param parameter.
\r
61 //*****************************************************************************
\r
62 typedef struct MPU_initThreeSegmentsParam
\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
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
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
87 //! - \b MPU_NO_READ_WRITE_EXEC
\r
88 uint8_t seg3accmask;
\r
89 } MPU_initThreeSegmentsParam;
\r
91 //*****************************************************************************
\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
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
106 //*****************************************************************************
\r
108 // The following are values that can be passed to the segment parameter for
\r
109 // functions: MPU_enablePUCOnViolation(), and MPU_disablePUCOnViolation().
\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
117 //*****************************************************************************
\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
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
130 //*****************************************************************************
\r
132 // Prototypes for the APIs.
\r
134 //*****************************************************************************
\r
136 //*****************************************************************************
\r
138 //! \brief Initializes MPU with two memory segments
\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
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
162 //! Modified bits of \b MPUSAM register, bits of \b MPUSEG register and bits of
\r
163 //! \b MPUCTL0 register.
\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
173 //*****************************************************************************
\r
175 //! \brief Initializes MPU with three memory segments
\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
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
187 //! Modified bits of \b MPUSAM register, bits of \b MPUSEG register and bits of
\r
188 //! \b MPUCTL0 register.
\r
192 //*****************************************************************************
\r
193 extern void MPU_initThreeSegments(uint16_t baseAddress,
\r
194 MPU_initThreeSegmentsParam *param);
\r
196 //*****************************************************************************
\r
198 //! \brief Initializes user information memory segment
\r
200 //! This function initializes user information memory segment with specified
\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
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
212 //! Modified bits of \b MPUSAM register and bits of \b MPUCTL0 register.
\r
216 //*****************************************************************************
\r
217 extern void MPU_initInfoSegment(uint16_t baseAddress,
\r
220 //*****************************************************************************
\r
222 //! \brief The following function enables the NMI Event if a Segment violation
\r
225 //! \param baseAddress is the base address of the MPU module.
\r
227 //! Modified bits of \b MPUCTL0 register.
\r
231 //*****************************************************************************
\r
232 extern void MPU_enableNMIevent(uint16_t baseAddress);
\r
234 //*****************************************************************************
\r
236 //! \brief The following function enables the MPU module in the device.
\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
241 //! \param baseAddress is the base address of the MPU module.
\r
243 //! Modified bits of \b MPUCTL0 register.
\r
247 //*****************************************************************************
\r
248 extern void MPU_start(uint16_t baseAddress);
\r
250 //*****************************************************************************
\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
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
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
270 //! Modified bits of \b MPUSAM register and bits of \b MPUCTL0 register.
\r
274 //*****************************************************************************
\r
275 extern void MPU_enablePUCOnViolation(uint16_t baseAddress,
\r
278 //*****************************************************************************
\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
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
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
298 //! Modified bits of \b MPUSAM register and bits of \b MPUCTL0 register.
\r
302 //*****************************************************************************
\r
303 extern void MPU_disablePUCOnViolation(uint16_t baseAddress,
\r
306 //*****************************************************************************
\r
308 //! \brief Returns the memory segment violation flag status requested by the
\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
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
334 //*****************************************************************************
\r
335 extern uint16_t MPU_getInterruptStatus(uint16_t baseAddress,
\r
336 uint16_t memAccFlag);
\r
338 //*****************************************************************************
\r
340 //! \brief Clears the masked interrupt flags
\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
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
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
369 //*****************************************************************************
\r
370 extern uint16_t MPU_clearInterrupt(uint16_t baseAddress,
\r
371 uint16_t memAccFlag);
\r
373 //*****************************************************************************
\r
375 //! \brief Clears all Memory Segment Access Violation Interrupt Flags.
\r
377 //! \param baseAddress is the base address of the MPU module.
\r
379 //! Modified bits of \b MPUCTL1 register.
\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
392 //*****************************************************************************
\r
393 extern uint16_t MPU_clearAllInterrupts(uint16_t baseAddress);
\r
395 //*****************************************************************************
\r
397 //! \brief Lock MPU to protect from write access.
\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
404 //! \param baseAddress is the base address of the MPU module.
\r
406 //! Modified bits are \b MPULOCK of \b MPUCTL1 register.
\r
410 //*****************************************************************************
\r
411 extern void MPU_lockMPU(uint16_t baseAddress);
\r
413 //*****************************************************************************
\r
415 // Mark the end of the C bindings section for C++ compilers.
\r
417 //*****************************************************************************
\r
423 #endif // __MSP430WARE_MPU_H__
\r