CC23x0R5DriverLibrary
ckmd.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Filename: ckmd.h
3  *
4  * Description: Defines and prototypes for the CKMD module.
5  *
6  * Copyright (c) 2023-2025 Texas Instruments Incorporated
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1) Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  *
14  * 2) Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  *
18  * 3) Neither the name of the copyright holder nor the names of its
19  * contributors may be used to endorse or promote products derived from this
20  * software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ******************************************************************************/
35 
36 #ifndef __CKMD_H__
37 #define __CKMD_H__
38 
39 //*****************************************************************************
40 //
45 //
46 //*****************************************************************************
47 
48 //*****************************************************************************
49 //
50 // If building with a C++ compiler, make all of the definitions in this header
51 // have a C binding.
52 //
53 //*****************************************************************************
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 #include <stdbool.h>
59 #include <stdint.h>
60 
61 #include "../inc/hw_types.h"
62 #include "../inc/hw_memmap.h"
63 #include "../inc/hw_ckmd.h"
64 #include "../inc/hw_fcfg.h"
65 
66 //*****************************************************************************
67 //
83 //
84 //*****************************************************************************
85 #define CKMD_LFOSC_MID_TEMP_COEFFICIENT_RANGE_MIN (INT16_MIN)
86 #define CKMD_LFOSC_MID_TEMP_COEFFICIENT_RANGE_MAX (70)
87 
90 #define CKMD_WATCHDOG_UNLOCK 0x1ACCE551
91 
92 //*****************************************************************************
93 //
94 // API Functions and prototypes
95 //
96 //*****************************************************************************
97 
98 //*****************************************************************************
99 //
101 //
102 //*****************************************************************************
104 {
105  HWREG(CKMD_BASE + CKMD_O_HFXTCTL) |= CKMD_HFXTCTL_HPBUFEN;
106 }
107 
108 //*****************************************************************************
109 //
111 //
112 //*****************************************************************************
114 {
115  HWREG(CKMD_BASE + CKMD_O_HFXTCTL) &= ~CKMD_HFXTCTL_HPBUFEN;
116 }
117 
118 //*****************************************************************************
119 //
136 //
137 //*****************************************************************************
138 __STATIC_INLINE void CKMDSetInitialCapTrim(uint32_t q1CapTrim, uint32_t q2CapTrim)
139 {
140  uint32_t tmp = HWREG(CKMD_BASE + CKMD_O_HFXTINIT) & ~(CKMD_HFXTINIT_Q1CAP_M | CKMD_HFXTINIT_Q2CAP_M);
141  tmp |= (q1CapTrim << CKMD_HFXTINIT_Q1CAP_S) & CKMD_HFXTINIT_Q1CAP_M;
142  tmp |= (q2CapTrim << CKMD_HFXTINIT_Q2CAP_S) & CKMD_HFXTINIT_Q2CAP_M;
143  HWREG(CKMD_BASE + CKMD_O_HFXTINIT) = tmp;
144 }
145 
146 //*****************************************************************************
147 //
163 //
164 //*****************************************************************************
166 {
167  uint32_t tmp = HWREG(CKMD_BASE + CKMD_O_HFXTINIT) & ~CKMD_HFXTINIT_Q1CAP_M;
168  tmp |= (q1Cap << CKMD_HFXTINIT_Q1CAP_S) & CKMD_HFXTINIT_Q1CAP_M;
169  HWREG(CKMD_BASE + CKMD_O_HFXTINIT) = tmp;
170 }
171 
172 //*****************************************************************************
173 //
189 //
190 //*****************************************************************************
192 {
193  uint32_t tmp = HWREG(CKMD_BASE + CKMD_O_HFXTINIT) & ~CKMD_HFXTINIT_Q2CAP_M;
194  tmp |= (q2Cap << CKMD_HFXTINIT_Q2CAP_S) & CKMD_HFXTINIT_Q2CAP_M;
195  HWREG(CKMD_BASE + CKMD_O_HFXTINIT) = tmp;
196 }
197 
198 //*****************************************************************************
199 //
215 //
216 //*****************************************************************************
218 {
219  uint32_t tmp = HWREG(CKMD_BASE + CKMD_O_HFXTINIT) & ~CKMD_HFXTINIT_IREF_M;
220  tmp |= (iref << CKMD_HFXTINIT_IREF_S) & CKMD_HFXTINIT_IREF_M;
221  HWREG(CKMD_BASE + CKMD_O_HFXTINIT) = tmp;
222 }
223 
224 //*****************************************************************************
225 //
241 //
242 //*****************************************************************************
244 {
245  uint32_t tmp = HWREG(CKMD_BASE + CKMD_O_HFXTINIT) & ~CKMD_HFXTINIT_IDAC_M;
246  tmp |= (idac << CKMD_HFXTINIT_IDAC_S) & CKMD_HFXTINIT_IDAC_M;
247  HWREG(CKMD_BASE + CKMD_O_HFXTINIT) = tmp;
248 }
249 
250 //*****************************************************************************
251 //
267 //
268 //*****************************************************************************
269 __STATIC_INLINE void CKMDSetInitialAmplitudeThresholdTrim(uint32_t amplitudeThreshold)
270 {
271  uint32_t tmp = HWREG(CKMD_BASE + CKMD_O_HFXTINIT) & ~CKMD_HFXTINIT_AMPTHR_M;
272  tmp |= (amplitudeThreshold << CKMD_HFXTINIT_AMPTHR_S) & CKMD_HFXTINIT_AMPTHR_M;
273  HWREG(CKMD_BASE + CKMD_O_HFXTINIT) = tmp;
274 }
275 
276 //*****************************************************************************
277 //
285 //
286 //*****************************************************************************
288 {
289  return (HWREG(CKMD_BASE + CKMD_O_HFXTINIT) & CKMD_HFXTINIT_Q1CAP_M) >> CKMD_HFXTINIT_Q1CAP_S;
290 }
291 
292 //*****************************************************************************
293 //
301 //
302 //*****************************************************************************
304 {
305  return (HWREG(CKMD_BASE + CKMD_O_HFXTINIT) & CKMD_HFXTINIT_Q2CAP_M) >> CKMD_HFXTINIT_Q2CAP_S;
306 }
307 
308 //*****************************************************************************
309 //
317 //
318 //*****************************************************************************
320 {
321  return (HWREG(CKMD_BASE + CKMD_O_HFXTINIT) & CKMD_HFXTINIT_IREF_M) >> CKMD_HFXTINIT_IREF_S;
322 }
323 
324 //*****************************************************************************
325 //
333 //
334 //*****************************************************************************
336 {
337  return (HWREG(CKMD_BASE + CKMD_O_HFXTINIT) & CKMD_HFXTINIT_IDAC_M) >> CKMD_HFXTINIT_IDAC_S;
338 }
339 
340 //*****************************************************************************
341 //
349 //
350 //*****************************************************************************
352 {
353  return (HWREG(CKMD_BASE + CKMD_O_HFXTINIT) & CKMD_HFXTINIT_AMPTHR_M) >> CKMD_HFXTINIT_AMPTHR_S;
354 }
355 
356 //*****************************************************************************
357 //
374 //
375 //*****************************************************************************
376 __STATIC_INLINE void CKMDSetTargetCapTrim(uint32_t q1CapTrim, uint32_t q2CapTrim)
377 {
378  uint32_t tmp = HWREG(CKMD_BASE + CKMD_O_HFXTTARG) & ~(CKMD_HFXTTARG_Q1CAP_M | CKMD_HFXTTARG_Q2CAP_M);
379  tmp |= (q1CapTrim << CKMD_HFXTTARG_Q1CAP_S) & CKMD_HFXTTARG_Q1CAP_M;
380  tmp |= (q2CapTrim << CKMD_HFXTTARG_Q2CAP_S) & CKMD_HFXTTARG_Q2CAP_M;
381  HWREG(CKMD_BASE + CKMD_O_HFXTTARG) = tmp;
382 }
383 
384 //*****************************************************************************
385 //
399 //
400 //*****************************************************************************
402 {
403  uint32_t tmp = HWREG(CKMD_BASE + CKMD_O_HFXTTARG) & ~CKMD_HFXTTARG_Q1CAP_M;
404  tmp |= (q1Cap << CKMD_HFXTTARG_Q1CAP_S) & CKMD_HFXTTARG_Q1CAP_M;
405  HWREG(CKMD_BASE + CKMD_O_HFXTTARG) = tmp;
406 }
407 
408 //*****************************************************************************
409 //
423 //
424 //*****************************************************************************
426 {
427  uint32_t tmp = HWREG(CKMD_BASE + CKMD_O_HFXTTARG) & ~CKMD_HFXTTARG_Q2CAP_M;
428  tmp |= (q2Cap << CKMD_HFXTTARG_Q2CAP_S) & CKMD_HFXTTARG_Q2CAP_M;
429  HWREG(CKMD_BASE + CKMD_O_HFXTTARG) = tmp;
430 }
431 
432 //*****************************************************************************
433 //
447 //
448 //*****************************************************************************
450 {
451  uint32_t tmp = HWREG(CKMD_BASE + CKMD_O_HFXTTARG) & ~CKMD_HFXTTARG_IREF_M;
452  tmp |= (iref << CKMD_HFXTTARG_IREF_S) & CKMD_HFXTTARG_IREF_M;
453  HWREG(CKMD_BASE + CKMD_O_HFXTTARG) = tmp;
454 }
455 
456 //*****************************************************************************
457 //
471 //
472 //*****************************************************************************
474 {
475  uint32_t tmp = HWREG(CKMD_BASE + CKMD_O_HFXTTARG) & ~CKMD_HFXTTARG_IDAC_M;
476  tmp |= (idac << CKMD_HFXTTARG_IDAC_S) & CKMD_HFXTTARG_IDAC_M;
477  HWREG(CKMD_BASE + CKMD_O_HFXTTARG) = tmp;
478 }
479 
480 //*****************************************************************************
481 //
495 //
496 //*****************************************************************************
497 __STATIC_INLINE void CKMDSetTargetAmplitudeThresholdTrim(uint32_t amplitudeThreshold)
498 {
499  uint32_t tmp = HWREG(CKMD_BASE + CKMD_O_HFXTTARG) & ~CKMD_HFXTTARG_AMPTHR_M;
500  tmp |= (amplitudeThreshold << CKMD_HFXTTARG_AMPTHR_S) & CKMD_HFXTTARG_AMPTHR_M;
501  HWREG(CKMD_BASE + CKMD_O_HFXTTARG) = tmp;
502 }
503 
504 //*****************************************************************************
505 //
513 //
514 //*****************************************************************************
516 {
517  return (HWREG(CKMD_BASE + CKMD_O_HFXTTARG) & CKMD_HFXTTARG_Q1CAP_M) >> CKMD_HFXTTARG_Q1CAP_S;
518 }
519 
520 //*****************************************************************************
521 //
529 //
530 //*****************************************************************************
532 {
533  return (HWREG(CKMD_BASE + CKMD_O_HFXTTARG) & CKMD_HFXTTARG_Q2CAP_M) >> CKMD_HFXTTARG_Q2CAP_S;
534 }
535 
536 //*****************************************************************************
537 //
545 //
546 //*****************************************************************************
548 {
549  return (HWREG(CKMD_BASE + CKMD_O_HFXTTARG) & CKMD_HFXTTARG_IREF_M) >> CKMD_HFXTTARG_IREF_S;
550 }
551 
552 //*****************************************************************************
553 //
561 //
562 //*****************************************************************************
564 {
565  return (HWREG(CKMD_BASE + CKMD_O_HFXTTARG) & CKMD_HFXTTARG_IDAC_M) >> CKMD_HFXTTARG_IDAC_S;
566 }
567 
568 //*****************************************************************************
569 //
577 //
578 //*****************************************************************************
580 {
581  return (HWREG(CKMD_BASE + CKMD_O_HFXTTARG) & CKMD_HFXTTARG_AMPTHR_M) >> CKMD_HFXTTARG_AMPTHR_S;
582 }
583 
584 //*****************************************************************************
585 //
589 //
590 //*****************************************************************************
592 {
593  // Only App trims revision 5 and newer has a ppmRtn field. For older
594  // revisions use a default value of 20 (equivalent to 600ppm)
595  uint8_t ppmRtn = 20;
596  if (fcfg->appTrims.revision >= 0x5)
597  {
598  ppmRtn = fcfg->appTrims.cc23x0r5.misc0.lfoscPpmRtn;
599  }
600 
601  // The ppmTempMid field uses units of 30ppm, convert to ppm
602  return ppmRtn * 30;
603 }
604 
605 //*****************************************************************************
606 //
616 //
617 //*****************************************************************************
619 {
620  // Only App trims revision 5 and newer has a ppmTempMid field. For older
621  // revisions use a default value of 20 (equivalent to 260ppm/C)
622  uint8_t ppmTempMid = 20;
623  if (fcfg->appTrims.revision >= 0x5)
624  {
625  ppmTempMid = fcfg->appTrims.cc23x0r5.misc0.lfoscPpmTempMid;
626  }
627 
628  // The ppmTempMid field uses units of 13ppm/C, convert to ppm/C
629  return ppmTempMid * 13;
630 }
631 
632 //*****************************************************************************
633 //
644 //
645 //*****************************************************************************
647 {
648  // Only App trims revision 5 and newer has a ppmTempExt field. For older
649  // revisions use a default value of 20 (equivalent to 700ppm/C)
650  uint8_t ppmTempExt = 20;
651  if (fcfg->appTrims.revision >= 0x5)
652  {
653  ppmTempExt = fcfg->appTrims.cc23x0r5.misc0.lfoscPpmTempExt;
654  }
655 
656  // The ppmTempExt field uses units of 35ppm/C, convert to ppm/C
657  return ppmTempExt * 35;
658 }
659 
660 //*****************************************************************************
661 //
666 //
667 //*****************************************************************************
669 {
670  // Unlock the Watchdog
671  HWREG(CKMD_BASE + CKMD_O_WDTLOCK) = CKMD_WATCHDOG_UNLOCK;
672 
673  // Make sure the Watchdog is unlocked before continuing
674  while (HWREG(CKMD_BASE + CKMD_O_WDTLOCK) == 1) {}
675 }
676 
677 //*****************************************************************************
678 //
680 //
681 //*****************************************************************************
683 {
684  HWREG(CKMD_BASE + CKMD_O_WDTLOCK) = 0x0;
685 }
686 
687 //*****************************************************************************
688 //
695 //
696 //*****************************************************************************
698 {
699  HWREG(CKMD_BASE + CKMD_O_WDTCNT) = value;
700 }
701 
702 //*****************************************************************************
703 //
710 //
711 //*****************************************************************************
712 __STATIC_INLINE void CKMDSetWatchdogDebugConfig(bool stopWhenCpuIsHalted)
713 {
714  HWREG(CKMD_BASE + CKMD_O_WDTTEST) = stopWhenCpuIsHalted ? CKMD_WDTTEST_STALLEN_EN : CKMD_WDTTEST_STALLEN_DIS;
715 }
716 
717 //*****************************************************************************
718 //
719 // Mark the end of the C bindings section for C++ compilers.
720 //
721 //*****************************************************************************
722 #ifdef __cplusplus
723 }
724 #endif
725 
726 //*****************************************************************************
727 //
731 //
732 //*****************************************************************************
733 
734 #endif // __CKMD_H__
__STATIC_INLINE void CKMDSetTargetQ1CapTrim(uint32_t q1Cap)
Sets target HFXT Q1 capacitor ramp trim.
Definition: ckmd.h:401
__STATIC_INLINE void CKMDSetTargetIrefTrim(uint32_t iref)
Sets target HFXT IREF ramp trim.
Definition: ckmd.h:449
__STATIC_INLINE uint32_t CKMDGetTargetAmplitudeThresholdTrim(void)
Gets target HFXT amplitude threshold ramp trim.
Definition: ckmd.h:579
__STATIC_INLINE uint_least16_t CKMDGetLfoscMidTempCoefficientPpmPerC(void)
Gets the the worst-case LFOSC temperature coefficient in the "middle" temperature range...
Definition: ckmd.h:618
__STATIC_INLINE void CKMDSetTargetIdacTrim(uint32_t idac)
Sets target HFXT IDAC ramp trim.
Definition: ckmd.h:473
__STATIC_INLINE uint32_t CKMDGetTargetIdacTrim(void)
Gets target HFXT IDAC ramp trim.
Definition: ckmd.h:563
__STATIC_INLINE void CKMDSetInitialCapTrim(uint32_t q1CapTrim, uint32_t q2CapTrim)
Sets initial HFXT capacitor ramp trims.
Definition: ckmd.h:138
__STATIC_INLINE void CKMDSetInitialQ1CapTrim(uint32_t q1Cap)
Sets initial HFXT Q1 capacitor ramp trim.
Definition: ckmd.h:165
__STATIC_INLINE void CKMDSetInitialAmplitudeThresholdTrim(uint32_t amplitudeThreshold)
Sets initial HFXT amplitude threshold ramp trim.
Definition: ckmd.h:269
__STATIC_INLINE void CKMDEnableHighPerformanceClockBuffer(void)
Enable high performance clock buffer.
Definition: ckmd.h:103
__STATIC_INLINE void CKMDSetWatchdogDebugConfig(bool stopWhenCpuIsHalted)
Configure if the Watchdog should stop when the CPU is halted by a debugger.
Definition: ckmd.h:712
__STATIC_INLINE void CKMDSetInitialQ2CapTrim(uint32_t q2Cap)
Sets initial HFXT Q2 capacitor ramp trim.
Definition: ckmd.h:191
__STATIC_INLINE uint32_t CKMDGetTargetQ2CapTrim(void)
Gets target HFXT Q2 capacitor ramp trim.
Definition: ckmd.h:531
__STATIC_INLINE uint32_t CKMDGetInitialQ1CapTrim(void)
Gets initial HFXT Q1 capacitor ramp trim.
Definition: ckmd.h:287
__STATIC_INLINE uint32_t CKMDGetInitialIdacTrim(void)
Gets initial HFXT IDAC ramp trim.
Definition: ckmd.h:335
__STATIC_INLINE void CKMDUnlockWatchdog(void)
Unlock write access to the Watchdog.
Definition: ckmd.h:668
#define CKMD_WATCHDOG_UNLOCK
Watchdog unlocking value.
Definition: ckmd.h:90
__STATIC_INLINE uint_least16_t CKMDGetLfoscExtTempCoefficientPpmPerC(void)
Gets the the worst-case LFOSC temperature coefficient in the "extended" temperature range...
Definition: ckmd.h:646
__STATIC_INLINE void CKMDSetTargetAmplitudeThresholdTrim(uint32_t amplitudeThreshold)
Sets target HFXT amplitude threshold ramp trim.
Definition: ckmd.h:497
__STATIC_INLINE uint32_t CKMDGetTargetQ1CapTrim(void)
Gets target HFXT Q1 capacitor ramp trim.
Definition: ckmd.h:515
__STATIC_INLINE void CKMDLockWatchdog(void)
Lock write access to the Watchdog.
Definition: ckmd.h:682
__STATIC_INLINE void CKMDSetWatchdogCounter(uint32_t value)
Set watchdog counter value.
Definition: ckmd.h:697
__STATIC_INLINE void CKMDSetTargetCapTrim(uint32_t q1CapTrim, uint32_t q2CapTrim)
Sets target HFXT capacitor ramp trims.
Definition: ckmd.h:376
__STATIC_INLINE uint32_t CKMDGetInitialIrefTrim(void)
Gets initial HFXT IREF ramp trim.
Definition: ckmd.h:319
__STATIC_INLINE void CKMDDisableHighPerformanceClockBuffer(void)
Disable high performance clock buffer.
Definition: ckmd.h:113
__STATIC_INLINE void CKMDSetInitialIrefTrim(uint32_t iref)
Sets initial HFXT IREF ramp trim.
Definition: ckmd.h:217
#define __STATIC_INLINE
Definition: cmsis_gcc.h:47
__STATIC_INLINE uint32_t CKMDGetInitialAmplitudeThresholdTrim(void)
Gets initial HFXT amplitude threshold ramp trim.
Definition: ckmd.h:351
__STATIC_INLINE void CKMDSetTargetQ2CapTrim(uint32_t q2Cap)
Sets target HFXT Q2 capacitor ramp trim.
Definition: ckmd.h:425
__STATIC_INLINE void CKMDSetInitialIdacTrim(uint32_t idac)
Sets initial HFXT IDAC ramp trim.
Definition: ckmd.h:243
__STATIC_INLINE uint32_t CKMDGetTargetIrefTrim(void)
Gets target HFXT IREF ramp trim.
Definition: ckmd.h:547
__STATIC_INLINE uint_least16_t CKMDGetLfoscRtnPpm(void)
Gets the worst-case LFOSC frequency jump due to RTN.
Definition: ckmd.h:591
__STATIC_INLINE uint32_t CKMDGetInitialQ2CapTrim(void)
Gets initial HFXT Q2 capacitor ramp trim.
Definition: ckmd.h:303