1 /******************************************************************************
2 * Filename: osc.h
3 *
4 * Description: Defines and prototypes for the system oscillator control.
5 *
6 * Copyright (c) 2015 - 2022, Texas Instruments Incorporated
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * 1) Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * 2) Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 *
19 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
20 * be used to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************/
36
37 //*****************************************************************************
38 //
39 //! \addtogroup system_control_group
40 //! @{
41 //! \addtogroup osc_api
42 //! @{
43 //
44 //*****************************************************************************
45
46 #ifndef __OSC_H__
47 #define __OSC_H__
48
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include "../inc/hw_aon_pmctl.h"
63 #include "../inc/hw_ccfg.h"
64 #include "../inc/hw_fcfg1.h"
65 #include "../inc/hw_types.h"
66 #include "../inc/hw_memmap.h"
67 #include "../inc/hw_ddi.h"
68 #include "../inc/hw_ddi_0_osc.h"
69 #include "rom.h"
70 #include "ddi.h"
71 #include "debug.h"
72
73 //*****************************************************************************
74 //
75 // Support for DriverLib in ROM:
76 // This section renames all functions that are not "static inline", so that
77 // calling these functions will default to implementation in flash. At the end
78 // of this file a second renaming will change the defaults to implementation in
79 // ROM for available functions.
80 //
81 // To force use of the implementation in flash, e.g. for debugging:
82 // - Globally: Define DRIVERLIB_NOROM at project level
83 // - Per function: Use prefix "NOROM_" when calling the function
84 //
85 //*****************************************************************************
86 #if !defined(DOXYGEN)
87 #define OSCClockSourceSet NOROM_OSCClockSourceSet
88 #define OSCClockSourceGet NOROM_OSCClockSourceGet
89 #define OSCHF_GetStartupTime NOROM_OSCHF_GetStartupTime
90 #define OSCHF_TurnOnXosc NOROM_OSCHF_TurnOnXosc
91 #define OSCHF_AttemptToSwitchToXosc NOROM_OSCHF_AttemptToSwitchToXosc
92 #define OSCHF_SwitchToRcOscTurnOffXosc NOROM_OSCHF_SwitchToRcOscTurnOffXosc
93 #define OSCHF_DebugGetCrystalAmplitude NOROM_OSCHF_DebugGetCrystalAmplitude
94 #define OSCHF_DebugGetExpectedAverageCrystalAmplitude NOROM_OSCHF_DebugGetExpectedAverageCrystalAmplitude
95 #define OSCHF_DebugGetCrystalStartupTime NOROM_OSCHF_DebugGetCrystalStartupTime
96 #define OSC_HPOSCInitializeFrequencyOffsetParameters NOROM_OSC_HPOSCInitializeFrequencyOffsetParameters
97 #define OSC_HPOSC_Debug_InitFreqOffsetParams NOROM_OSC_HPOSC_Debug_InitFreqOffsetParams
98 #define OSC_HPOSCInitializeSingleInsertionFreqOffsParams NOROM_OSC_HPOSCInitializeSingleInsertionFreqOffsParams
99 #define OSC_HPOSCRelativeFrequencyOffsetGet NOROM_OSC_HPOSCRelativeFrequencyOffsetGet
100 #define OSC_AdjustXoscHfCapArray NOROM_OSC_AdjustXoscHfCapArray
101 #define OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert NOROM_OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert
102 #define OSC_HPOSCRtcCompensate NOROM_OSC_HPOSCRtcCompensate
103 #endif
104
105 //*****************************************************************************
106 //
107 // Defines for the High Frequency XTAL Power mode
108 //
109 //*****************************************************************************
110 #define LOW_POWER_XOSC 1
111 #define HIGH_POWER_XOSC 0
112
113 //*****************************************************************************
114 //
115 // Defines for the High Frequency XTAL Power mode
116 //
117 //*****************************************************************************
118 #define OSC_SRC_CLK_HF 0x00000001
119 #define OSC_SRC_CLK_LF 0x00000004
120
121 #define OSC_RCOSC_HF 0x00000000
122 #define OSC_XOSC_HF 0x00000001
123 #define OSC_RCOSC_LF 0x00000002
124 #define OSC_XOSC_LF 0x00000003
125
126 #define SCLK_HF_RCOSC_HF 0
127 #define SCLK_HF_XOSC_HF 1
128
129 #define SCLK_LF_FROM_RCOSC_HF 0
130 #define SCLK_LF_FROM_XOSC_HF 1
131 #define SCLK_LF_FROM_RCOSC_LF 2
132 #define SCLK_LF_FROM_XOSC_LF 3
133
134 //*****************************************************************************
135 //
136 // API Functions and prototypes
137 //
138 //*****************************************************************************
139
140 //*****************************************************************************
141 //
142 //! \brief Set Power Mode for High Frequency XTAL Oscillator.
143 //!
144 //! \param ui32Mode is the power mode for the HF XTAL.
145 //! - \ref LOW_POWER_XOSC
146 //! - \ref HIGH_POWER_XOSC
147 //!
148 //! \return None
149 //
150 //*****************************************************************************
151 __STATIC_INLINE void
OSCXHfPowerModeSet(uint32_t ui32Mode)152 OSCXHfPowerModeSet(uint32_t ui32Mode)
153 {
154 // Check the arguments.
155 ASSERT((ui32Mode == LOW_POWER_XOSC) ||
156 (ui32Mode == HIGH_POWER_XOSC));
157
158 // Change the power mode.
159 DDI16BitWrite(AUX_DDI0_OSC_BASE, DDI_0_OSC_O_CTL0, DDI_0_OSC_CTL0_XOSC_HF_POWER_MODE,
160 ui32Mode);
161 }
162
163 //*****************************************************************************
164 //
165 //! \brief Enables OSC clock loss event detection.
166 //!
167 //! Enables the clock loss event flag to be raised if a clock loss is detected.
168 //!
169 //! \note OSC clock loss event must be disabled before SCLK_LF clock source is
170 //! changed (by calling \ref OSCClockSourceSet()) and remain disabled until the
171 //! change is confirmed (by calling \ref OSCClockSourceGet()).
172 //!
173 //! \return None
174 //!
175 //! \sa \ref OSCClockLossEventDisable()
176 //
177 //*****************************************************************************
178 __STATIC_INLINE void
OSCClockLossEventEnable(void)179 OSCClockLossEventEnable( void )
180 {
181 DDI16BitfieldWrite( AUX_DDI0_OSC_BASE, DDI_0_OSC_O_CTL0,
182 DDI_0_OSC_CTL0_CLK_LOSS_EN_M,
183 DDI_0_OSC_CTL0_CLK_LOSS_EN_S, 1 );
184 }
185
186 //*****************************************************************************
187 //
188 //! \brief Disables OSC clock loss event detection.
189 //!
190 //! Disabling the OSC clock loss event does also clear the clock loss event flag.
191 //!
192 //! \note OSC clock loss event must be disabled before SCLK_LF clock source is
193 //! changed (by calling \ref OSCClockSourceSet()) and remain disabled until the
194 //! change is confirmed (by calling \ref OSCClockSourceGet()).
195 //!
196 //! \return None
197 //!
198 //! \sa \ref OSCClockLossEventEnable()
199 //
200 //*****************************************************************************
201 __STATIC_INLINE void
OSCClockLossEventDisable(void)202 OSCClockLossEventDisable( void )
203 {
204 DDI16BitfieldWrite( AUX_DDI0_OSC_BASE, DDI_0_OSC_O_CTL0,
205 DDI_0_OSC_CTL0_CLK_LOSS_EN_M,
206 DDI_0_OSC_CTL0_CLK_LOSS_EN_S, 0 );
207 }
208
209 //*****************************************************************************
210 //
211 //! \brief Configure the oscillator input to the a source clock.
212 //!
213 //! Use this function to set the oscillator source for one or more of the
214 //! system source clocks.
215 //!
216 //! When selecting the high frequency clock source (OSC_SRC_CLK_HF), this function will not do
217 //! the actual switch. Enabling the high frequency XTAL can take several hundred
218 //! micro seconds, so the actual switch is done in a separate function, \ref OSCHfSourceSwitch(),
219 //! leaving System CPU free to perform other tasks as the XTAL starts up.
220 //!
221 //! \note The High Frequency (\ref OSC_SRC_CLK_HF) can only be derived from the
222 //! high frequency oscillator. The Low Frequency source clock (\ref OSC_SRC_CLK_LF)
223 //! can be derived from all 4 oscillators.
224 //!
225 //! \note If enabling \ref OSC_XOSC_LF it is not safe to go to powerdown/shutdown
226 //! until the LF clock is running which can be checked using \ref OSCClockSourceGet().
227 //!
228 //! \note Clock loss reset generation must be disabled before SCLK_LF (\ref OSC_SRC_CLK_LF)
229 //! clock source is changed and remain disabled until the change is confirmed.
230 //!
231 //! \param ui32SrcClk is the source clocks to configure.
232 //! - \ref OSC_SRC_CLK_HF
233 //! - \ref OSC_SRC_CLK_LF
234 //! \param ui32Osc is the oscillator that drives the source clock.
235 //! - \ref OSC_RCOSC_HF
236 //! - \ref OSC_XOSC_HF
237 //! - \ref OSC_RCOSC_LF (only when ui32SrcClk is \ref OSC_SRC_CLK_LF)
238 //! - \ref OSC_XOSC_LF (only when ui32SrcClk is \ref OSC_SRC_CLK_LF)
239 //!
240 //! \sa \ref OSCClockSourceGet(), \ref OSCHfSourceSwitch()
241 //!
242 //! \return None
243 //
244 //*****************************************************************************
245 extern void OSCClockSourceSet(uint32_t ui32SrcClk, uint32_t ui32Osc);
246
247 //*****************************************************************************
248 //
249 //! \brief Get the source clock settings.
250 //!
251 //! Use this function to get the oscillator source for one of the system source
252 //! clocks.
253 //!
254 //! \param ui32SrcClk is the source clock to check.
255 //! - \ref OSC_SRC_CLK_HF
256 //! - \ref OSC_SRC_CLK_LF
257 //!
258 //! \return Returns the type of oscillator that drives the clock source.
259 //! - \ref OSC_RCOSC_HF
260 //! - \ref OSC_XOSC_HF
261 //! - \ref OSC_RCOSC_LF
262 //! - \ref OSC_XOSC_LF
263 //!
264 //! \sa \ref OSCClockSourceSet(), \ref OSCHfSourceSwitch()
265 //
266 //*****************************************************************************
267 extern uint32_t OSCClockSourceGet(uint32_t ui32SrcClk);
268
269 //*****************************************************************************
270 //
271 //! \brief Check if the HF clock source is ready to be switched.
272 //!
273 //! If a request to switch the HF clock source has been made, this function
274 //! can be used to check if the clock source is ready to be switched.
275 //!
276 //! Once the HF clock source is ready the switch can be performed by calling
277 //! the \ref OSCHfSourceSwitch()
278 //!
279 //! \return Returns status of HF clock source:
280 //! - \c true : HF clock source is ready.
281 //! - \c false : HF clock source is \b not ready.
282 //
283 //*****************************************************************************
284 __STATIC_INLINE bool
OSCHfSourceReady(void)285 OSCHfSourceReady(void)
286 {
287 // Return the readiness of the HF clock source
288 return (DDI16BitfieldRead(AUX_DDI0_OSC_BASE, DDI_0_OSC_O_STAT0,
289 DDI_0_OSC_STAT0_PENDINGSCLKHFSWITCHING_M,
290 DDI_0_OSC_STAT0_PENDINGSCLKHFSWITCHING_S)) ?
291 true : false;
292 }
293
294 //*****************************************************************************
295 //
296 //! \brief Switch the high frequency clock.
297 //!
298 //! When switching the HF clock source the clock period might be prolonged
299 //! leaving the clock 'stuck-at' high or low for a few cycles. To ensure that
300 //! this does not coincide with a read access to the Flash, potentially
301 //! freezing the device, the HF clock source switch must be executed from ROM.
302 //!
303 //! \note This function will not return until the clock source has been
304 //! switched. It is left to the programmer to ensure, that there is a pending
305 //! request for a HF clock source switch before this function is called.
306 //!
307 //! \return None
308 //!
309 //! \sa \ref OSCClockSourceSet()
310 //
311 //*****************************************************************************
312 __STATIC_INLINE void
OSCHfSourceSwitch(void)313 OSCHfSourceSwitch(void)
314 {
315 // Read target clock (lower half of the 32-bit CTL0 register)
316 uint16_t hfSrc = HWREGH(AUX_DDI0_OSC_BASE + DDI_0_OSC_O_CTL0) & DDI_0_OSC_CTL0_SCLK_HF_SRC_SEL_M;
317
318 // If target clock source is RCOSC, change clock source for DCDC to RCOSC
319 if(hfSrc == DDI_0_OSC_CTL0_SCLK_HF_SRC_SEL_RCOSC)
320 {
321 // Force DCDC to use RCOSC before switching SCLK_HF to RCOSC
322 HWREG(AUX_DDI0_OSC_BASE + DDI_O_MASK16B + (DDI_0_OSC_O_CTL0 << 1) + 4) = DDI_0_OSC_CTL0_CLK_DCDC_SRC_SEL_M | (DDI_0_OSC_CTL0_CLK_DCDC_SRC_SEL_M >> 16);
323 // Dummy read to ensure that the write has propagated
324 HWREGH(AUX_DDI0_OSC_BASE + DDI_0_OSC_O_CTL0);
325 }
326
327 // Switch the HF clock source
328 HapiHFSourceSafeSwitch();
329
330 // If target clock source is XOSC, change clock source for DCDC to "auto"
331 if(hfSrc == DDI_0_OSC_CTL0_SCLK_HF_SRC_SEL_XOSC)
332 {
333 // Set DCDC clock source back to "auto" after SCLK_HF was switched to XOSC
334 HWREG(AUX_DDI0_OSC_BASE + DDI_O_MASK16B + (DDI_0_OSC_O_CTL0 << 1) + 4) = DDI_0_OSC_CTL0_CLK_DCDC_SRC_SEL_M;
335 }
336 }
337
338 //*****************************************************************************
339 //
340 //! \brief Identifies if HPOSC is enabled.
341 //!
342 //! This function checks if the device supports HPOSC and that HPOSC is selected
343 //! as HF oscillator for use when the radio is active.
344 //!
345 //! \return Returns status of HPOSC functionality:
346 //! - \c true : HPOSC is enabled.
347 //! - \c false : HPOSC is not enabled.
348 //
349 //*****************************************************************************
350 __STATIC_INLINE bool
OSC_IsHPOSCEnabled(void)351 OSC_IsHPOSCEnabled(void)
352 {
353 bool enabled = false;
354
355 if((( HWREG(CCFG_BASE + CCFG_O_MODE_CONF) & CCFG_MODE_CONF_XOSC_FREQ_M) == CCFG_MODE_CONF_XOSC_FREQ_HPOSC) &&
356 (( HWREG(FCFG1_BASE + FCFG1_O_OSC_CONF) & FCFG1_OSC_CONF_HPOSC_OPTION) == 0))
357 {
358 enabled = true;
359 }
360
361 return (enabled);
362 }
363
364 //*****************************************************************************
365 //
366 //! \brief Identifies if HPOSC is enabled and that SCLK_LF is derived from XOSC_HF.
367 //!
368 //! This function checks if the device supports HPOSC and that HPOSC is selected
369 //! as HF oscillator for use when the radio is active and also that SCLK_LF is
370 //! derived from XOSC_HF.
371 //!
372 //! \return Returns status of HPOSC and SCLK_LF configuration:
373 //! - \c true : HPOSC is enabled and SCLK_LF is derived from XOSC_HF.
374 //! - \c false : Either HPOSC not enabled or SCLK_LF is not derived from XOSC_HF.
375 //
376 //*****************************************************************************
377 __STATIC_INLINE bool
OSC_IsHPOSCEnabledWithHfDerivedLfClock(void)378 OSC_IsHPOSCEnabledWithHfDerivedLfClock(void)
379 {
380 bool enabled = false;
381
382 // Check configuration by reading lower half of the 32-bit CTL0 register
383 uint16_t regVal = HWREGH(AUX_DDI0_OSC_BASE + DDI_0_OSC_O_CTL0);
384 if( ( ( regVal & DDI_0_OSC_CTL0_SCLK_LF_SRC_SEL_M ) == DDI_0_OSC_CTL0_SCLK_LF_SRC_SEL_XOSCHFDLF ) &&
385 ( ( regVal & DDI_0_OSC_CTL0_HPOSC_MODE_EN_M ) == DDI_0_OSC_CTL0_HPOSC_MODE_EN ) )
386 {
387 enabled = true;
388 }
389
390 return (enabled);
391 }
392
393 //*****************************************************************************
394 //
395 //! \brief Returns maximum startup time (in microseconds) of XOSC_HF.
396 //!
397 //! The startup time depends on several factors. This function calculates the
398 //! maximum startup time based on statistical information.
399 //!
400 //! \param timeUntilWakeupInMs indicates how long time (milliseconds) to the
401 //! startup will occur.
402 //!
403 //! \return Time margin to use in microseconds.
404 //
405 //*****************************************************************************
406 extern uint32_t OSCHF_GetStartupTime( uint32_t timeUntilWakeupInMs );
407
408 //*****************************************************************************
409 //
410 //! \brief Turns on XOSC_HF (but without switching to XOSC_HF).
411 //!
412 //! This function simply indicates the need for XOSC_HF to the hardware which
413 //! initiates the XOSC_HF startup.
414 //!
415 //! \return None
416 //
417 //*****************************************************************************
418 extern void OSCHF_TurnOnXosc( void );
419
420 //*****************************************************************************
421 //
422 //! \brief Switch to XOSC_HF if XOSC_HF is ready.
423 //!
424 //! This is a non-blocking function checking if the XOSC_HF is ready and
425 //! performs the switching if ready. The function is somewhat blocking in the
426 //! case where switching is performed.
427 //!
428 //! \return Returns status of the XOSC_HF switching:
429 //! - \c true : Switching to XOSC_HF has occurred.
430 //! - \c false : Switching has not occurred.
431 //
432 //*****************************************************************************
433 extern bool OSCHF_AttemptToSwitchToXosc( void );
434
435 //*****************************************************************************
436 //
437 //! \brief Switch to RCOSC_HF and turn off XOSC_HF.
438 //!
439 //! This operation takes approximately 50 microseconds (can be shorter if
440 //! RCOSC_HF already was running).
441 //!
442 //! \return None
443 //
444 //*****************************************************************************
445 extern void OSCHF_SwitchToRcOscTurnOffXosc( void );
446
447 //*****************************************************************************
448 //
449 //! \brief Get crystal amplitude (assuming crystal is running).
450 //!
451 //! \note This is a debug function only.
452 //! It is hence not recommended to call this function in normal operation.
453 //!
454 //! This function uses an on-chip ADC and peak detector for reading the crystal
455 //! amplitude. The measurement time is set to 4 milliseconds and this function
456 //! does not return before the measurement is done.
457 //!
458 //! Expected value is \ref OSCHF_DebugGetExpectedAverageCrystalAmplitude +/- 50 millivolt.
459 //!
460 //! \return Returns crystal amplitude in millivolt.
461 //!
462 //! \sa OSCHF_DebugGetExpectedAverageCrystalAmplitude()
463 //
464 //*****************************************************************************
465 extern uint32_t OSCHF_DebugGetCrystalAmplitude( void );
466
467 //*****************************************************************************
468 //
469 //! \brief Get the expected average crystal amplitude.
470 //!
471 //! \note This is a debug function only.
472 //! It is hence not recommended to call this function in normal operation.
473 //!
474 //! This function read the configured high and low thresholds and returns
475 //! the mean value converted to millivolt.
476 //!
477 //! \return Returns expected average crystal amplitude in millivolt.
478 //!
479 //! \sa OSCHF_DebugGetCrystalAmplitude()
480 //
481 //*****************************************************************************
482 extern uint32_t OSCHF_DebugGetExpectedAverageCrystalAmplitude( void );
483
484 //*****************************************************************************
485 //
486 //! \brief Measure the crystal startup time.
487 //!
488 //! \note This is a debug function that should not be needed in normal operation.
489 //!
490 //! This function assumes that the chip is running on RCOSC_HF when called.
491 //! It then switches to XOSC_HF while measuring number of LF-clock edges
492 //! before XOSC_HF has started and are ready to be used.
493 //! After that, the function switches back to RCOSC_HF and returns number of LF-edges found.
494 //!
495 //! The length in time between the LF clock edges is approximately 15 microseconds.
496 //! Or more exactly: LF_clock_edges / ( 32768 * 2 ) seconds.
497 //!
498 //! Please note that the startup time, in addition to the crystal itself also can vary depending
499 //! on the time since the crystal was stopped and the frequency of the RCOSC_HF oscillator.
500 //! Calling this function intensively will show a shorter startup time than in typical use cases.
501 //! When running with TI-RTOS there is a background task (optional but default on) adjusting RCOSC_HF
502 //! to be as equal as possible to the crystal frequency, giving the shortest possible startup time.
503 //!
504 //! \return Returns number of LF-clock edges from starting the crystal until it's ready to be used.
505 //
506 //*****************************************************************************
507 extern uint32_t OSCHF_DebugGetCrystalStartupTime( void );
508
509 //*****************************************************************************
510 //
511 //! \brief HPOSC initialization function. Must always be called before using HPOSC.
512 //!
513 //! Calculates the fitting curve parameters (polynomials) to be used by the
514 //! HPOSC temperature compensation.
515 //!
516 //! \return None
517 //!
518 //! \sa OSC_HPOSC_Debug_InitFreqOffsetParams(), OSC_HPOSCInitializeSingleInsertionFreqOffsParams()
519 //
520 //*****************************************************************************
521 extern void OSC_HPOSCInitializeFrequencyOffsetParameters( void );
522
523 //*****************************************************************************
524 //
525 //! \brief Data structure for experimental HPOSC polynomials calculation.
526 //!
527 //! The structure of the meas_1, meas_2 and meas_3 parameter is
528 //! as defined in FCFG1_O_HPOSC_MEAS_1, 2 and 3.
529 //!
530 //! \sa OSC_HPOSC_Debug_InitFreqOffsetParams()
531 //
532 //*****************************************************************************
533 typedef struct {
534 uint32_t meas_1 ; //!< Measurement set 1 (typically at room temp)
535 uint32_t meas_2 ; //!< Measurement set 2 (typically at high temp)
536 uint32_t meas_3 ; //!< Measurement set 3 (typically at low temp)
537 int32_t offsetD1 ; //!< Offset to measurement set 1
538 int32_t offsetD2 ; //!< Offset to measurement set 2
539 int32_t offsetD3 ; //!< Offset to measurement set 3
540 int32_t polyP3 ; //!< The P3 polynomial
541 } HposcDebugData_t;
542
543 //*****************************************************************************
544 //
545 //! \brief Debug function to calculate the HPOSC polynomials for experimental data sets.
546 //!
547 //! \param pDebugData pointer to the input data collected in \ref HposcDebugData_t
548 //!
549 //! \return None
550 //!
551 //! \sa OSC_HPOSCInitializeFrequencyOffsetParameters()
552 //
553 //*****************************************************************************
554 extern void OSC_HPOSC_Debug_InitFreqOffsetParams( HposcDebugData_t * pDebugData );
555
556 //*****************************************************************************
557 //
558 //! \brief Special HPOSC initialization function for single temperature compensation.
559 //!
560 //! Used when a single temperature offset measurement is available.
561 //! This is espesially designed to get a better crystal performance (SW TCXO) on the SiP module
562 //! but can also be usful to get better crystal performance over the entire temperature range on a standard design as well.
563 //!
564 //! \return None
565 //!
566 //! \sa OSC_HPOSCInitializeFrequencyOffsetParameters()
567 //
568 //*****************************************************************************
569 extern void OSC_HPOSCInitializeSingleInsertionFreqOffsParams( uint32_t measFieldAddress );
570
571 //*****************************************************************************
572 //
573 //! \brief Calculate the temperature dependent relative frequency offset of HPOSC
574 //!
575 //! The HPOSC (High Precision Oscillator) frequency will vary slightly with chip temperature.
576 //! The frequency offset from the nominal value can be predicted based on
577 //! second order linear interpolation using coefficients measured in chip
578 //! production and stored as factory configuration parameters.
579 //!
580 //! This function calculates the relative frequency offset, defined as:
581 //! <pre>
582 //! F_HPOSC = F_nom * (1 + d/(2^22))
583 //! </pre>
584 //! where
585 //! - F_HPOSC is the current HPOSC frequency.
586 //! - F_nom is the nominal oscillator frequency, assumed to be 48.000 MHz.
587 //! - d is the relative frequency offset (the value returned).
588 //!
589 //! By knowing the relative frequency offset it is then possible to compensate
590 //! any timing related values accordingly.
591 //!
592 //! \param tempDegC is the chip temperature in degrees Celsius. Use the
593 //! function \ref AONBatMonTemperatureGetDegC() to get current chip temperature.
594 //!
595 //! \return Returns the relative frequency offset parameter d.
596 //!
597 //! \sa OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert(), AONBatMonTemperatureGetDegC()
598 //
599 //*****************************************************************************
600 extern int32_t OSC_HPOSCRelativeFrequencyOffsetGet( int32_t tempDegC );
601
602 //*****************************************************************************
603 //
604 //! \brief Adjust the XOSC HF cap array relative to the factory setting
605 //!
606 //! The cap array factory setting (FCFG) can be converted to a number in the range 0 - 63.
607 //! Both this function and the customer configuration (CCFG) setting can apply a delta to the FCFG setting.
608 //! The CCFG setting is automatically applied at boot time (See ../startup_files/ccfg.c).
609 //! Calling this function will discard the CCFG setting and adjust relative to the FCFG setting.
610 //!
611 //! \note Adjusted value will not take effect before XOSC_HF is stopped and restarted
612 //!
613 //! \param capArrDelta specifies number of step to adjust the cap array relative to the factory setting.
614 //!
615 //! \return None
616 //
617 //*****************************************************************************
618 extern void OSC_AdjustXoscHfCapArray( int32_t capArrDelta );
619
620 //*****************************************************************************
621 //
622 //! \brief Converts the relative frequency offset of HPOSC to the RF Core parameter format.
623 //!
624 //! The HPOSC (High Precision Oscillator) clock is used by the RF Core.
625 //! To compensate for a frequency offset in the frequency of the clock source,
626 //! a frequency offset parameter can be provided as part of the radio configuration
627 //! override setting list to enable compensation of the RF synthesizer frequency,
628 //! symbol timing, and radio timer to still achieve correct frequencies.
629 //!
630 //! The RF Core takes a relative frequency offset parameter defined differently
631 //! compared to the relative frequency offset parameter returned from function
632 //! \ref OSC_HPOSCRelativeFrequencyOffsetGet() and thus needs to be converted:
633 //! <pre>
634 //! F_nom = F_HPOSC * (1 + RfCoreRelFreqOffset/(2^22))
635 //! </pre>
636 //! where
637 //! - F_nom is the nominal oscillator frequency, assumed to be 48.000 MHz.
638 //! - F_HPOSC is the current HPOSC frequency.
639 //! - RfCoreRelFreqOffset is the relative frequency offset in the "RF Core" format (the value returned).
640 //!
641 //! \param HPOSC_RelFreqOffset is the relative frequency offset parameter d returned from \ref OSC_HPOSCRelativeFrequencyOffsetGet()
642 //!
643 //! \return Returns the relative frequency offset in RF Core format.
644 //!
645 //! \sa OSC_HPOSCRelativeFrequencyOffsetGet()
646 //
647 //*****************************************************************************
648 extern int16_t OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert( int32_t HPOSC_RelFreqOffset );
649
650 //*****************************************************************************
651 //
652 //! \brief Compensate the RTC increment based on the relative frequency offset of HPOSC
653 //!
654 //! The HPOSC (High Precision Oscillator) frequency will vary slightly with chip temperature.
655 //! This variation forces the RTC increment to be compensated if SCLK_LF is configured
656 //! to be derived from the HF clock of HPOSC.
657 //! This function must only be called if SCLK_LF is configured to be derived from
658 //! the HF clock of HPOSC. The status of this configuration can be determined
659 //! by calling the \ref OSC_IsHPOSCEnabledWithHfDerivedLfClock() function.
660 //!
661 //! This function first calculates the HPOSC frequency, defined as:
662 //! <pre>
663 //! F_HPOSC = F_nom * (1 + d/(2^22))
664 //! </pre>
665 //! where
666 //! - F_HPOSC is the current HPOSC frequency.
667 //! - F_nom is the nominal oscillator frequency, assumed to be 48.000 MHz.
668 //! - d is the relative frequency offset given by the input argument relFreqOffset.
669 //! Then the SCLK_LF frequency is calculated, defined as:
670 //! <pre>
671 //! F_SCLK_LF = F_HPOSC / 1536
672 //! </pre>
673 //! Then the RTC increment SUBSECINC is calculated, defined as;
674 //! <pre>
675 //! SUBSECINC = (2^38) / F_SCLK_LF
676 //! </pre>
677 //! Finally the RTC module is updated with the calculated SUBSECINC value.
678 //!
679 //! \param relFreqOffset is the relative frequency offset parameter d returned from \ref OSC_HPOSCRelativeFrequencyOffsetGet()
680 //!
681 //! \return None
682 //!
683 //
684 //*****************************************************************************
685 extern void OSC_HPOSCRtcCompensate( int32_t relFreqOffset );
686
687 //*****************************************************************************
688 //
689 // Support for DriverLib in ROM:
690 // Redirect to implementation in ROM when available.
691 //
692 //*****************************************************************************
693 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
694 #include "../driverlib/rom.h"
695 #ifdef ROM_OSCClockSourceSet
696 #undef OSCClockSourceSet
697 #define OSCClockSourceSet ROM_OSCClockSourceSet
698 #endif
699 #ifdef ROM_OSCClockSourceGet
700 #undef OSCClockSourceGet
701 #define OSCClockSourceGet ROM_OSCClockSourceGet
702 #endif
703 #ifdef ROM_OSCHF_GetStartupTime
704 #undef OSCHF_GetStartupTime
705 #define OSCHF_GetStartupTime ROM_OSCHF_GetStartupTime
706 #endif
707 #ifdef ROM_OSCHF_TurnOnXosc
708 #undef OSCHF_TurnOnXosc
709 #define OSCHF_TurnOnXosc ROM_OSCHF_TurnOnXosc
710 #endif
711 #ifdef ROM_OSCHF_AttemptToSwitchToXosc
712 #undef OSCHF_AttemptToSwitchToXosc
713 #define OSCHF_AttemptToSwitchToXosc ROM_OSCHF_AttemptToSwitchToXosc
714 #endif
715 #ifdef ROM_OSCHF_SwitchToRcOscTurnOffXosc
716 #undef OSCHF_SwitchToRcOscTurnOffXosc
717 #define OSCHF_SwitchToRcOscTurnOffXosc ROM_OSCHF_SwitchToRcOscTurnOffXosc
718 #endif
719 #ifdef ROM_OSCHF_DebugGetCrystalAmplitude
720 #undef OSCHF_DebugGetCrystalAmplitude
721 #define OSCHF_DebugGetCrystalAmplitude ROM_OSCHF_DebugGetCrystalAmplitude
722 #endif
723 #ifdef ROM_OSCHF_DebugGetExpectedAverageCrystalAmplitude
724 #undef OSCHF_DebugGetExpectedAverageCrystalAmplitude
725 #define OSCHF_DebugGetExpectedAverageCrystalAmplitude ROM_OSCHF_DebugGetExpectedAverageCrystalAmplitude
726 #endif
727 #ifdef ROM_OSCHF_DebugGetCrystalStartupTime
728 #undef OSCHF_DebugGetCrystalStartupTime
729 #define OSCHF_DebugGetCrystalStartupTime ROM_OSCHF_DebugGetCrystalStartupTime
730 #endif
731 #ifdef ROM_OSC_HPOSCInitializeFrequencyOffsetParameters
732 #undef OSC_HPOSCInitializeFrequencyOffsetParameters
733 #define OSC_HPOSCInitializeFrequencyOffsetParameters ROM_OSC_HPOSCInitializeFrequencyOffsetParameters
734 #endif
735 #ifdef ROM_OSC_HPOSC_Debug_InitFreqOffsetParams
736 #undef OSC_HPOSC_Debug_InitFreqOffsetParams
737 #define OSC_HPOSC_Debug_InitFreqOffsetParams ROM_OSC_HPOSC_Debug_InitFreqOffsetParams
738 #endif
739 #ifdef ROM_OSC_HPOSCInitializeSingleInsertionFreqOffsParams
740 #undef OSC_HPOSCInitializeSingleInsertionFreqOffsParams
741 #define OSC_HPOSCInitializeSingleInsertionFreqOffsParams ROM_OSC_HPOSCInitializeSingleInsertionFreqOffsParams
742 #endif
743 #ifdef ROM_OSC_HPOSCRelativeFrequencyOffsetGet
744 #undef OSC_HPOSCRelativeFrequencyOffsetGet
745 #define OSC_HPOSCRelativeFrequencyOffsetGet ROM_OSC_HPOSCRelativeFrequencyOffsetGet
746 #endif
747 #ifdef ROM_OSC_AdjustXoscHfCapArray
748 #undef OSC_AdjustXoscHfCapArray
749 #define OSC_AdjustXoscHfCapArray ROM_OSC_AdjustXoscHfCapArray
750 #endif
751 #ifdef ROM_OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert
752 #undef OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert
753 #define OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert ROM_OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert
754 #endif
755 #ifdef ROM_OSC_HPOSCRtcCompensate
756 #undef OSC_HPOSCRtcCompensate
757 #define OSC_HPOSCRtcCompensate ROM_OSC_HPOSCRtcCompensate
758 #endif
759 #endif
760
761 //*****************************************************************************
762 //
763 // Mark the end of the C bindings section for C++ compilers.
764 //
765 //*****************************************************************************
766 #ifdef __cplusplus
767 }
768 #endif
769
770 #endif // __OSC_H__
771
772 //*****************************************************************************
773 //
774 //! Close the Doxygen group.
775 //! @}
776 //! @}
777 //
778 //*****************************************************************************
779