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