MSP430 DriverLib for MSP430FR5xx_6xx Devices  2.21.00.08
 All Data Structures Functions Variables Modules Pages
mpu.h
1 //*****************************************************************************
2 //
3 // mpu.h - Driver for the MPU Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_MPU_H__
8 #define __MSP430WARE_MPU_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_MPU__
13 
14 //*****************************************************************************
15 //
16 // If building with a C++ compiler, make all of the definitions in this header
17 // have a C binding.
18 //
19 //*****************************************************************************
20 #ifdef __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #include "inc/hw_memmap.h"
26 //*****************************************************************************
27 //
28 //! \brief Used in the MPU_initThreeSegments() function as the param parameter.
29 //
30 //*****************************************************************************
32  //! Valid values can be found in the Family User's Guide
33  uint16_t seg1boundary;
34  //! Valid values can be found in the Family User's Guide
35  uint16_t seg2boundary;
36  //! Is the bit mask of access right for memory segment 1.
37  //! \n Logical OR of any of the following:
38  //! - \b MPU_READ - Read rights
39  //! - \b MPU_WRITE - Write rights
40  //! - \b MPU_EXEC - Execute rights
41  //! - \b MPU_NO_READ_WRITE_EXEC - no read/write/execute rights
42  uint8_t seg1accmask;
43  //! Is the bit mask of access right for memory segment 2.
44  //! \n Logical OR of any of the following:
45  //! - \b MPU_READ - Read rights
46  //! - \b MPU_WRITE - Write rights
47  //! - \b MPU_EXEC - Execute rights
48  //! - \b MPU_NO_READ_WRITE_EXEC - no read/write/execute rights
49  uint8_t seg2accmask;
50  //! Is the bit mask of access right for memory segment 3.
51  //! \n Logical OR of any of the following:
52  //! - \b MPU_READ - Read rights
53  //! - \b MPU_WRITE - Write rights
54  //! - \b MPU_EXEC - Execute rights
55  //! - \b MPU_NO_READ_WRITE_EXEC - no read/write/execute rights
56  uint8_t seg3accmask;
58 
59 
60 //*****************************************************************************
61 //
62 // The following are values that can be passed to the accmask parameter for
63 // functions: MPU_initInfoSegment(); the seg2accmask parameter for functions:
64 // MPU_initTwoSegments(); the seg1accmask parameter for functions:
65 // MPU_initTwoSegments(); the param parameter for functions:
66 // MPU_initThreeSegments(), MPU_initThreeSegments(), and
67 // MPU_initThreeSegments().
68 //
69 //*****************************************************************************
70 #define MPU_READ MPUSEG1RE
71 #define MPU_WRITE MPUSEG1WE
72 #define MPU_EXEC MPUSEG1XE
73 #define MPU_NO_READ_WRITE_EXEC (0x0000)
74 
75 //*****************************************************************************
76 //
77 // The following are values that can be passed to the segment parameter for
78 // functions: MPU_enablePUCOnViolation(), and MPU_disablePUCOnViolation().
79 //
80 //*****************************************************************************
81 #define MPU_FIRST_SEG MPUSEG1VS
82 #define MPU_SECOND_SEG MPUSEG2VS
83 #define MPU_THIRD_SEG MPUSEG3VS
84 #define MPU_INFO_SEG MPUSEGIVS
85 
86 //*****************************************************************************
87 //
88 // The following are values that can be passed to the memAccFlag parameter for
89 // functions: MPU_getInterruptStatus(), and MPU_clearInterrupt() as well as
90 // returned by the MPU_getInterruptStatus() function, the
91 // MPU_clearAllInterrupts() function and the MPU_clearInterrupt() function.
92 //
93 //*****************************************************************************
94 #define MPU_SEG_1_ACCESS_VIOLATION MPUSEG1IFG
95 #define MPU_SEG_2_ACCESS_VIOLATION MPUSEG2IFG
96 #define MPU_SEG_3_ACCESS_VIOLATION MPUSEG3IFG
97 #define MPU_SEG_INFO_ACCESS_VIOLATION MPUSEGIIFG
98 
99 //*****************************************************************************
100 //
101 // Prototypes for the APIs.
102 //
103 //*****************************************************************************
104 
105 //*****************************************************************************
106 //
107 //! \brief Initializes MPU with two memory segments
108 //!
109 //! This function creates two memory segments in FRAM allowing the user to set
110 //! access right to each segment. To set the correct value for seg1boundary,
111 //! the user must consult the Device Family User's Guide and provide the MPUSBx
112 //! value corresponding to the memory address where the user wants to create
113 //! the partition. Consult the "Segment Border Setting" section in the User's
114 //! Guide to find the options available for MPUSBx.
115 //!
116 //! \param baseAddress is the base address of the MPU module.
117 //! \param seg1boundary Valid values can be found in the Family User's Guide
118 //! \param seg1accmask is the bit mask of access right for memory segment 1.
119 //! Mask value is the logical OR of any of the following:
120 //! - \b MPU_READ - Read rights
121 //! - \b MPU_WRITE - Write rights
122 //! - \b MPU_EXEC - Execute rights
123 //! - \b MPU_NO_READ_WRITE_EXEC - no read/write/execute rights
124 //! \param seg2accmask is the bit mask of access right for memory segment 2
125 //! Mask value is the logical OR of any of the following:
126 //! - \b MPU_READ - Read rights
127 //! - \b MPU_WRITE - Write rights
128 //! - \b MPU_EXEC - Execute rights
129 //! - \b MPU_NO_READ_WRITE_EXEC - no read/write/execute rights
130 //!
131 //! Modified bits of \b MPUSAM register, bits of \b MPUSEG register and bits of
132 //! \b MPUCTL0 register.
133 //!
134 //! \return None
135 //
136 //*****************************************************************************
137 extern void MPU_initTwoSegments(uint16_t baseAddress,
138  uint16_t seg1boundary,
139  uint8_t seg1accmask,
140  uint8_t seg2accmask);
141 
142 //*****************************************************************************
143 //
144 //! \brief Initializes MPU with three memory segments
145 //!
146 //! This function creates three memory segments in FRAM allowing the user to
147 //! set access right to each segment. To set the correct value for
148 //! seg1boundary, the user must consult the Device Family User's Guide and
149 //! provide the MPUSBx value corresponding to the memory address where the user
150 //! wants to create the partition. Consult the "Segment Border Setting" section
151 //! in the User's Guide to find the options available for MPUSBx.
152 //!
153 //! \param baseAddress is the base address of the MPU module.
154 //! \param param is the pointer to struct for initializing three segments.
155 //!
156 //! Modified bits of \b MPUSAM register, bits of \b MPUSEG register and bits of
157 //! \b MPUCTL0 register.
158 //!
159 //! \return None
160 //
161 //*****************************************************************************
162 extern void MPU_initThreeSegments(uint16_t baseAddress,
164 
165 //*****************************************************************************
166 //
167 //! \brief Initializes user information memory segment
168 //!
169 //! This function initializes user information memory segment with specified
170 //! access rights.
171 //!
172 //! \param baseAddress is the base address of the MPU module.
173 //! \param accmask is the bit mask of access right for user information memory
174 //! segment.
175 //! Mask value is the logical OR of any of the following:
176 //! - \b MPU_READ - Read rights
177 //! - \b MPU_WRITE - Write rights
178 //! - \b MPU_EXEC - Execute rights
179 //! - \b MPU_NO_READ_WRITE_EXEC - no read/write/execute rights
180 //!
181 //! Modified bits of \b MPUSAM register and bits of \b MPUCTL0 register.
182 //!
183 //! \return None
184 //
185 //*****************************************************************************
186 extern void MPU_initInfoSegment(uint16_t baseAddress,
187  uint8_t accmask);
188 
189 //*****************************************************************************
190 //
191 //! \brief The following function enables the NMI Event if a Segment violation
192 //! has occurred.
193 //!
194 //! \param baseAddress is the base address of the MPU module.
195 //!
196 //! Modified bits of \b MPUCTL0 register.
197 //!
198 //! \return None
199 //
200 //*****************************************************************************
201 extern void MPU_enableNMIevent(uint16_t baseAddress);
202 
203 //*****************************************************************************
204 //
205 //! \brief The following function enables the MPU module in the device.
206 //!
207 //! This function needs to be called once all memory segmentation has been
208 //! done. If this function is not called the MPU module will not be activated.
209 //!
210 //! \param baseAddress is the base address of the MPU module.
211 //!
212 //! Modified bits of \b MPUCTL0 register.
213 //!
214 //! \return None
215 //
216 //*****************************************************************************
217 extern void MPU_start(uint16_t baseAddress);
218 
219 //*****************************************************************************
220 //
221 //! \brief The following function enables PUC generation when an access
222 //! violation has occurred on the memory segment selected by the user.
223 //!
224 //! Note that only specified segments for PUC generation are enabled. Other
225 //! segments for PUC generation are left untouched. Users may call
226 //! MPU_enablePUCOnViolation() and MPU_disablePUCOnViolation() to assure that
227 //! all the bits will be set and/or cleared.
228 //!
229 //! \param baseAddress is the base address of the MPU module.
230 //! \param segment is the bit mask of memory segment that will generate a PUC
231 //! when an access violation occurs.
232 //! Mask value is the logical OR of any of the following:
233 //! - \b MPU_FIRST_SEG - PUC generation on first memory segment
234 //! - \b MPU_SECOND_SEG - PUC generation on second memory segment
235 //! - \b MPU_THIRD_SEG - PUC generation on third memory segment
236 //! - \b MPU_INFO_SEG - PUC generation on user information memory
237 //! segment
238 //!
239 //! Modified bits of \b MPUSAM register and bits of \b MPUCTL0 register.
240 //!
241 //! \return None
242 //
243 //*****************************************************************************
244 extern void MPU_enablePUCOnViolation(uint16_t baseAddress,
245  uint16_t segment);
246 
247 //*****************************************************************************
248 //
249 //! \brief The following function disables PUC generation when an access
250 //! violation has occurred on the memory segment selected by the user.
251 //!
252 //! Note that only specified segments for PUC generation are disabled. Other
253 //! segments for PUC generation are left untouched. Users may call
254 //! MPU_enablePUCOnViolation() and MPU_disablePUCOnViolation() to assure that
255 //! all the bits will be set and/or cleared.
256 //!
257 //! \param baseAddress is the base address of the MPU module.
258 //! \param segment is the bit mask of memory segment that will NOT generate a
259 //! PUC when an access violation occurs.
260 //! Mask value is the logical OR of any of the following:
261 //! - \b MPU_FIRST_SEG - PUC generation on first memory segment
262 //! - \b MPU_SECOND_SEG - PUC generation on second memory segment
263 //! - \b MPU_THIRD_SEG - PUC generation on third memory segment
264 //! - \b MPU_INFO_SEG - PUC generation on user information memory
265 //! segment
266 //!
267 //! Modified bits of \b MPUSAM register and bits of \b MPUCTL0 register.
268 //!
269 //! \return None
270 //
271 //*****************************************************************************
272 extern void MPU_disablePUCOnViolation(uint16_t baseAddress,
273  uint16_t segment);
274 
275 //*****************************************************************************
276 //
277 //! \brief Returns the memory segment violation flag status requested by the
278 //! user.
279 //!
280 //! \param baseAddress is the base address of the MPU module.
281 //! \param memAccFlag is the is the memory access violation flag.
282 //! Mask value is the logical OR of any of the following:
283 //! - \b MPU_SEG_1_ACCESS_VIOLATION - is set if an access violation in
284 //! Main Memory Segment 1 is detected
285 //! - \b MPU_SEG_2_ACCESS_VIOLATION - is set if an access violation in
286 //! Main Memory Segment 2 is detected
287 //! - \b MPU_SEG_3_ACCESS_VIOLATION - is set if an access violation in
288 //! Main Memory Segment 3 is detected
289 //! - \b MPU_SEG_INFO_ACCESS_VIOLATION - is set if an access violation
290 //! in User Information Memory Segment is detected
291 //!
292 //! \return Logical OR of any of the following:
293 //! - \b MPU_SEG_1_ACCESS_VIOLATION is set if an access violation in
294 //! Main Memory Segment 1 is detected
295 //! - \b MPU_SEG_2_ACCESS_VIOLATION is set if an access violation in
296 //! Main Memory Segment 2 is detected
297 //! - \b MPU_SEG_3_ACCESS_VIOLATION is set if an access violation in
298 //! Main Memory Segment 3 is detected
299 //! - \b MPU_SEG_INFO_ACCESS_VIOLATION is set if an access violation in
300 //! User Information Memory Segment is detected
301 //! \n indicating the status of the masked flags.
302 //
303 //*****************************************************************************
304 extern uint16_t MPU_getInterruptStatus(uint16_t baseAddress,
305  uint16_t memAccFlag);
306 
307 //*****************************************************************************
308 //
309 //! \brief Clears the masked interrupt flags
310 //!
311 //! Returns the memory segment violation flag status requested by the user or
312 //! if user is providing a bit mask value, the function will return a value
313 //! indicating if all flags were cleared.
314 //!
315 //! \param baseAddress is the base address of the MPU module.
316 //! \param memAccFlag is the is the memory access violation flag.
317 //! Mask value is the logical OR of any of the following:
318 //! - \b MPU_SEG_1_ACCESS_VIOLATION - is set if an access violation in
319 //! Main Memory Segment 1 is detected
320 //! - \b MPU_SEG_2_ACCESS_VIOLATION - is set if an access violation in
321 //! Main Memory Segment 2 is detected
322 //! - \b MPU_SEG_3_ACCESS_VIOLATION - is set if an access violation in
323 //! Main Memory Segment 3 is detected
324 //! - \b MPU_SEG_INFO_ACCESS_VIOLATION - is set if an access violation
325 //! in User Information Memory Segment is detected
326 //!
327 //! \return Logical OR of any of the following:
328 //! - \b MPU_SEG_1_ACCESS_VIOLATION is set if an access violation in
329 //! Main Memory Segment 1 is detected
330 //! - \b MPU_SEG_2_ACCESS_VIOLATION is set if an access violation in
331 //! Main Memory Segment 2 is detected
332 //! - \b MPU_SEG_3_ACCESS_VIOLATION is set if an access violation in
333 //! Main Memory Segment 3 is detected
334 //! - \b MPU_SEG_INFO_ACCESS_VIOLATION is set if an access violation in
335 //! User Information Memory Segment is detected
336 //! \n indicating the status of the masked flags.
337 //
338 //*****************************************************************************
339 extern uint16_t MPU_clearInterrupt(uint16_t baseAddress,
340  uint16_t memAccFlag);
341 
342 //*****************************************************************************
343 //
344 //! \brief Clears all Memory Segment Access Violation Interrupt Flags.
345 //!
346 //! \param baseAddress is the base address of the MPU module.
347 //!
348 //! Modified bits of \b MPUCTL1 register.
349 //!
350 //! \return Logical OR of any of the following:
351 //! - \b MPU_SEG_1_ACCESS_VIOLATION is set if an access violation in
352 //! Main Memory Segment 1 is detected
353 //! - \b MPU_SEG_2_ACCESS_VIOLATION is set if an access violation in
354 //! Main Memory Segment 2 is detected
355 //! - \b MPU_SEG_3_ACCESS_VIOLATION is set if an access violation in
356 //! Main Memory Segment 3 is detected
357 //! - \b MPU_SEG_INFO_ACCESS_VIOLATION is set if an access violation in
358 //! User Information Memory Segment is detected
359 //! \n indicating the status of the interrupt flags.
360 //
361 //*****************************************************************************
362 extern uint16_t MPU_clearAllInterrupts(uint16_t baseAddress);
363 
364 //*****************************************************************************
365 //
366 //! \brief Lock MPU to protect from write access.
367 //!
368 //! Sets MPULOCK to protect MPU from write access on all MPU registers except
369 //! MPUCTL1, MPUIPC0 and MPUIPSEGBx until a BOR occurs. MPULOCK bit cannot be
370 //! cleared manually. MPU_clearInterrupt() and MPU_clearAllInterrupts() still
371 //! can be used after this API is called.
372 //!
373 //! \param baseAddress is the base address of the MPU module.
374 //!
375 //! Modified bits are \b MPULOCK of \b MPUCTL1 register.
376 //!
377 //! \return None
378 //
379 //*****************************************************************************
380 extern void MPU_lockMPU(uint16_t baseAddress);
381 
382 //*****************************************************************************
383 //
384 // Mark the end of the C bindings section for C++ compilers.
385 //
386 //*****************************************************************************
387 #ifdef __cplusplus
388 }
389 #endif
390 
391 #endif
392 #endif // __MSP430WARE_MPU_H__
uint16_t MPU_clearAllInterrupts(uint16_t baseAddress)
Clears all Memory Segment Access Violation Interrupt Flags.
Definition: mpu.c:278
uint8_t seg2accmask
Definition: mpu.h:49
void MPU_disablePUCOnViolation(uint16_t baseAddress, uint16_t segment)
The following function disables PUC generation when an access violation has occurred on the memory se...
Definition: mpu.c:246
void MPU_enablePUCOnViolation(uint16_t baseAddress, uint16_t segment)
The following function enables PUC generation when an access violation has occurred on the memory seg...
Definition: mpu.c:235
uint8_t seg3accmask
Definition: mpu.h:56
uint16_t MPU_clearInterrupt(uint16_t baseAddress, uint16_t memAccFlag)
Clears the masked interrupt flags.
Definition: mpu.c:264
uint16_t seg2boundary
Valid values can be found in the Family User's Guide.
Definition: mpu.h:35
void MPU_initTwoSegments(uint16_t baseAddress, uint16_t seg1boundary, uint8_t seg1accmask, uint8_t seg2accmask)
Initializes MPU with two memory segments.
Definition: mpu.c:30
void MPU_start(uint16_t baseAddress)
The following function enables the MPU module in the device.
Definition: mpu.c:227
void MPU_enableNMIevent(uint16_t baseAddress)
The following function enables the NMI Event if a Segment violation has occurred. ...
Definition: mpu.c:218
void MPU_initThreeSegments(uint16_t baseAddress, MPU_initThreeSegmentsParam *param)
Initializes MPU with three memory segments.
Definition: mpu.c:100
Used in the MPU_initThreeSegments() function as the param parameter.
Definition: mpu.h:31
uint8_t seg1accmask
Definition: mpu.h:42
uint16_t seg1boundary
Valid values can be found in the Family User's Guide.
Definition: mpu.h:33
void MPU_lockMPU(uint16_t baseAddress)
Lock MPU to protect from write access.
Definition: mpu.c:291
uint16_t MPU_getInterruptStatus(uint16_t baseAddress, uint16_t memAccFlag)
Returns the memory segment violation flag status requested by the user.
Definition: mpu.c:257
void MPU_initInfoSegment(uint16_t baseAddress, uint8_t accmask)
Initializes user information memory segment.
Definition: mpu.c:186

Copyright 2015, Texas Instruments Incorporated