1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #ifndef __CS_H__
33 #define __CS_H__
34 
35 //*****************************************************************************
36 //
37 //! \addtogroup cs_api
38 //! @{
39 //
40 //*****************************************************************************
41 
42 //*****************************************************************************
43 //
44 // If building with a C++ compiler, make all of the definitions in this header
45 // have a C binding.
46 //
47 //*****************************************************************************
48 #ifdef __cplusplus
49 extern "C"
50 {
51 #endif
52 
53 #include <stdint.h>
54 #include <stdbool.h>
55 #include <ti/devices/msp432p4xx/inc/msp.h>
56 
57 //*****************************************************************************
58 //
59 // Control specific variables
60 //
61 //*****************************************************************************
62 #define CS_CLOCK_DIVIDER_1 CS_CTL1_DIVS_0
63 #define CS_CLOCK_DIVIDER_2 CS_CTL1_DIVS_1
64 #define CS_CLOCK_DIVIDER_4 CS_CTL1_DIVS_2
65 #define CS_CLOCK_DIVIDER_8 CS_CTL1_DIVS_3
66 #define CS_CLOCK_DIVIDER_16 CS_CTL1_DIVS_4
67 #define CS_CLOCK_DIVIDER_32 CS_CTL1_DIVS_5
68 #define CS_CLOCK_DIVIDER_64 CS_CTL1_DIVS_6
69 #define CS_CLOCK_DIVIDER_128 CS_CTL1_DIVS_7
70 
71 #define CS_LFXTCLK_SELECT   CS_CTL1_SELM_0
72 #define CS_HFXTCLK_SELECT   CS_CTL1_SELM_5
73 #define CS_VLOCLK_SELECT    CS_CTL1_SELM_1
74 #define CS_REFOCLK_SELECT   CS_CTL1_SELM_2
75 #define CS_DCOCLK_SELECT    CS_CTL1_SELM_3
76 #define CS_MODOSC_SELECT    CS_CTL1_SELM_4
77 
78 #define CS_KEY 0x695A
79 
80 /* Number of positions to shift for divider calculation */
81 #define CS_ACLK_DIV_BITPOS 0x04
82 #define CS_MCLK_DIV_BITPOS 0x0C
83 #define CS_SMCLK_DIV_BITPOS 0x00
84 #define CS_HSMCLK_DIV_BITPOS 0x08
85 
86 /* Number of positions to shift for source calculation */
87 #define CS_ACLK_SRC_BITPOS 0x08
88 #define CS_MCLK_SRC_BITPOS 0x00
89 #define CS_SMCLK_SRC_BITPOS 0x04
90 #define CS_HSMCLK_SRC_BITPOS 0x04
91 
92 /* REFO Clock Values */
93 #define CS_REFO_32KHZ 0x00
94 #define CS_REFO_128KHZ 0x01
95 
96 /* Frequency Values */
97 #define CS_VLOCLK_FREQUENCY 10000
98 #define CS_MODCLK_FREQUENCY 24000000
99 
100 /* Interrupts */
101 #define CS_LFXT_FAULT   CS_IE_LFXTIE
102 #define CS_HFXT_FAULT   CS_IE_HFXTIE
103 #define CS_DCO_OPEN_FAULT   CS_IE_DCOR_OPNIE
104 #define CS_STARTCOUNT_LFXT_FAULT   CS_IE_FCNTLFIE
105 #define CS_STARTCOUNT_HFXT_FAULT   CS_IE_FCNTHFIE
106 #define CS_DCO_SHORT_FAULT   CS_IFG_DCOR_SHTIFG
107 
108 #define CS_HFXT_DRIVE CS_CTL2_HFXTDRIVE
109 #define CS_HFXT_BYPASS CS_CTL2_HFXTBYPASS
110 
111 #define CS_LFXT_DRIVE0 CS_CTL2_LFXTDRIVE_0
112 #define CS_LFXT_DRIVE1 CS_CTL2_LFXTDRIVE_1
113 #define CS_LFXT_DRIVE2 CS_CTL2_LFXTDRIVE_2
114 #define CS_LFXT_DRIVE3 CS_CTL2_LFXTDRIVE_3
115 #define CS_LFXT_BYPASS CS_CTL2_LFXTBYPASS
116 
117 #define CS_ACLK CS_CLKEN_ACLK_EN
118 #define CS_MCLK CS_CLKEN_MCLK_EN
119 #define CS_SMCLK CS_CLKEN_SMCLK_EN
120 #define CS_HSMCLK CS_CLKEN_HSMCLK_EN
121 #define CS_BCLK CS_STAT_BCLK_READY
122 
123 #define CS_LFXTCLK  0x01
124 
125 #define CS_1MHZ 1000000
126 #define CS_15MHZ 1500000
127 #define CS_3MHZ 3000000
128 #define CS_4MHZ 4000000
129 #define CS_6MHZ 6000000
130 #define CS_8MHZ 8000000
131 #define CS_12MHZ 12000000
132 #define CS_16MHZ 16000000
133 #define CS_24MHZ 24000000
134 #define CS_32MHZ 32000000
135 #define CS_40MHZ 40000000
136 #define CS_48MHZ 48000000
137 
138 #define CS_DCO_FREQUENCY_1_5 CS_CTL0_DCORSEL_0
139 #define CS_DCO_FREQUENCY_3 CS_CTL0_DCORSEL_1
140 #define CS_DCO_FREQUENCY_6 CS_CTL0_DCORSEL_2
141 #define CS_DCO_FREQUENCY_12 CS_CTL0_DCORSEL_3
142 #define CS_DCO_FREQUENCY_24 CS_CTL0_DCORSEL_4
143 #define CS_DCO_FREQUENCY_48 CS_CTL0_DCORSEL_5
144 
145 #define CS_HFXT_FAULT_COUNTER 0x01
146 #define CS_LFXT_FAULT_COUNTER 0x02
147 
148 #define CS_FAULT_COUNTER_4096_CYCLES CS_CTL3_FCNTLF_0
149 #define CS_FAULT_COUNTER_8192_CYCLES CS_CTL3_FCNTLF_1
150 #define CS_FAULT_COUNTER_16384_CYCLES CS_CTL3_FCNTLF_2
151 #define CS_FAULT_COUNTER_32768_CYCLES CS_CTL3_FCNTLF_3
152 
153 #define CS_OVER32MHZ    0x01
154 #define CS_UNDER32MHZ   0x02
155 
156 //******************************************************************************
157 //
158 //! This function sets the external clock sources LFXT and HFXT crystal
159 //! oscillator frequency values. This function must be called if an external
160 //! crystal LFXT or HFXT is used and the user intends to call
161 //! CS_getSMCLK, CS_getMCLK, CS_getBCLK,  CS_getHSMCLK, CS_getACLK and
162 //! any of the HFXT oscillator control functions
163 //!
164 //! \param lfxt_XT_CLK_frequency is the LFXT crystal frequencies in Hz
165 //! \param hfxt_XT_CLK_frequency is the HFXT crystal frequencies in Hz
166 //!
167 //! \return None
168 //
169 //******************************************************************************
170 extern void CS_setExternalClockSourceFrequency(uint32_t lfxt_XT_CLK_frequency,
171         uint32_t hfxt_XT_CLK_frequency);
172 
173 //******************************************************************************
174 //
175 //! This function initializes each of the clock signals. The user must ensure
176 //! that this function is called for each clock signal. If not, the default
177 //! state is assumed for the particular clock signal. Refer to DriverLib
178 //! documentation for CS module or Device Family User's Guide for details of
179 //! default clock signal states.
180 //!
181 //! Note that this function is blocking and will wait on the appropriate bit
182 //! to be set in the CSSTAT READY register to be set before setting the clock
183 //! source.
184 //!
185 //! Also note that when HSMCLK and SMCLK share the same clock signal. If you
186 //! change the clock signal for HSMCLK, the clock signal for SMCLK will change
187 //! also (and vice-versa).
188 //!
189 //! HFXTCLK is not available for BCLK or ACLK.
190 //!
191 //! \param selectedClockSignal Clock signal to initialize.
192 //!           - \b CS_ACLK,
193 //!           - \b CS_MCLK,
194 //!           - \b CS_HSMCLK
195 //!           - \b CS_SMCLK
196 //!           - \b CS_BCLK  [clockSourceDivider is ignored for this parameter]
197 //! \param clockSource  Clock source for the selectedClockSignal signal.
198 //!            - \b CS_LFXTCLK_SELECT,
199 //!            - \b CS_HFXTCLK_SELECT,
200 //!            - \b CS_VLOCLK_SELECT,     [Not available for BCLK]
201 //!            - \b CS_DCOCLK_SELECT,     [Not available for ACLK, BCLK]
202 //!            - \b CS_REFOCLK_SELECT,
203 //!            - \b CS_MODOSC_SELECT      [Not available for ACLK, BCLK]
204 //! \param clockSourceDivider - selected the clock divider to calculate
205 //!         clock signal from clock source. This parameter is ignored when
206 //!         setting BLCK. Valid values are:
207 //!           - \b CS_CLOCK_DIVIDER_1,
208 //!           - \b CS_CLOCK_DIVIDER_2,
209 //!           - \b CS_CLOCK_DIVIDER_4,
210 //!           - \b CS_CLOCK_DIVIDER_8,
211 //!           - \b CS_CLOCK_DIVIDER_16,
212 //!           - \b CS_CLOCK_DIVIDER_32,
213 //!           - \b CS_CLOCK_DIVIDER_64,
214 //!           - \b CS_CLOCK_DIVIDER_128
215 //!
216 //! \return NONE
217 //
218 //******************************************************************************
219 extern void CS_initClockSignal(uint32_t selectedClockSignal,
220         uint32_t clockSource, uint32_t clockSourceDivider);
221 
222 //******************************************************************************
223 //
224 //! Initializes the HFXT crystal oscillator, which supports crystal frequencies
225 //! between 0 MHz and 48 MHz, depending on the selected drive strength. Loops
226 //! until all oscillator fault flags are cleared, with no timeout. See the
227 //! device-specific data sheet for appropriate drive settings. NOTE: User must
228 //! call CS_setExternalClockSourceFrequency to set frequency of external clocks
229 //! before calling this function.
230 //!
231 //! \param bypassMode When this variable is set, the oscillator will start
232 //! in bypass mode and the signal can be generated by a digital square wave.
233 //!
234 //! \return true if started correctly, false otherwise
235 //
236 //******************************************************************************
237 extern bool CS_startHFXT(bool bypassMode);
238 
239 //******************************************************************************
240 //
241 //! Initializes the HFXT crystal oscillator, which supports crystal frequencies
242 //! between 0 MHz and 48 MHz, depending on the selected drive strength. Loops
243 //! until all oscillator fault flags are cleared, with no timeout. See the
244 //! device-specific data sheet for appropriate drive settings. NOTE: User must
245 //! call CS_setExternalClockSourceFrequency to set frequency of external clocks
246 //! before calling this function. This function has a timeout associated with
247 //! stabilizing the oscillator.
248 //!
249 //! \param bypassMode When this variable is set, the oscillator will start
250 //! in bypass mode and the signal can be generated by a digital square wave.
251 //!
252 //! \param timeout is the count value that gets decremented every time the loop
253 //!         that clears oscillator fault flags gets executed.
254 //!
255 //! \return true if started correctly, false otherwise
256 //
257 //******************************************************************************
258 extern bool CS_startHFXTWithTimeout(bool bypassMode, uint32_t timeout);
259 
260 //******************************************************************************
261 //
262 //! Initializes the LFXT crystal oscillator, which supports crystal frequencies
263 //! up to 50kHz, depending on the selected drive strength. Loops
264 //! until all oscillator fault flags are cleared, with no timeout. See the
265 //! device-specific data sheet for appropriate drive settings. NOTE: User must
266 //! call CS_setExternalClockSourceFrequency to set frequency of external clocks
267 //! before calling this function.
268 //!
269 //! \param xtDrive is the target drive strength for the LFXT crystal
270 //!                  oscillator.
271 //!      Valid values are:
272 //!         - \b CS_LFXT_DRIVE0,
273 //!         - \b CS_LFXT_DRIVE1,
274 //!         - \b CS_LFXT_DRIVE2,
275 //!         - \b CS_LFXT_DRIVE3,  [Default Value]
276 //!         - \b CS_LFXT_BYPASS
277 //!
278 //! \note When CS_LFXT_BYPASS is passed as a parameter the oscillator will start
279 //! in bypass mode and the signal can be generated by a digital square wave.
280 //!
281 //! \return true if started correctly, false otherwise
282 //
283 //******************************************************************************
284 extern bool CS_startLFXT(uint32_t xtDrive);
285 
286 //******************************************************************************
287 //
288 //! Initializes the LFXT crystal oscillator, which supports crystal frequencies
289 //! up to 50kHz, depending on the selected drive strength. Loops
290 //! until all oscillator fault flags are cleared. See the
291 //! device-specific data sheet for appropriate drive settings. NOTE: User must
292 //! call CS_setExternalClockSourceFrequency to set frequency of external clocks
293 //! before calling this function. This function has a timeout associated with
294 //! stabilizing the oscillator.
295 //!
296 //! \param xtDrive is the target drive strength for the LFXT crystal
297 //!                  oscillator.
298 //!      Valid values are:
299 //!         - \b CS_LFXT_DRIVE0,
300 //!         - \b CS_LFXT_DRIVE1,
301 //!         - \b CS_LFXT_DRIVE2,
302 //!         - \b CS_LFXT_DRIVE3,  [Default Value]
303 //!         - \b CS_LFXT_BYPASS
304 //!
305 //! \note When CS_LFXT_BYPASS is passed as a parameter the oscillator will
306 //! start in bypass mode and the signal can be generated by a digital square
307 //! wave.
308 //!
309 //! \param timeout is the count value that gets decremented every time the loop
310 //!         that clears oscillator fault flags gets executed.
311 //!
312 //! \return true if started correctly, false otherwise
313 //
314 //******************************************************************************
315 extern bool CS_startLFXTWithTimeout(uint32_t xtDrive, uint32_t timeout);
316 
317 //******************************************************************************
318 //
319 //! Selects between the frequency of the internal REFO clock source
320 //!
321 //! \param referenceFrequency selects between the valid frequencies:
322 //!        - \b CS_REFO_32KHZ,
323 //!        - \b CS_REFO_128KHZ,
324 //!
325 //! \return NONE
326 //
327 //******************************************************************************
328 extern void CS_setReferenceOscillatorFrequency(uint8_t referenceFrequency);
329 
330 //******************************************************************************
331 //
332 //! Enables conditional module requests
333 //!
334 //! \param selectClock selects specific request enables. Valid values are
335 //!        are a logical OR of the following values:
336 //!        - \b CS_ACLK,
337 //!        - \b CS_HSMCLK,
338 //!        - \b CS_SMCLK,
339 //!        - \b CS_MCLK
340 //!
341 //! \return NONE
342 //
343 //******************************************************************************
344 extern void CS_enableClockRequest(uint32_t selectClock);
345 
346 //******************************************************************************
347 //
348 //! Disables conditional module requests
349 //!
350 //! \param selectClock selects specific request disables. Valid values are
351 //!        are a logical OR of the following values:
352 //!        - \b CS_ACLK,
353 //!        - \b CS_HSMCLK,
354 //!        - \b CS_SMCLK,
355 //!        - \b CS_MCLK
356 //!
357 //! \return NONE
358 //
359 //******************************************************************************
360 extern void CS_disableClockRequest(uint32_t selectClock);
361 
362 //******************************************************************************
363 //
364 //! Get the current ACLK frequency.
365 //!
366 //! If a oscillator fault is set, the frequency returned will be based on the
367 //! fail safe mechanism of CS module. The user of this API must ensure that
368 //! \link CS_setExternalClockSourceFrequency() \endlink API was invoked before
369 //! in case LFXT is being used.
370 //!
371 //! \return Current ACLK frequency in Hz
372 //
373 //******************************************************************************
374 extern uint32_t CS_getACLK(void);
375 
376 //******************************************************************************
377 //
378 //! Get the current SMCLK frequency.
379 //!
380 //! If a oscillator fault is set, the frequency returned will be based on the
381 //! fail safe mechanism of CS module. The user of this API must ensure that
382 //! CS_setExternalClockSourceFrequency API was invoked before in case LFXT or
383 //! HFXT is being used.
384 //!
385 //! \return Current SMCLK frequency in Hz
386 //
387 //******************************************************************************
388 extern uint32_t CS_getSMCLK(void);
389 
390 //******************************************************************************
391 //
392 //! Get the current MCLK frequency.
393 //!
394 //! If a oscillator fault is set, the frequency returned will be based on the
395 //! fail safe mechanism of CS module. The user of this API must ensure that
396 //! CS_setExternalClockSourceFrequency API was invoked before in case LFXT or
397 //! HFXT is being used.
398 //!
399 //! \return Current MCLK frequency in Hz
400 //
401 //******************************************************************************
402 extern uint32_t CS_getMCLK(void);
403 
404 //******************************************************************************
405 //
406 //! Get the current BCLK frequency.
407 //!
408 //! If a oscillator fault is set, the frequency returned will be based on the
409 //! fail safe mechanism of CS module. The user of this API must ensure that
410 //! \link CS_setExternalClockSourceFrequency \endlink API was invoked before in
411 //! case LFXT or HFXT is being used.
412 //!
413 //! \return Current BCLK frequency in Hz
414 //
415 //******************************************************************************
416 extern uint32_t CS_getBCLK(void);
417 
418 //******************************************************************************
419 //
420 //! Get the current HSMCLK frequency.
421 //!
422 //! If a oscillator fault is set, the frequency returned will be based on the
423 //! fail safe mechanism of CS module. The user of this API must ensure that
424 //! \link CS_setExternalClockSourceFrequency \endlink API was invoked before in
425 //! case LFXT or HFXT is being used.
426 //!
427 //! \return Current HSMCLK frequency in Hz
428 //
429 //******************************************************************************
430 extern uint32_t CS_getHSMCLK(void);
431 
432 //******************************************************************************
433 //
434 //! Sets the centered frequency of DCO operation.  Each frequency represents
435 //! the centred frequency of a particular frequency range. Further tuning can
436 //! be achieved by using the CS_tuneDCOFrequency function. Note that setting
437 //! the nominal frequency will reset the tuning parameters.
438 //!
439 //! \param dcoFreq selects between the valid frequencies:
440 //!        - \b CS_DCO_FREQUENCY_1_5, [1MHz to 2MHz]
441 //!        - \b CS_DCO_FREQUENCY_3,   [2MHz to 4MHz]
442 //!        - \b CS_DCO_FREQUENCY_6,   [4MHz to 8MHz]
443 //!        - \b CS_DCO_FREQUENCY_12,  [8MHz to 16MHz]
444 //!        - \b CS_DCO_FREQUENCY_24,  [16MHz to 32MHz]
445 //!        - \b CS_DCO_FREQUENCY_48   [32MHz to 64MHz]
446 //!
447 //! \return NONE
448 //
449 //******************************************************************************
450 extern void CS_setDCOCenteredFrequency(uint32_t dcoFreq);
451 
452 //******************************************************************************
453 //
454 //! Automatically sets/tunes the DCO to the given frequency. Any valid value
455 //! up to max frequency in the spec can be given to this function and the API
456 //! will do its best to determine the correct tuning parameter.
457 //!
458 //! \note The frequency ranges that can be custom tuned on early release MSP432
459 //! devices is limited. For further details on supported tunable frequencies,
460 //! please refer to the device errata sheet or data sheet.
461 //!
462 //! \param dcoFrequency Frequency in Hz that the user wants to set the DCO to.
463 //!
464 //! \note This function uses floating point math to calculate the DCO tuning
465 //!         parameter. If efficiency is a concern, the user should use the
466 //!         \link FPU_enableModule \endlink function (if available) to enable
467 //!         the floating point co-processor.
468 //!
469 //! \return None
470 //
471 //******************************************************************************
472 extern void CS_setDCOFrequency(uint32_t dcoFrequency);
473 
474 //******************************************************************************
475 //
476 //! Tunes the DCO to a specific frequency. Tuning of the DCO is based off of the
477 //! following equation in the user's guide:
478 //!
479 //! See the user's guide for more detailed information about DCO tuning.
480 //!
481 //! \note This function is not currently available on pre-release MSP432 devices.
482 //!  On early release versions of MSP432, the DCO calibration information has not been
483 //!  populated making the DCO only able to operate at the pre-calibrated centered
484 //!  frequencies accessible by the \link CS_setDCOCenteredFrequency \endlink
485 //!  function. While this function will be added on the final devices being released,
486 //!  for early silicon please default to the pre-calibrated DCO center frequencies.
487 //!
488 //! \param tuneParameter Tuning parameter in 2's Compliment representation.
489 //!  Can be negative or positive.
490 //!
491 //! \return NONE
492 //
493 //******************************************************************************
494 extern void CS_tuneDCOFrequency(int16_t tuneParameter);
495 
496 //******************************************************************************
497 //
498 //! Enables the external resistor for DCO operation
499 //!
500 //! \return NONE
501 //
502 //******************************************************************************
503 extern void CS_enableDCOExternalResistor(void);
504 
505 //******************************************************************************
506 //
507 //! Disables the external resistor for DCO operation
508 //!
509 //! \return NONE
510 //
511 //******************************************************************************
512 extern void CS_disableDCOExternalResistor(void);
513 
514 //******************************************************************************
515 //
516 //! Sets the calibration value for the DCO when using the external resistor
517 //! mode. This value is used for tuning the DCO to custom frequencies. By
518 //! default, the value in the CS module is populated by the calibration
519 //! data of the suggested external resistor (see device datasheet).
520 //!
521 //! \param calData is the calibration data constant for the external resistor.
522 //!
523 //! \param freqRange is the range of the DCO to set the external calibration
524 //!             for. Frequencies above 32MHZ have a different calibration value
525 //!             than frequencies below 32MHZ.
526 //!
527 //! \return None
528 //
529 //******************************************************************************
530 extern void CS_setDCOExternalResistorCalibration(uint_fast8_t uiCalData,
531                                                  uint_fast8_t freqRange);
532 
533 //******************************************************************************
534 //
535 //! Gets the current tuned DCO frequency. If no tuning has been done, this
536 //! returns the nominal DCO frequency of the current DCO range. Note that this
537 //! function will grab any constant/calibration data from the DDDS table
538 //! without any user interaction needed.
539 //!
540 //! \note This function uses floating point math to calculate the DCO tuning
541 //!         parameter. If efficiency is a concern, the user should use the
542 //!         \link FPU_enableModule \endlink function (if available) to enable
543 //!         the floating point co-processor.
544 //!
545 //! \return Current DCO frequency in Hz
546 //
547 //******************************************************************************
548 extern uint32_t CS_getDCOFrequency(void);
549 
550 //******************************************************************************
551 //
552 //! Automatically sets/tunes the DCO to the given frequency. Any valid value
553 //! up to (and including) 64Mhz can be given to this function and the API
554 //! will do its best to determine the correct tuning parameter.
555 //!
556 //!
557 //! \note This function is not currently available on pre-release MSP432 devices.
558 //!  On early release versions of MSP432, the DCO calibration information has not been
559 //!  populated making the DCO only able to operate at the pre-calibrated centered
560 //!  frequencies accessible by the \link CS_setDCOCenteredFrequency \endlink
561 //!  function. While this function will be added on the final devices being released,
562 //!  for early silicon please default to the pre-calibrated DCO center frequencies.
563 //!
564 //! \param dcoFrequency Frequency in Hz (1500000 - 64000000) that the user wants
565 //!         to set the DCO to.
566 //!
567 //! \note This function uses floating point math to calculate the DCO tuning
568 //!         parameter. If efficiency is a concern, the user should use the
569 //!         \link FPU_enableModule \endlink function (if available) to enable
570 //!         the floating point co-processor.
571 //!
572 //! \return None
573 //
574 //******************************************************************************
575 extern void CS_setDCOFrequency(uint32_t dcoFrequency);
576 
577 //******************************************************************************
578 //
579 //! Enables the fault counter for the CS module. This function can enable
580 //! either the HFXT fault counter or the LFXT fault counter.
581 //!
582 //! \param counterSelect selects the fault counter to enable
583 //!        - \b CS_HFXT_FAULT_COUNTER
584 //!        - \b CS_LFXT_FAULT_COUNTER
585 //!
586 //! \return NONE
587 //
588 //******************************************************************************
589 extern void CS_enableFaultCounter(uint_fast8_t counterSelect);
590 
591 //******************************************************************************
592 //
593 //! Disables the fault counter for the CS module. This function can disable
594 //! either the HFXT fault counter or the LFXT fault counter.
595 //!
596 //! \param counterSelect selects the fault counter to disable
597 //!        - \b CS_HFXT_FAULT_COUNTER
598 //!        - \b CS_LFXT_FAULT_COUNTER
599 //!
600 //! \return NONE
601 //
602 //******************************************************************************
603 extern void CS_disableFaultCounter(uint_fast8_t counterSelect);
604 
605 //******************************************************************************
606 //
607 //! Resets the fault counter for the CS module. This function can reset
608 //! either the HFXT fault counter or the LFXT fault counter.
609 //!
610 //! \param counterSelect selects the fault counter to reset
611 //!        - \b CS_HFXT_FAULT_COUNTER
612 //!        - \b CS_LFXT_FAULT_COUNTER
613 //!
614 //! \return NONE
615 //
616 //******************************************************************************
617 extern void CS_resetFaultCounter(uint_fast8_t counterSelect);
618 
619 //******************************************************************************
620 //
621 //! Sets the count for the start value of the fault counter. This function can
622 //! be used to set either the HFXT count or the LFXT count.
623 //!
624 //! \param counterSelect selects the fault counter to reset
625 //!        - \b CS_HFXT_FAULT_COUNTER
626 //!        - \b CS_LFXT_FAULT_COUNTER
627 //! \param countValue selects the cycles to set the fault counter to
628 //!        - \b CS_FAULT_COUNTER_4096_CYCLES
629 //!        - \b CS_FAULT_COUNTER_8192_CYCLES
630 //!        - \b CS_FAULT_COUNTER_16384_CYCLES
631 //!        - \b CS_FAULT_COUNTER_32768_CYCLES
632 //!
633 //! \return NONE
634 //
635 //******************************************************************************
636 extern void CS_startFaultCounter(uint_fast8_t counterSelect,
637         uint_fast8_t countValue);
638 
639 //*****************************************************************************
640 //
641 //! Enables individual clock control interrupt sources.
642 //!
643 //! \param flags is a bit mask of the interrupt sources to be enabled.  Must
644 //! be a logical OR of:
645 //!                     - \b CS_LFXT_FAULT,
646 //!                     - \b CS_HFXT_FAULT,
647 //!                     - \b CS_DCOMIN_FAULT,
648 //!                     - \b CS_DCOMAX_FAULT,
649 //!                     - \b CS_DCO_OPEN_FAULT,
650 //!                     - \b CS_STARTCOUNT_LFXT_FAULT,
651 //!                     - \b CS_STARTCOUNT_HFXT_FAULT,
652 //!
653 //! This function enables the indicated clock system interrupt sources.  Only
654 //! the sources that are enabled can be reflected to the processor interrupt;
655 //! disabled sources have no effect on the processor.
656 //!
657 //! \note The interrupt sources vary based on the part in use.
658 //! Please consult the data sheet for the part you are using to determine
659 //! which interrupt sources are available.
660 //!
661 //! \return None.
662 //
663 //*****************************************************************************
664 extern void CS_enableInterrupt(uint32_t flags);
665 
666 //*****************************************************************************
667 //
668 //! Disables individual clock system interrupt sources.
669 //!
670 //! \param flags is a bit mask of the interrupt sources to be disabled.  Must
671 //! be a logical OR of:
672 //!                     - \b CS_LFXT_FAULT,
673 //!                     - \b CS_HFXT_FAULT,
674 //!                     - \b CS_DCOMIN_FAULT,
675 //!                     - \b CS_DCOMAX_FAULT,
676 //!                     - \b CS_DCO_OPEN_FAULT,
677 //!                     - \b CS_STARTCOUNT_LFXT_FAULT,
678 //!                     - \b CS_STARTCOUNT_HFXT_FAULT,
679 //!
680 //! \note The interrupt sources vary based on the part in use.
681 //! Please consult the data sheet for the part you are using to determine
682 //! which interrupt sources are available.
683 //!
684 //! \return None.
685 //
686 //*****************************************************************************
687 extern void CS_disableInterrupt(uint32_t flags);
688 
689 //*****************************************************************************
690 //
691 //! Gets the current interrupt status masked with the enabled interrupts.
692 //! This function is useful to call in ISRs to get a list of pending interrupts
693 //! that are actually enabled and could have caused the ISR.
694 //!
695 //! \return The current interrupt status, enumerated as a bit field of
696 //!                     - \b CS_LFXT_FAULT,
697 //!                     - \b CS_HFXT_FAULT,
698 //!                     - \b CS_DCO_OPEN_FAULT,
699 //!                     - \b CS_DCO_SHORT_FAULT,
700 //!                     - \b CS_STARTCOUNT_LFXT_FAULT,
701 //!                     - \b CS_STARTCOUNT_HFXT_FAULT,
702 //!
703 //! \note The interrupt sources vary based on the part in use.
704 //! Please consult the data sheet for the part you are using to determine
705 //! which interrupt sources are available.
706 //
707 //*****************************************************************************
708 extern uint32_t CS_getEnabledInterruptStatus(void);
709 
710 //*****************************************************************************
711 //
712 //! Gets the current interrupt status.
713 //!
714 //! \return The current interrupt status, enumerated as a bit field of:
715 //!                     - \b CS_LFXT_FAULT,
716 //!                     - \b CS_HFXT_FAULT,
717 //!                     - \b CS_DCO_OPEN_FAULT,
718 //!                     - \b CS_DCO_SHORT_FAULT,
719 //!                     - \b CS_STARTCOUNT_LFXT_FAULT,
720 //!                     - \b CS_STARTCOUNT_HFXT_FAULT,
721 //!
722 //! \note The interrupt sources vary based on the part in use.
723 //! Please consult the data sheet for the part you are using to determine
724 //! which interrupt sources are available.
725 //
726 //*****************************************************************************
727 extern uint32_t CS_getInterruptStatus(void);
728 
729 //*****************************************************************************
730 //
731 //! Clears clock system interrupt sources.
732 //!
733 //! \param flags is a bit mask of the interrupt sources to be cleared.  Must
734 //! be a logical OR of:
735 //!                     - \b CS_LFXT_FAULT,
736 //!                     - \b CS_HFXT_FAULT,
737 //!                     - \b CS_DCO_OPEN_FAULT,
738 //!                     - \b CS_STARTCOUNT_LFXT_FAULT,
739 //!                     - \b CS_STARTCOUNT_HFXT_FAULT,
740 //!
741 //! The specified clock system interrupt sources are cleared, so that they no
742 //! longer assert.  This function must be called in the interrupt handler to
743 //! keep it from being called again immediately upon exit.
744 //!
745 //! \note Because there is a write buffer in the Cortex-M processor, it may
746 //! take several clock cycles before the interrupt source is actually cleared.
747 //! Therefore, it is recommended that the interrupt source be cleared early in
748 //! the interrupt handler (as opposed to the very last action) to avoid
749 //! returning from the interrupt handler before the interrupt source is
750 //! actually cleared.  Failure to do so may result in the interrupt handler
751 //! being immediately reentered (because the interrupt controller still sees
752 //! the interrupt source asserted).
753 //!
754 //! \note The interrupt sources vary based on the part in use.
755 //! Please consult the data sheet for the part you are using to determine
756 //! which interrupt sources are available.
757 //!
758 //! \return None.
759 //
760 //*****************************************************************************
761 extern void CS_clearInterruptFlag(uint32_t flags);
762 
763 //*****************************************************************************
764 //
765 //! Registers an interrupt handler for the clock system interrupt.
766 //!
767 //! \param intHandler is a pointer to the function to be called when the clock
768 //! system interrupt occurs.
769 //!
770 //! This function registers the handler to be called when a clock system
771 //! interrupt occurs. This function enables the global interrupt in the
772 //! interrupt controller; specific clock system interrupts must be enabled
773 //! via CS_enableInterrupt().  It is the interrupt handler's responsibility to
774 //! clear the interrupt source via CS_clearInterruptFlag().
775 //!
776 //! Clock System can generate interrupts when
777 //!
778 //! \sa Interrupt_registerInterrupt() for important information about
779 //! registering interrupt handlers.
780 //!
781 //! \return None.
782 //
783 //*****************************************************************************
784 extern void CS_registerInterrupt(void (*intHandler)(void));
785 
786 //*****************************************************************************
787 //
788 //! Unregisters the interrupt handler for the clock system.
789 //!
790 //! This function unregisters the handler to be called when a clock system
791 //! interrupt occurs.  This function also masks off the interrupt in the
792 //! interrupt controller so that the interrupt handler no longer is called.
793 //!
794 //! \sa Interrupt_registerInterrupt() for important information about
795 //! registering interrupt handlers.
796 //!
797 //! \return None.
798 //
799 //*****************************************************************************
800 extern void CS_unregisterInterrupt(void);
801 
802 //*****************************************************************************
803 //
804 // Mark the end of the C bindings section for C++ compilers.
805 //
806 //*****************************************************************************
807 #ifdef __cplusplus
808 }
809 #endif
810 
811 //*****************************************************************************
812 //
813 // Close the Doxygen group.
814 //! @}
815 //
816 //*****************************************************************************
817 
818 #endif
819