MSP430 DriverLib for MSP430FR2xx_4xx Devices  2.10.00.09
 All Data Structures Functions Variables Modules Pages
cs.h
1 //*****************************************************************************
2 //
3 // cs.h - Driver for the CS Module.
4 //
5 //*****************************************************************************
6 
7 #ifndef __MSP430WARE_CS_H__
8 #define __MSP430WARE_CS_H__
9 
10 #include "inc/hw_memmap.h"
11 
12 #ifdef __MSP430_HAS_CS__
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 //*****************************************************************************
26 //
27 // The following are values that can be passed to the clockSourceDivider
28 // parameter for functions: CS_initClockSignal().
29 //
30 //*****************************************************************************
31 #define CS_CLOCK_DIVIDER_1 DIVM__1
32 #define CS_CLOCK_DIVIDER_2 DIVM__2
33 #define CS_CLOCK_DIVIDER_4 DIVM__4
34 #define CS_CLOCK_DIVIDER_8 DIVM__8
35 #define CS_CLOCK_DIVIDER_16 DIVM__16
36 #define CS_CLOCK_DIVIDER_32 DIVM__32
37 #define CS_CLOCK_DIVIDER_64 DIVM__64
38 #define CS_CLOCK_DIVIDER_128 DIVM__128
39 #define CS_CLOCK_DIVIDER_256 0x8
40 #define CS_CLOCK_DIVIDER_512 0x9
41 
42 //*****************************************************************************
43 //
44 // The following are values that can be passed to the selectClock parameter for
45 // functions: CS_enableClockRequest(), and CS_disableClockRequest(); the
46 // selectedClockSignal parameter for functions: CS_initClockSignal().
47 //
48 //*****************************************************************************
49 #define CS_ACLK 0x01
50 #define CS_MCLK 0x02
51 #define CS_SMCLK 0x04
52 
53 //*****************************************************************************
54 //
55 // The following are values that can be passed to the selectedClockSignal
56 // parameter for functions: CS_initClockSignal().
57 //
58 //*****************************************************************************
59 #define CS_FLLREF 0x08
60 
61 //*****************************************************************************
62 //
63 // The following are values that can be passed to the selectClock parameter for
64 // functions: CS_enableClockRequest(), and CS_disableClockRequest().
65 //
66 //*****************************************************************************
67 #define CS_MODOSC MODCLKREQEN
68 
69 //*****************************************************************************
70 //
71 // The following are values that can be passed to the clockSource parameter for
72 // functions: CS_initClockSignal().
73 //
74 //*****************************************************************************
75 #define CS_XT1CLK_SELECT SELMS__XT1CLK
76 #define CS_VLOCLK_SELECT SELMS__VLOCLK
77 #define CS_REFOCLK_SELECT SELMS__REFOCLK
78 #define CS_DCOCLKDIV_SELECT SELMS__DCOCLKDIV
79 
80 //*****************************************************************************
81 //
82 // The following are values that can be passed to the xt1drive parameter for
83 // functions: CS_turnOnXT1(), and CS_turnOnXT1WithTimeout().
84 //
85 //*****************************************************************************
86 #define CS_XT1_DRIVE_0 XT1DRIVE_0
87 #define CS_XT1_DRIVE_1 XT1DRIVE_1
88 #define CS_XT1_DRIVE_2 XT1DRIVE_2
89 #define CS_XT1_DRIVE_3 XT1DRIVE_3
90 
91 //*****************************************************************************
92 //
93 // The following are values that can be passed to the mask parameter for
94 // functions: CS_getFaultFlagStatus(), and CS_clearFaultFlag() as well as
95 // returned by the CS_clearAllOscFlagsWithTimeout() function.
96 //
97 //*****************************************************************************
98 #define CS_XT1OFFG XT1OFFG
99 #define CS_DCOFFG DCOFFG
100 #define CS_FLLULIFG FLLULIFG
101 
102 //*****************************************************************************
103 //
104 // Prototypes for the APIs.
105 //
106 //*****************************************************************************
107 
108 //*****************************************************************************
109 //
110 //! \brief Sets the external clock source
111 //!
112 //! This function sets the external clock sources XT1 crystal oscillator
113 //! frequency values. This function must be called if an external crystal XT1
114 //! is used and the user intends to call CS_getMCLK, CS_getSMCLK or CS_getACLK
115 //! APIs. If not, it is not necessary to invoke this API.
116 //!
117 //! \param XT1CLK_frequency is the XT1 crystal frequencies in Hz
118 //!
119 //! \return None
120 //
121 //*****************************************************************************
122 extern void CS_setExternalClockSource(uint32_t XT1CLK_frequency);
123 
124 //*****************************************************************************
125 //
126 //! \brief Initalizes a clock signal
127 //!
128 //! This function initializes each of the clock signals. The user must ensure
129 //! that this function is called for each clock signal. If not, the default
130 //! state is assumed for the particular clock signal. Refer MSP430Ware
131 //! documentation for CS module or Device Family User's Guide for details of
132 //! default clock signal states. Note that the dividers for \b CS_FLLREF are
133 //! different from the available clock dividers. Some devices do not support
134 //! dividers setting for \b CS_FLLREF, please refer to device specific
135 //! datasheet for details.
136 //!
137 //! \param selectedClockSignal selected clock signal
138 //! Valid values are:
139 //! - \b CS_ACLK
140 //! - \b CS_MCLK
141 //! - \b CS_SMCLK
142 //! - \b CS_FLLREF
143 //! \param clockSource is clock source for the selectedClockSignal
144 //! Valid values are:
145 //! - \b CS_XT1CLK_SELECT
146 //! - \b CS_VLOCLK_SELECT
147 //! - \b CS_REFOCLK_SELECT
148 //! - \b CS_DCOCLKDIV_SELECT
149 //! \param clockSourceDivider selected the clock divider to calculate
150 //! clocksignal from clock source.
151 //! Valid values are:
152 //! - \b CS_CLOCK_DIVIDER_1 [Default] - [Valid for CS_FLLREF, CS_MCLK,
153 //! CS_ACLK, CS_SMCLK]
154 //! - \b CS_CLOCK_DIVIDER_2 - [Valid for CS_MCLK, CS_SMCLK]
155 //! - \b CS_CLOCK_DIVIDER_4 - [Valid for CS_MCLK, CS_SMCLK]
156 //! - \b CS_CLOCK_DIVIDER_8 - [Valid for CS_MCLK, CS_SMCLK]
157 //! - \b CS_CLOCK_DIVIDER_16 - [Valid for CS_MCLK]
158 //! - \b CS_CLOCK_DIVIDER_32 - [Valid for CS_FLLREF, CS_MCLK]
159 //! - \b CS_CLOCK_DIVIDER_64 - [Valid for CS_FLLREF, CS_MCLK]
160 //! - \b CS_CLOCK_DIVIDER_128 - [Valid for CS_FLLREF, CS_MCLK]
161 //! - \b CS_CLOCK_DIVIDER_256 - [Valid for CS_FLLREF]
162 //! - \b CS_CLOCK_DIVIDER_512 - [Valid for CS_FLLREF]
163 //!
164 //! Modified bits of \b CSCTL3 register, bits of \b CSCTL5 register and bits of
165 //! \b CSCTL4 register.
166 //!
167 //! \return None
168 //
169 //*****************************************************************************
170 extern void CS_initClockSignal(uint8_t selectedClockSignal,
171  uint16_t clockSource,
172  uint16_t clockSourceDivider);
173 
174 //*****************************************************************************
175 //
176 //! \brief Intializes the XT1 crystal oscillator in low frequency mode
177 //!
178 //! Initializes the XT1 crystal oscillator in low frequency mode. Loops until
179 //! all oscillator fault flags are cleared, with no timeout. See the device-
180 //! specific data sheet for appropriate drive settings.
181 //!
182 //! \param xt1drive is the target drive strength for the XT1 crystal
183 //! oscillator.
184 //! Valid values are:
185 //! - \b CS_XT1_DRIVE_0
186 //! - \b CS_XT1_DRIVE_1
187 //! - \b CS_XT1_DRIVE_2
188 //! - \b CS_XT1_DRIVE_3 [Default]
189 //! \n Modified bits are \b XT1DRIVE of \b UCSCTL6 register.
190 //!
191 //! \return None
192 //
193 //*****************************************************************************
194 extern void CS_turnOnXT1(uint16_t xt1drive);
195 
196 //*****************************************************************************
197 //
198 //! \brief Bypass the XT1 crystal oscillator
199 //!
200 //! Bypasses the XT1 crystal oscillator. Loops until all oscillator fault flags
201 //! are cleared, with no timeout.
202 //!
203 //!
204 //! Modified bits of \b SFRIFG1 register, bits of \b CSCTL7 register and bits
205 //! of \b CSCTL6 register.
206 //!
207 //! \return None
208 //
209 //*****************************************************************************
210 extern void CS_bypassXT1(void);
211 
212 //*****************************************************************************
213 //
214 //! \brief Initializes the XT1 crystal oscillator in low frequency mode with
215 //! timeout
216 //!
217 //! Initializes the XT1 crystal oscillator in low frequency mode with timeout.
218 //! Loops until all oscillator fault flags are cleared or until a timeout
219 //! counter is decremented and equals to zero. See the device-specific
220 //! datasheet for appropriate drive settings.
221 //!
222 //! \param xt1drive is the target drive strength for the XT1 crystal
223 //! oscillator.
224 //! Valid values are:
225 //! - \b CS_XT1_DRIVE_0
226 //! - \b CS_XT1_DRIVE_1
227 //! - \b CS_XT1_DRIVE_2
228 //! - \b CS_XT1_DRIVE_3 [Default]
229 //! \param timeout is the count value that gets decremented every time the loop
230 //! that clears oscillator fault flags gets executed.
231 //!
232 //! Modified bits of \b SFRIFG1 register, bits of \b CSCTL7 register and bits
233 //! of \b CSCTL6 register.
234 //!
235 //! \return STATUS_SUCCESS or STATUS_FAIL
236 //
237 //*****************************************************************************
238 extern bool CS_turnOnXT1WithTimeout(uint16_t xt1drive,
239  uint16_t timeout);
240 
241 //*****************************************************************************
242 //
243 //! \brief Bypasses the XT1 crystal oscillator with time out
244 //!
245 //! Bypasses the XT1 crystal oscillator with time out. Loops until all
246 //! oscillator fault flags are cleared or until a timeout counter is
247 //! decremented and equals to zero.
248 //!
249 //! \param timeout is the count value that gets decremented every time the loop
250 //! that clears oscillator fault flags gets executed.
251 //!
252 //! Modified bits of \b SFRIFG1 register, bits of \b CSCTL7 register and bits
253 //! of \b CSCTL6 register.
254 //!
255 //! \return STATUS_SUCCESS or STATUS_FAIL
256 //
257 //*****************************************************************************
258 extern bool CS_bypassXT1WithTimeout(uint16_t timeout);
259 
260 //*****************************************************************************
261 //
262 //! \brief Stops the XT1 oscillator using the XT1AUTOOFF bit.
263 //!
264 //!
265 //! Modified bits are \b XT1AUTOOFF of \b CSCTL6 register.
266 //!
267 //! \return None
268 //
269 //*****************************************************************************
270 extern void CS_turnOffXT1(void);
271 
272 //*****************************************************************************
273 //
274 //! \brief Initializes the DCO to operate a frequency that is a multiple of the
275 //! reference frequency into the FLL
276 //!
277 //! Initializes the DCO to operate a frequency that is a multiple of the
278 //! reference frequency into the FLL. Loops until all oscillator fault flags
279 //! are cleared, with a timeout. If the frequency is greater than 16 MHz, the
280 //! function sets the MCLK and SMCLK source to the undivided DCO frequency.
281 //! Otherwise, the function sets the MCLK and SMCLK source to the DCOCLKDIV
282 //! frequency. This function executes a software delay that is proportional in
283 //! length to the ratio of the target FLL frequency and the FLL reference.
284 //!
285 //! \param fsystem is the target frequency for MCLK in kHz
286 //! \param ratio is the ratio x/y, where x = fsystem and y = FLL reference
287 //! frequency.
288 //!
289 //! Modified bits of \b CSCTL1 register, bits of \b CSCTL0 register, bits of \b
290 //! CSCTL2 register, bits of \b CSCTL4 register, bits of \b CSCTL7 register and
291 //! bits of \b SFRIFG1 register.
292 //!
293 //! \return None
294 //
295 //*****************************************************************************
296 extern void CS_initFLLSettle(uint16_t fsystem,
297  uint16_t ratio);
298 
299 //*****************************************************************************
300 //
301 //! \brief Initializes the DCO to operate a frequency that is a multiple of the
302 //! reference frequency into the FLL
303 //!
304 //! Initializes the DCO to operate a frequency that is a multiple of the
305 //! reference frequency into the FLL. Loops until all oscillator fault flags
306 //! are cleared, with no timeout. If the frequency is greater than 16 MHz, the
307 //! function sets the MCLK and SMCLK source to the undivided DCO frequency.
308 //! Otherwise, the function sets the MCLK and SMCLK source to the DCOCLKDIV
309 //! frequency.
310 //!
311 //! \param fsystem is the target frequency for MCLK in kHz
312 //! \param ratio is the ratio x/y, where x = fsystem and y = FLL reference
313 //! frequency.
314 //!
315 //! Modified bits of \b CSCTL1 register, bits of \b CSCTL0 register, bits of \b
316 //! CSCTL2 register, bits of \b CSCTL4 register, bits of \b CSCTL7 register and
317 //! bits of \b SFRIFG1 register.
318 //!
319 //! \return None
320 //
321 //*****************************************************************************
322 extern void CS_initFLL(uint16_t fsystem,
323  uint16_t ratio);
324 
325 //*****************************************************************************
326 //
327 //! \brief Enables conditional module requests
328 //!
329 //! \param selectClock selects specific request enables
330 //! Valid values are:
331 //! - \b CS_ACLK
332 //! - \b CS_MCLK
333 //! - \b CS_SMCLK
334 //! - \b CS_MODOSC
335 //!
336 //! Modified bits of \b CSCTL8 register.
337 //!
338 //! \return None
339 //
340 //*****************************************************************************
341 extern void CS_enableClockRequest(uint8_t selectClock);
342 
343 //*****************************************************************************
344 //
345 //! \brief Disables conditional module requests
346 //!
347 //! \param selectClock selects specific request disable
348 //! Valid values are:
349 //! - \b CS_ACLK
350 //! - \b CS_MCLK
351 //! - \b CS_SMCLK
352 //! - \b CS_MODOSC
353 //!
354 //! Modified bits of \b CSCTL8 register.
355 //!
356 //! \return None
357 //
358 //*****************************************************************************
359 extern void CS_disableClockRequest(uint8_t selectClock);
360 
361 //*****************************************************************************
362 //
363 //! \brief Gets the current CS fault flag status.
364 //!
365 //! \param mask is the masked interrupt flag status to be returned. Mask
366 //! parameter can be either any of the following selection.
367 //! Valid values are:
368 //! - \b CS_XT1OFFG - XT1 oscillator fault flag
369 //! - \b CS_DCOFFG - DCO fault flag
370 //! - \b CS_FLLULIFG - FLL unlock interrupt flag
371 //!
372 //! Modified bits of \b CSCTL7 register.
373 //!
374 //! \return The current flag status for the corresponding masked bit
375 //
376 //*****************************************************************************
377 extern uint8_t CS_getFaultFlagStatus(uint8_t mask);
378 
379 //*****************************************************************************
380 //
381 //! \brief Clears the current CS fault flag status for the masked bit.
382 //!
383 //! \param mask is the masked interrupt flag status to be returned. mask
384 //! parameter can be any one of the following
385 //! Valid values are:
386 //! - \b CS_XT1OFFG - XT1 oscillator fault flag
387 //! - \b CS_DCOFFG - DCO fault flag
388 //! - \b CS_FLLULIFG - FLL unlock interrupt flag
389 //!
390 //! Modified bits of \b CSCTL7 register.
391 //!
392 //! \return None
393 //
394 //*****************************************************************************
395 extern void CS_clearFaultFlag(uint8_t mask);
396 
397 //*****************************************************************************
398 //
399 //! \brief Get the current ACLK frequency
400 //!
401 //! Get the current ACLK frequency. The user of this API must ensure that
402 //! CS_setExternalClockSource API was invoked before in case XT1 is being used.
403 //!
404 //!
405 //! \return Current ACLK frequency in Hz
406 //
407 //*****************************************************************************
408 extern uint32_t CS_getACLK(void);
409 
410 //*****************************************************************************
411 //
412 //! \brief Get the current SMCLK frequency
413 //!
414 //! Get the current SMCLK frequency. The user of this API must ensure that
415 //! CS_setExternalClockSource API was invoked before in case XT1 is being used.
416 //!
417 //!
418 //! \return Current SMCLK frequency in Hz
419 //
420 //*****************************************************************************
421 extern uint32_t CS_getSMCLK(void);
422 
423 //*****************************************************************************
424 //
425 //! \brief Get the current MCLK frequency
426 //!
427 //! Get the current MCLK frequency. The user of this API must ensure that
428 //! CS_setExternalClockSource API was invoked before in case XT1 is being used.
429 //!
430 //!
431 //! \return Current MCLK frequency in Hz
432 //
433 //*****************************************************************************
434 extern uint32_t CS_getMCLK(void);
435 
436 //*****************************************************************************
437 //
438 //! \brief Clears all the Oscillator Flags
439 //!
440 //! \param timeout is the count value that gets decremented every time the loop
441 //! that clears oscillator fault flags gets executed.
442 //!
443 //! \return The mask of the oscillator flag status
444 //! Return Logical OR of any of the following:
445 //! - \b CS_XT1OFFG XT1 oscillator fault flag
446 //! - \b CS_DCOFFG DCO fault flag
447 //! - \b CS_FLLULIFG FLL unlock interrupt flag
448 //! \n indicating the status of the osciallator fault flags
449 //
450 //*****************************************************************************
451 extern uint16_t CS_clearAllOscFlagsWithTimeout(uint16_t timeout);
452 
453 //*****************************************************************************
454 //
455 //! \brief Enables XT1 automatic gain control
456 //!
457 //!
458 //! Modified bits of \b CSCTL6 register.
459 //!
460 //! \return None
461 //
462 //*****************************************************************************
463 extern void CS_enableXT1AutomaticGainControl(void);
464 
465 //*****************************************************************************
466 //
467 //! \brief Disables XT1 automatic gain control
468 //!
469 //!
470 //! Modified bits of \b CSCTL6 register.
471 //!
472 //! \return None
473 //
474 //*****************************************************************************
475 extern void CS_disableXT1AutomaticGainControl(void);
476 
477 //*****************************************************************************
478 //
479 //! \brief Enables FLL unlock interrupt.
480 //!
481 //!
482 //! Modified bits are \b FLLULIE of \b CSCTL7 register.
483 //!
484 //! \return None
485 //
486 //*****************************************************************************
487 extern void CS_enableFLLUnlock(void);
488 
489 //*****************************************************************************
490 //
491 //! \brief Disables FLL unlock interrupt.
492 //!
493 //!
494 //! Modified bits are \b FLLULIE of \b CSCTL7 register.
495 //!
496 //! \return None
497 //
498 //*****************************************************************************
499 extern void CS_disableFLLUnlock(void);
500 
501 //*****************************************************************************
502 //
503 // Mark the end of the C bindings section for C++ compilers.
504 //
505 //*****************************************************************************
506 #ifdef __cplusplus
507 }
508 #endif
509 
510 #endif
511 #endif // __MSP430WARE_CS_H__
void CS_disableFLLUnlock(void)
Disables FLL unlock interrupt.
Definition: cs.c:559
void CS_disableClockRequest(uint8_t selectClock)
Disables conditional module requests.
Definition: cs.c:462
uint32_t CS_getACLK(void)
Get the current ACLK frequency.
Definition: cs.c:480
bool CS_bypassXT1WithTimeout(uint16_t timeout)
Bypasses the XT1 crystal oscillator with time out.
Definition: cs.c:331
uint8_t CS_getFaultFlagStatus(uint8_t mask)
Gets the current CS fault flag status.
Definition: cs.c:468
void CS_setExternalClockSource(uint32_t XT1CLK_frequency)
Sets the external clock source.
Definition: cs.c:130
uint16_t CS_clearAllOscFlagsWithTimeout(uint16_t timeout)
Clears all the Oscillator Flags.
Definition: cs.c:530
void CS_enableFLLUnlock(void)
Enables FLL unlock interrupt.
Definition: cs.c:554
void CS_initClockSignal(uint8_t selectedClockSignal, uint16_t clockSource, uint16_t clockSourceDivider)
Initalizes a clock signal.
Definition: cs.c:136
void CS_initFLL(uint16_t fsystem, uint16_t ratio)
Initializes the DCO to operate a frequency that is a multiple of the reference frequency into the FLL...
Definition: cs.c:378
void CS_disableXT1AutomaticGainControl(void)
Disables XT1 automatic gain control.
Definition: cs.c:549
void CS_enableClockRequest(uint8_t selectClock)
Enables conditional module requests.
Definition: cs.c:456
void CS_initFLLSettle(uint16_t fsystem, uint16_t ratio)
Initializes the DCO to operate a frequency that is a multiple of the reference frequency into the FLL...
Definition: cs.c:364
void CS_turnOffXT1(void)
Stops the XT1 oscillator using the XT1AUTOOFF bit.
Definition: cs.c:358
uint32_t CS_getMCLK(void)
Get the current MCLK frequency.
Definition: cs.c:517
bool CS_turnOnXT1WithTimeout(uint16_t xt1drive, uint16_t timeout)
Initializes the XT1 crystal oscillator in low frequency mode with timeout.
Definition: cs.c:291
void CS_turnOnXT1(uint16_t xt1drive)
Intializes the XT1 crystal oscillator in low frequency mode.
Definition: cs.c:240
void CS_bypassXT1(void)
Bypass the XT1 crystal oscillator.
Definition: cs.c:271
void CS_enableXT1AutomaticGainControl(void)
Enables XT1 automatic gain control.
Definition: cs.c:544
void CS_clearFaultFlag(uint8_t mask)
Clears the current CS fault flag status for the masked bit.
Definition: cs.c:474
uint32_t CS_getSMCLK(void)
Get the current SMCLK frequency.
Definition: cs.c:503

Copyright 2015, Texas Instruments Incorporated