2 * -------------------------------------------
3 * MSP432 DriverLib - v01_04_00_18
4 * -------------------------------------------
6 * --COPYRIGHT--,BSD,BSD
7 * Copyright (c) 2015, Texas Instruments Incorporated
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 /* Standard Includes */
40 /* DriverLib Includes */
44 #include <interrupt.h>
47 static uint32_t hfxtFreq;
48 static uint32_t lfxtFreq;
52 bool _CSIsClockDividerValid(uint8_t divider)
54 return ((divider == CS_CLOCK_DIVIDER_1) || (divider == CS_CLOCK_DIVIDER_2)
55 || (divider == CS_CLOCK_DIVIDER_4) || (divider == CS_CLOCK_DIVIDER_8)
56 || (divider == CS_CLOCK_DIVIDER_16) || (divider == CS_CLOCK_DIVIDER_32)
57 || (divider == CS_CLOCK_DIVIDER_64) || (divider == CS_CLOCK_DIVIDER_128));
62 static uint32_t _CSGetHFXTFrequency()
64 if (hfxtFreq >= CS_1MHZ && hfxtFreq <= CS_4MHZ)
66 else if (hfxtFreq > CS_4MHZ && hfxtFreq <= CS_8MHZ)
68 else if (hfxtFreq > CS_8MHZ && hfxtFreq <= CS_16MHZ)
70 else if (hfxtFreq > CS_16MHZ && hfxtFreq <= CS_24MHZ)
72 else if (hfxtFreq > CS_24MHZ && hfxtFreq <= CS_32MHZ)
74 else if (hfxtFreq > CS_32MHZ && hfxtFreq <= CS_40MHZ)
76 else if (hfxtFreq > CS_40MHZ && hfxtFreq <= CS_48MHZ)
86 static uint32_t _CSGetDividerValue(uint32_t wDivider)
90 case CS_CLOCK_DIVIDER_1:
92 case CS_CLOCK_DIVIDER_2:
94 case CS_CLOCK_DIVIDER_4:
96 case CS_CLOCK_DIVIDER_8:
98 case CS_CLOCK_DIVIDER_16:
100 case CS_CLOCK_DIVIDER_32:
102 case CS_CLOCK_DIVIDER_64:
104 case CS_CLOCK_DIVIDER_128:
112 static uint32_t _CSComputeCLKFrequency(uint32_t wClockSource, uint32_t wDivider)
116 bDivider = _CSGetDividerValue(wDivider);
118 switch (wClockSource)
120 case CS_LFXTCLK_SELECT:
122 if (BITBAND_PERI(CS->rIFG.r, LFXTIFG_OFS))
124 CS_clearInterruptFlag(CS_LFXT_FAULT);
126 if (BITBAND_PERI(CS->rIFG.r, LFXTIFG_OFS))
128 if (BITBAND_PERI(CS->rCLKEN.r, REFOFSEL_OFS))
129 return (128000 / bDivider);
131 return (32000 / bDivider);
134 return lfxtFreq / bDivider;
136 case CS_HFXTCLK_SELECT:
138 if (BITBAND_PERI(CS->rIFG.r, HFXTIFG_OFS))
140 CS_clearInterruptFlag(CS_HFXT_FAULT);
142 if (BITBAND_PERI(CS->rIFG.r, HFXTIFG_OFS))
144 if (BITBAND_PERI(CS->rCLKEN.r, REFOFSEL_OFS))
145 return (128000 / bDivider);
147 return (32000 / bDivider);
150 return hfxtFreq / bDivider;
152 case CS_VLOCLK_SELECT:
153 return CS_VLOCLK_FREQUENCY / bDivider;
154 case CS_REFOCLK_SELECT:
156 if (BITBAND_PERI(CS->rCLKEN.r, REFOFSEL_OFS))
157 return (128000 / bDivider);
159 return (32000 / bDivider);
161 case CS_DCOCLK_SELECT:
162 return (CS_getDCOFrequency() / bDivider);
163 case CS_MODOSC_SELECT:
164 return CS_MODCLK_FREQUENCY / bDivider;
171 //******************************************************************************
172 // Internal function for getting DCO nominal frequency
173 //******************************************************************************
174 static uint32_t _CSGetDOCFrequency(void)
178 switch (CS->rCTL0.r & DCORSEL_M)
205 void CS_setExternalClockSourceFrequency(uint32_t lfxt_XT_CLK_frequency,
206 uint32_t hfxt_XT_CLK_frequency)
208 hfxtFreq = hfxt_XT_CLK_frequency;
209 lfxtFreq = lfxt_XT_CLK_frequency;
212 void CS_initClockSignal(uint32_t selectedClockSignal, uint32_t clockSource,
213 uint32_t clockSourceDivider)
215 ASSERT(_CSIsClockDividerValid(clockSourceDivider));
217 /* Unlocking the CS Module */
220 switch (selectedClockSignal)
224 /* Making sure that the clock signal for ACLK isn't set to anything
228 (selectedClockSignal != CS_DCOCLK_SELECT)
229 && (selectedClockSignal != CS_MODOSC_SELECT)
230 && (selectedClockSignal != CS_HFXTCLK_SELECT));
232 /* Waiting for the clock source ready bit to be valid before
234 while (!BITBAND_PERI(CS->rSTAT.r, ACLK_READY_OFS))
237 /* Setting the divider and source */
238 CS->rCTL1.r = ((clockSourceDivider >> CS_ACLK_DIV_BITPOS)
239 | (clockSource << CS_ACLK_SRC_BITPOS))
240 | (CS->rCTL1.r & ~(SELA_M | DIVA_M));
242 /* Waiting for ACLK to be ready again */
243 while (!BITBAND_PERI(CS->rSTAT.r, ACLK_READY_OFS))
251 /* Waiting for the clock source ready bit to be valid before
253 while (!BITBAND_PERI(CS->rSTAT.r, MCLK_READY_OFS))
256 CS->rCTL1.r = ((clockSourceDivider >> CS_MCLK_DIV_BITPOS)
257 | (clockSource << CS_MCLK_SRC_BITPOS))
258 | (CS->rCTL1.r & ~(SELM_M | DIVM_M));
260 /* Waiting for MCLK to be ready */
261 while (!BITBAND_PERI(CS->rSTAT.r, MCLK_READY_OFS))
268 /* Waiting for the clock source ready bit to be valid before
270 while (!BITBAND_PERI(CS->rSTAT.r, SMCLK_READY_OFS))
273 CS->rCTL1.r = ((clockSourceDivider >> CS_SMCLK_DIV_BITPOS)
274 | (clockSource << CS_HSMCLK_SRC_BITPOS))
275 | (CS->rCTL1.r & ~(DIVS_M | SELS_M));
277 /* Waiting for SMCLK to be ready */
278 while (!BITBAND_PERI(CS->rSTAT.r, SMCLK_READY_OFS))
285 /* Waiting for the clock source ready bit to be valid before
287 while (!BITBAND_PERI(CS->rSTAT.r, HSMCLK_READY_OFS))
290 CS->rCTL1.r = ((clockSourceDivider >> CS_HSMCLK_DIV_BITPOS)
291 | (clockSource << CS_HSMCLK_SRC_BITPOS))
292 | (CS->rCTL1.r & ~(DIVHS_M | SELS_M));
294 /* Waiting for HSMCLK to be ready */
295 while (!BITBAND_PERI(CS->rSTAT.r, HSMCLK_READY_OFS))
303 /* Waiting for the clock source ready bit to be valid before
305 while (!BITBAND_PERI(CS->rSTAT.r, BCLK_READY_OFS))
308 /* Setting the clock source and then returning
309 * (cannot divide CLK)
311 if (clockSource == CS_LFXTCLK_SELECT)
312 BITBAND_PERI(CS->rCTL1.r, SELB_OFS) = 0;
313 else if (clockSource == CS_REFOCLK_SELECT)
314 BITBAND_PERI(CS->rCTL1.r, SELB_OFS) = 1;
318 /* Waiting for BCLK to be ready */
319 while (!BITBAND_PERI(CS->rSTAT.r, BCLK_READY_OFS))
326 /* Should never get here */
331 /* Locking the module */
332 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
335 void CS_startHFXT(bool bypassMode)
337 CS_startHFXTWithTimeout(bypassMode, 0);
340 void CS_startHFXTWithTimeout(bool bypassMode, uint32_t timeout)
342 uint32_t wHFFreqRange;
346 /* Unlocking the CS Module */
349 /* Saving status and temporarily disabling NMIs for UCS faults */
350 bNMIStatus = SysCtl_getNMISourceStatus() & SYSCTL_CS_SRC;
351 SysCtl_disableNMISource(SYSCTL_CS_SRC);
353 /* Determining which frequency range to use */
354 wHFFreqRange = _CSGetHFXTFrequency();
355 boolTimeout = (timeout == 0) ? false : true;
357 /* Setting to maximum drive strength */
358 BITBAND_PERI(CS->rCTL2.r, HFXTDRIVE_OFS) = 1;
359 CS->rCTL2.r = (CS->rCTL2.r & (~HFXTFREQ_M)) | (wHFFreqRange);
363 BITBAND_PERI(CS->rCTL2.r, HFXTBYPASS_OFS) = 1;
366 BITBAND_PERI(CS->rCTL2.r, HFXTBYPASS_OFS) = 0;
369 /* Starting and Waiting for frequency stabilization */
370 BITBAND_PERI(CS->rCTL2.r, HFXT_EN_OFS) = 1;
371 while (BITBAND_PERI(CS->rIFG.r, HFXTIFG_OFS))
373 if (boolTimeout && ((--timeout) == 0))
376 BITBAND_PERI(CS->rCLRIFG.r,CLR_HFXTIFG_OFS) = 1;
379 /* Setting the drive strength */
382 if (wHFFreqRange != HFXTFREQ_0)
383 BITBAND_PERI(CS->rCTL2.r, HFXTDRIVE_OFS) = 1;
385 BITBAND_PERI(CS->rCTL2.r, HFXTDRIVE_OFS) = 0;
388 /* Locking the module */
389 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
391 /* Enabling the NMI state */
392 SysCtl_enableNMISource(bNMIStatus);
396 void CS_startLFXT(uint32_t xtDrive)
398 CS_startLFXTWithTimeout(xtDrive, 0);
401 void CS_startLFXTWithTimeout(uint32_t xtDrive, uint32_t timeout)
404 bool boolBypassMode, boolTimeout;
406 ASSERT(lfxtFreq != 0)
408 (xtDrive == CS_LFXT_DRIVE0) || (xtDrive == CS_LFXT_DRIVE1)
409 || (xtDrive == CS_LFXT_DRIVE2)
410 || (xtDrive == CS_LFXT_DRIVE3)
411 || (xtDrive == CS_LFXT_BYPASS));
413 /* Unlocking the CS Module */
416 /* Saving status and temporarily disabling NMIs for UCS faults */
417 bNMIStatus = SysCtl_getNMISourceStatus() & SYSCTL_CS_SRC;
418 SysCtl_disableNMISource(SYSCTL_CS_SRC);
419 boolBypassMode = (xtDrive == CS_LFXT_BYPASS) ? true : false;
420 boolTimeout = (timeout == 0) ? false : true;
422 /* Setting to maximum drive strength */
425 BITBAND_PERI(CS->rCTL2.r, LFXTBYPASS_OFS) = 1;
428 CS->rCTL2.r |= (CS_LFXT_DRIVE3);
429 BITBAND_PERI(CS->rCTL2.r, LFXTBYPASS_OFS) = 0;
432 /* Waiting for frequency stabilization */
433 BITBAND_PERI(CS->rCTL2.r, LFXT_EN_OFS) = 1;
435 while (BITBAND_PERI(CS->rIFG.r, LFXTIFG_OFS))
437 if (boolTimeout && ((--timeout) == 0))
440 BITBAND_PERI(CS->rCLRIFG.r,CLR_LFXTIFG_OFS) = 1;
443 /* Setting the drive strength */
446 CS->rCTL2.r = ((CS->rCTL2.r & ~CS_LFXT_DRIVE3) | xtDrive);
449 /* Locking the module */
450 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
452 /* Enabling the NMI state */
453 SysCtl_enableNMISource(bNMIStatus);
456 void CS_enableClockRequest(uint32_t selectClock)
459 selectClock == CS_ACLK || selectClock == CS_HSMCLK
460 || selectClock == CS_SMCLK || selectClock == CS_MCLK);
462 /* Unlocking the module */
465 CS->rCLKEN.r |= selectClock;
467 /* Locking the module */
468 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
471 void CS_disableClockRequest(uint32_t selectClock)
474 selectClock == CS_ACLK || selectClock == CS_HSMCLK
475 || selectClock == CS_SMCLK || selectClock == CS_MCLK);
477 /* Unlocking the module */
480 CS->rCLKEN.r &= ~selectClock;
482 /* Locking the module */
483 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
486 void CS_setReferenceOscillatorFrequency(uint8_t referenceFrequency)
489 referenceFrequency == CS_REFO_32KHZ
490 || referenceFrequency == CS_REFO_128KHZ);
492 /* Unlocking the module */
495 BITBAND_PERI(CS->rCLKEN.r, REFOFSEL_OFS) = referenceFrequency;
497 /* Locking the module */
498 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
501 void CS_enableDCOExternalResistor(void)
503 /* Unlocking the module */
506 BITBAND_PERI(CS->rCTL0.r,DCORES_OFS) = 1;
508 /* Locking the module */
509 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
512 void CS_setDCOExternalResistorCalibration(uint_fast8_t uiCalData)
514 CS->rDCOERCAL.r = (uiCalData);
517 void CS_disableDCOExternalResistor(void)
519 /* Unlocking the module */
522 BITBAND_PERI(CS->rCTL0.r,DCORES_OFS) = 0;
524 /* Locking the module */
525 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
528 void CS_setDCOCenteredFrequency(uint32_t dcoFreq)
531 dcoFreq == CS_DCO_FREQUENCY_1_5 || dcoFreq == CS_DCO_FREQUENCY_3
532 || dcoFreq == CS_DCO_FREQUENCY_6
533 || dcoFreq == CS_DCO_FREQUENCY_12
534 || dcoFreq == CS_DCO_FREQUENCY_24
535 || dcoFreq == CS_DCO_FREQUENCY_48);
537 /* Unlocking the CS Module */
540 /* Resetting Tuning Parameters and Setting the frequency */
541 CS->rCTL0.r = ((CS->rCTL0.r & ~DCORSEL_M) | dcoFreq);
543 /* Locking the CS Module */
544 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
547 void CS_tuneDCOFrequency(int16_t tuneParameter)
551 if (tuneParameter < 0)
553 CS->rCTL0.r = ((CS->rCTL0.r & ~DCOTUNE_M) | (tuneParameter & DCOTUNE_M)
559 ((CS->rCTL0.r & ~DCOTUNE_M) | (tuneParameter & DCOTUNE_M));
563 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
566 uint32_t CS_getDCOFrequency(void)
570 uint32_t centeredFreq;
573 dcoTune = CS->rCTL0.b.bDCOTUNE;
574 centeredFreq = _CSGetDOCFrequency();
577 return (uint32_t) centeredFreq;
579 /* Checking to see if we need to do signed conversion */
580 if (dcoTune & 0x1000)
582 dcoTune = dcoTune | 0xF000;
585 /* DCORSEL = 5, in final silicon this will have a different calibration
586 value, but currently DCORSEL5 calibration is not populated
587 if (centeredFreq == 48000000)
590 if (BITBAND_PERI(CS->rCTL0.r, DCORES_OFS))
592 dcoConst = *((float *) &TLV->rDCOER_CONSTK_RSEL5);
593 calVal = TLV->rDCOER_FCAL_RSEL5;
598 dcoConst = *((float *) &TLV->rDCOIR_CONSTK_RSEL5);
599 calVal = TLV->rDCOIR_FCAL_RSEL5;
605 /* External Resistor */
606 if (BITBAND_PERI(CS->rCTL0.r, DCORES_OFS))
608 dcoConst = *((float *) &TLV->rDCOER_CONSTK_RSEL04);
609 calVal = TLV->rDCOER_FCAL_RSEL04;
611 /* Internal Resistor */
614 dcoConst = *((float *) &TLV->rDCOIR_CONSTK_RSEL04);
615 calVal = TLV->rDCOIR_FCAL_RSEL04;
619 return (uint32_t) ((centeredFreq)
621 - ((dcoConst * dcoTune)
622 / (8 * (1 + dcoConst * (768 - calVal))))));
625 void CS_setDCOFrequency(uint32_t dcoFrequency)
627 int32_t nomFreq, calVal, dcoSigned;
630 // bool rsel5 = false;
631 dcoSigned = (int32_t) dcoFrequency;
633 if (dcoFrequency < 2000000)
636 CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_1_5);
637 } else if (dcoFrequency < 4000000)
640 CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_3);
641 } else if (dcoFrequency < 8000000)
644 CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_6);
645 } else if (dcoFrequency < 16000000)
648 CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_12);
649 } else if (dcoFrequency < 32000000)
652 CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_24);
653 } else if (dcoFrequency < 640000001)
656 CS_setDCOCenteredFrequency(CS_DCO_FREQUENCY_48);
664 if(dcoFrequency == nomFreq)
666 CS_tuneDCOFrequency(0);
670 /* DCORSEL = 5, in final silicon this will have a different calibration
671 value, but currently DCORSEL5 calibration is not populated
675 if (BITBAND_PERI(CS->rCTL0.r, DCORES_OFS))
677 dcoConst = *((float *) &TLV->rDCOER_CONSTK_RSEL5);
678 calVal = TLV->rDCOER_FCAL_RSEL5;
683 dcoConst = *((float *) &TLV->rDCOIR_CONSTK_RSEL5);
684 calVal = TLV->rDCOIR_FCAL_RSEL5;
690 /* External Resistor */
691 if (BITBAND_PERI(CS->rCTL0.r, DCORES_OFS))
693 dcoConst = *((float *) &TLV->rDCOER_CONSTK_RSEL04);
694 calVal = TLV->rDCOER_FCAL_RSEL04;
696 /* Internal Resistor */
699 dcoConst = *((float *) &TLV->rDCOIR_CONSTK_RSEL04);
700 calVal = TLV->rDCOIR_FCAL_RSEL04;
704 dcoTune = (int16_t) (((dcoSigned - nomFreq)
705 * (1.0 + dcoConst * (768.0 - calVal)) * 8.0)
706 / (dcoSigned * dcoConst));
708 CS_tuneDCOFrequency(dcoTune);
712 uint32_t CS_getBCLK(void)
714 if (BITBAND_PERI(CS->rCTL1.r, SELB_OFS))
715 return _CSComputeCLKFrequency(CS_REFOCLK_SELECT, CS_CLOCK_DIVIDER_1);
717 return _CSComputeCLKFrequency(CS_LFXTCLK_SELECT, CS_CLOCK_DIVIDER_1);
720 uint32_t CS_getHSMCLK(void)
722 uint32_t wSource, wDivider;
724 wSource = (CS->rCTL1.r & SELS_M) >> CS_HSMCLK_SRC_BITPOS;
725 wDivider = ((CS->rCTL1.r & DIVHS_M) << CS_HSMCLK_DIV_BITPOS);
727 return _CSComputeCLKFrequency(wSource, wDivider);
730 uint32_t CS_getACLK(void)
732 uint32_t wSource, wDivider;
734 wSource = (CS->rCTL1.r & SELA_M) >> CS_ACLK_SRC_BITPOS;
735 wDivider = ((CS->rCTL1.r & DIVA_M) << CS_ACLK_DIV_BITPOS);
737 return _CSComputeCLKFrequency(wSource, wDivider);
740 uint32_t CS_getSMCLK(void)
742 uint32_t wDivider, wSource;
744 wSource = (CS->rCTL1.r & SELS_M) >> CS_HSMCLK_SRC_BITPOS;
745 wDivider = ((CS->rCTL1.r & DIVS_M));
747 return _CSComputeCLKFrequency(wSource, wDivider);
751 uint32_t CS_getMCLK(void)
753 uint32_t wSource, wDivider;
755 wSource = (CS->rCTL1.r & SELM_M) << CS_MCLK_SRC_BITPOS;
756 wDivider = ((CS->rCTL1.r & DIVM_M) << CS_MCLK_DIV_BITPOS);
758 return _CSComputeCLKFrequency(wSource, wDivider);
761 void CS_enableFaultCounter(uint_fast8_t counterSelect)
763 ASSERT(counterSelect == CS_HFXT_FAULT_COUNTER ||
764 counterSelect == CS_HFXT_FAULT_COUNTER);
766 /* Unlocking the module */
769 if (counterSelect == CS_HFXT_FAULT_COUNTER)
771 BITBAND_PERI(CS->rCTL3.r, FCNTHF_EN_OFS) = 1;
774 BITBAND_PERI(CS->rCTL3.r, FCNTLF_EN_OFS) = 1;
777 /* Locking the module */
778 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
781 void CS_disableFaultCounter(uint_fast8_t counterSelect)
783 ASSERT(counterSelect == CS_HFXT_FAULT_COUNTER ||
784 counterSelect == CS_HFXT_FAULT_COUNTER);
786 /* Unlocking the module */
789 if (counterSelect == CS_HFXT_FAULT_COUNTER)
791 BITBAND_PERI(CS->rCTL3.r, FCNTHF_EN_OFS) = 0;
794 BITBAND_PERI(CS->rCTL3.r, FCNTLF_EN_OFS) = 0;
797 /* Locking the module */
798 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
801 void CS_resetFaultCounter(uint_fast8_t counterSelect)
803 ASSERT(counterSelect == CS_HFXT_FAULT_COUNTER ||
804 counterSelect == CS_HFXT_FAULT_COUNTER);
806 /* Unlocking the module */
809 if (counterSelect == CS_HFXT_FAULT_COUNTER)
811 BITBAND_PERI(CS->rCTL3.r, RFCNTHF_OFS) = 1;
814 BITBAND_PERI(CS->rCTL3.r, RFCNTLF_OFS) = 1;
817 /* Locking the module */
818 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
821 void CS_startFaultCounter(uint_fast8_t counterSelect, uint_fast8_t countValue)
823 ASSERT(counterSelect == CS_HFXT_FAULT_COUNTER ||
824 counterSelect == CS_HFXT_FAULT_COUNTER);
826 ASSERT(countValue == CS_FAULT_COUNTER_4096_CYCLES ||
827 countValue == CS_FAULT_COUNTER_8192_CYCLES ||
828 countValue == CS_FAULT_COUNTER_16384_CYCLES ||
829 countValue == CS_FAULT_COUNTER_32768_CYCLES);
831 /* Unlocking the module */
834 if (counterSelect == CS_HFXT_FAULT_COUNTER)
836 CS->rCTL3.r = ((CS->rCTL3.r & ~FCNTHF_M) | (countValue << 4));
839 CS->rCTL3.r = ((CS->rCTL3.r & ~FCNTLF_M) | (countValue));
842 /* Locking the module */
843 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
846 void CS_enableInterrupt(uint32_t flags)
848 /* Unlocking the module */
853 /* Locking the module */
854 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
857 void CS_disableInterrupt(uint32_t flags)
859 /* Unlocking the module */
864 /* Locking the module */
865 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
868 uint32_t CS_getInterruptStatus(void)
873 uint32_t CS_getEnabledInterruptStatus(void)
875 return CS_getInterruptStatus() & CS->rIE.r;
878 void CS_clearInterruptFlag(uint32_t flags)
880 /* Unlocking the module */
883 CS->rCLRIFG.r |= flags;
885 /* Locking the module */
886 BITBAND_PERI(CS->rKEY.r, CSKEY_OFS) = 1;
889 void CS_registerInterrupt(void (*intHandler)(void))
892 // Register the interrupt handler, returning an error if an error occurs.
894 Interrupt_registerInterrupt(INT_CS, intHandler);
897 // Enable the system control interrupt.
899 Interrupt_enableInterrupt(INT_CS);
902 void CS_unregisterInterrupt(void)
905 // Disable the interrupt.
907 Interrupt_disableInterrupt(INT_CS);
910 // Unregister the interrupt handler.
912 Interrupt_unregisterInterrupt(INT_CS);