MSP430 DriverLib for MSP430FR57xx Devices  2.91.13.01
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 MPU module in the device.
192 //!
193 //! This function needs to be called once all memory segmentation has been
194 //! done. If this function is not called the MPU module will not be activated.
195 //!
196 //! \param baseAddress is the base address of the MPU module.
197 //!
198 //! Modified bits of \b MPUCTL0 register.
199 //!
200 //! \return None
201 //
202 //*****************************************************************************
203 extern void MPU_start(uint16_t baseAddress);
204 
205 //*****************************************************************************
206 //
207 //! \brief The following function enables PUC generation when an access
208 //! violation has occurred on the memory segment selected by the user.
209 //!
210 //! Note that only specified segments for PUC generation are enabled. Other
211 //! segments for PUC generation are left untouched. Users may call
212 //! MPU_enablePUCOnViolation() and MPU_disablePUCOnViolation() to assure that
213 //! all the bits will be set and/or cleared.
214 //!
215 //! \param baseAddress is the base address of the MPU module.
216 //! \param segment is the bit mask of memory segment that will generate a PUC
217 //! when an access violation occurs.
218 //! Mask value is the logical OR of any of the following:
219 //! - \b MPU_FIRST_SEG - PUC generation on first memory segment
220 //! - \b MPU_SECOND_SEG - PUC generation on second memory segment
221 //! - \b MPU_THIRD_SEG - PUC generation on third memory segment
222 //! - \b MPU_INFO_SEG - PUC generation on user information memory
223 //! segment
224 //!
225 //! Modified bits of \b MPUSAM register and bits of \b MPUCTL0 register.
226 //!
227 //! \return None
228 //
229 //*****************************************************************************
230 extern void MPU_enablePUCOnViolation(uint16_t baseAddress,
231  uint16_t segment);
232 
233 //*****************************************************************************
234 //
235 //! \brief The following function disables PUC generation when an access
236 //! violation has occurred on the memory segment selected by the user.
237 //!
238 //! Note that only specified segments for PUC generation are disabled. Other
239 //! segments for PUC generation are left untouched. Users may call
240 //! MPU_enablePUCOnViolation() and MPU_disablePUCOnViolation() to assure that
241 //! all the bits will be set and/or cleared.
242 //!
243 //! \param baseAddress is the base address of the MPU module.
244 //! \param segment is the bit mask of memory segment that will NOT generate a
245 //! PUC when an access violation occurs.
246 //! Mask value is the logical OR of any of the following:
247 //! - \b MPU_FIRST_SEG - PUC generation on first memory segment
248 //! - \b MPU_SECOND_SEG - PUC generation on second memory segment
249 //! - \b MPU_THIRD_SEG - PUC generation on third memory segment
250 //! - \b MPU_INFO_SEG - PUC generation on user information memory
251 //! segment
252 //!
253 //! Modified bits of \b MPUSAM register and bits of \b MPUCTL0 register.
254 //!
255 //! \return None
256 //
257 //*****************************************************************************
258 extern void MPU_disablePUCOnViolation(uint16_t baseAddress,
259  uint16_t segment);
260 
261 //*****************************************************************************
262 //
263 //! \brief Returns the memory segment violation flag status requested by the
264 //! user.
265 //!
266 //! \param baseAddress is the base address of the MPU module.
267 //! \param memAccFlag is the is the memory access violation flag.
268 //! Mask value is the logical OR of any of the following:
269 //! - \b MPU_SEG_1_ACCESS_VIOLATION - is set if an access violation in
270 //! Main Memory Segment 1 is detected
271 //! - \b MPU_SEG_2_ACCESS_VIOLATION - is set if an access violation in
272 //! Main Memory Segment 2 is detected
273 //! - \b MPU_SEG_3_ACCESS_VIOLATION - is set if an access violation in
274 //! Main Memory Segment 3 is detected
275 //! - \b MPU_SEG_INFO_ACCESS_VIOLATION - is set if an access violation
276 //! in User Information Memory Segment is detected
277 //!
278 //! \return Logical OR of any of the following:
279 //! - \b MPU_SEG_1_ACCESS_VIOLATION is set if an access violation in
280 //! Main Memory Segment 1 is detected
281 //! - \b MPU_SEG_2_ACCESS_VIOLATION is set if an access violation in
282 //! Main Memory Segment 2 is detected
283 //! - \b MPU_SEG_3_ACCESS_VIOLATION is set if an access violation in
284 //! Main Memory Segment 3 is detected
285 //! - \b MPU_SEG_INFO_ACCESS_VIOLATION is set if an access violation in
286 //! User Information Memory Segment is detected
287 //! \n indicating the status of the masked flags.
288 //
289 //*****************************************************************************
290 extern uint16_t MPU_getInterruptStatus(uint16_t baseAddress,
291  uint16_t memAccFlag);
292 
293 //*****************************************************************************
294 //
295 //! \brief Clears the masked interrupt flags
296 //!
297 //! Returns the memory segment violation flag status requested by the user or
298 //! if user is providing a bit mask value, the function will return a value
299 //! indicating if all flags were cleared.
300 //!
301 //! \param baseAddress is the base address of the MPU module.
302 //! \param memAccFlag is the is the memory access violation flag.
303 //! Mask value is the logical OR of any of the following:
304 //! - \b MPU_SEG_1_ACCESS_VIOLATION - is set if an access violation in
305 //! Main Memory Segment 1 is detected
306 //! - \b MPU_SEG_2_ACCESS_VIOLATION - is set if an access violation in
307 //! Main Memory Segment 2 is detected
308 //! - \b MPU_SEG_3_ACCESS_VIOLATION - is set if an access violation in
309 //! Main Memory Segment 3 is detected
310 //! - \b MPU_SEG_INFO_ACCESS_VIOLATION - is set if an access violation
311 //! in User Information Memory Segment is detected
312 //!
313 //! \return Logical OR of any of the following:
314 //! - \b MPU_SEG_1_ACCESS_VIOLATION is set if an access violation in
315 //! Main Memory Segment 1 is detected
316 //! - \b MPU_SEG_2_ACCESS_VIOLATION is set if an access violation in
317 //! Main Memory Segment 2 is detected
318 //! - \b MPU_SEG_3_ACCESS_VIOLATION is set if an access violation in
319 //! Main Memory Segment 3 is detected
320 //! - \b MPU_SEG_INFO_ACCESS_VIOLATION is set if an access violation in
321 //! User Information Memory Segment is detected
322 //! \n indicating the status of the masked flags.
323 //
324 //*****************************************************************************
325 extern uint16_t MPU_clearInterrupt(uint16_t baseAddress,
326  uint16_t memAccFlag);
327 
328 //*****************************************************************************
329 //
330 //! \brief Clears all Memory Segment Access Violation Interrupt Flags.
331 //!
332 //! \param baseAddress is the base address of the MPU module.
333 //!
334 //! Modified bits of \b MPUCTL1 register.
335 //!
336 //! \return Logical OR of any of the following:
337 //! - \b MPU_SEG_1_ACCESS_VIOLATION is set if an access violation in
338 //! Main Memory Segment 1 is detected
339 //! - \b MPU_SEG_2_ACCESS_VIOLATION is set if an access violation in
340 //! Main Memory Segment 2 is detected
341 //! - \b MPU_SEG_3_ACCESS_VIOLATION is set if an access violation in
342 //! Main Memory Segment 3 is detected
343 //! - \b MPU_SEG_INFO_ACCESS_VIOLATION is set if an access violation in
344 //! User Information Memory Segment is detected
345 //! \n indicating the status of the interrupt flags.
346 //
347 //*****************************************************************************
348 extern uint16_t MPU_clearAllInterrupts(uint16_t baseAddress);
349 
350 //*****************************************************************************
351 //
352 // Mark the end of the C bindings section for C++ compilers.
353 //
354 //*****************************************************************************
355 #ifdef __cplusplus
356 }
357 #endif
358 
359 #endif
360 #endif // __MSP430WARE_MPU_H__
uint16_t MPU_clearAllInterrupts(uint16_t baseAddress)
Clears all Memory Segment Access Violation Interrupt Flags.
Definition: mpu.c:267
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:235
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:224
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:253
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:216
void MPU_initThreeSegments(uint16_t baseAddress, MPU_initThreeSegmentsParam *param)
Initializes MPU with three memory segments.
Definition: mpu.c:99
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
uint16_t MPU_getInterruptStatus(uint16_t baseAddress, uint16_t memAccFlag)
Returns the memory segment violation flag status requested by the user.
Definition: mpu.c:246
void MPU_initInfoSegment(uint16_t baseAddress, uint8_t accmask)
Initializes user information memory segment.
Definition: mpu.c:184

Copyright 2020, Texas Instruments Incorporated