1 /******************************************************************************
2 *  Filename:       osc.h
3 *  Revised:        2020-02-14 11:30:20 +0100 (Fri, 14 Feb 2020)
4 *  Revision:       56760
5 *
6 *  Description:    Defines and prototypes for the system oscillator control.
7 *
8 *  Copyright (c) 2015 - 2017, 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 OSC_HPOSC_Debug_InitFreqOffsetParams NOROM_OSC_HPOSC_Debug_InitFreqOffsetParams
98     #define OSC_HPOSCInitializeFrequencyOffsetParameters NOROM_OSC_HPOSCInitializeFrequencyOffsetParameters
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 Data structure for experimental HPOSC polynomials calculation.
487 //!
488 //! The structure of the meas_1, meas_2 and meas_3 parameter is
489 //! as defined in FCFG1_O_HPOSC_MEAS_1, 2 and 3.
490 //!
491 //! \sa OSC_HPOSC_Debug_InitFreqOffsetParams()
492 //
493 //*****************************************************************************
494 typedef struct {
495    uint32_t    meas_1   ; //!< Measurement set 1 (typically at room temp)
496    uint32_t    meas_2   ; //!< Measurement set 2 (typically at high temp)
497    uint32_t    meas_3   ; //!< Measurement set 3 (typically at low temp)
498    int32_t     offsetD1 ; //!< Offset to measurement set 1
499    int32_t     offsetD2 ; //!< Offset to measurement set 2
500    int32_t     offsetD3 ; //!< Offset to measurement set 3
501    int32_t     polyP3   ; //!< The P3 polynomial
502 } HposcDebugData_t;
503 
504 //*****************************************************************************
505 //
506 //! \brief Debug function to calculate the HPOSC polynomials for experimental data sets.
507 //!
508 //! \param pDebugData pointer to the input data collected in \ref HposcDebugData_t
509 //!
510 //! \return None
511 //!
512 //! \sa OSC_HPOSCInitializeFrequencyOffsetParameters()
513 //
514 //*****************************************************************************
515 extern void OSC_HPOSC_Debug_InitFreqOffsetParams( HposcDebugData_t * pDebugData );
516 
517 //*****************************************************************************
518 //
519 //! \brief HPOSC initialization function. Must always be called before using HPOSC.
520 //!
521 //! Calculates the fitting curve parameters (polynomials) to used by the
522 //! HPOSC temperature compensation.
523 //!
524 //! \return None
525 //!
526 //! \sa OSC_HPOSC_Debug_InitFreqOffsetParams()
527 //
528 //*****************************************************************************
529 extern void OSC_HPOSCInitializeFrequencyOffsetParameters( void );
530 
531 //*****************************************************************************
532 //
533 //! \brief Calculate the temperature dependent relative frequency offset of HPOSC
534 //!
535 //! The HPOSC (High Precision Oscillator) frequency will vary slightly with chip temperature.
536 //! The frequency offset from the nominal value can be predicted based on
537 //! second order linear interpolation using coefficients measured in chip
538 //! production and stored as factory configuration parameters.
539 //!
540 //! This function calculates the relative frequency offset, defined as:
541 //! <pre>
542 //!     F_HPOSC = F_nom * (1 + d/(2^22))
543 //! </pre>
544 //! where
545 //! -   F_HPOSC is the current HPOSC frequency.
546 //! -   F_nom is the nominal oscillator frequency, assumed to be 48.000 MHz.
547 //! -   d is the relative frequency offset (the value returned).
548 //!
549 //! By knowing the relative frequency offset it is then possible to compensate
550 //! any timing related values accordingly.
551 //!
552 //! \param tempDegC is the chip temperature in degrees Celsius. Use the
553 //! function \ref AONBatMonTemperatureGetDegC() to get current chip temperature.
554 //!
555 //! \return Returns the relative frequency offset parameter d.
556 //!
557 //! \sa OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert(), AONBatMonTemperatureGetDegC()
558 //
559 //*****************************************************************************
560 extern int32_t OSC_HPOSCRelativeFrequencyOffsetGet( int32_t tempDegC );
561 
562 //*****************************************************************************
563 //
564 //! \brief Adjust the XOSC HF cap array relative to the factory setting
565 //!
566 //! The cap array factory setting (FCFG) can be converted to a number in the range 0 - 63.
567 //! Both this function and the customer configuration (CCFG) setting can apply a delta to the FCFG setting.
568 //! The CCFG setting is automatically applied at boot time (See ../startup_files/ccfg.c).
569 //! Calling this function will discard the CCFG setting and adjust relative to the FCFG setting.
570 //!
571 //! \note Adjusted value will not take effect before XOSC_HF is stopped and restarted
572 //!
573 //! \param capArrDelta specifies number of step to adjust the cap array relative to the factory setting.
574 //!
575 //! \return None
576 //
577 //*****************************************************************************
578 extern void OSC_AdjustXoscHfCapArray( int32_t capArrDelta );
579 
580 //*****************************************************************************
581 //
582 //! \brief Converts the relative frequency offset of HPOSC to the RF Core parameter format.
583 //!
584 //! The HPOSC (High Precision Oscillator) clock is used by the RF Core.
585 //! To compensate for a frequency offset in the frequency of the clock source,
586 //! a frequency offset parameter can be provided as part of the radio configuration
587 //! override setting list to enable compensation of the RF synthesizer frequency,
588 //! symbol timing, and radio timer to still achieve correct frequencies.
589 //!
590 //! The RF Core takes a relative frequency offset parameter defined differently
591 //! compared to the relative frequency offset parameter returned from function
592 //! \ref OSC_HPOSCRelativeFrequencyOffsetGet() and thus needs to be converted:
593 //! <pre>
594 //!     F_nom = F_HPOSC * (1 + RfCoreRelFreqOffset/(2^22))
595 //! </pre>
596 //! where
597 //! -   F_nom is the nominal oscillator frequency, assumed to be 48.000 MHz.
598 //! -   F_HPOSC is the current HPOSC frequency.
599 //! -   RfCoreRelFreqOffset is the relative frequency offset in the "RF Core" format (the value returned).
600 //!
601 //! \param HPOSC_RelFreqOffset is the relative frequency offset parameter d returned from \ref OSC_HPOSCRelativeFrequencyOffsetGet()
602 //!
603 //! \return Returns the relative frequency offset in RF Core format.
604 //!
605 //! \sa OSC_HPOSCRelativeFrequencyOffsetGet()
606 //
607 //*****************************************************************************
608 extern int16_t OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert( int32_t HPOSC_RelFreqOffset );
609 
610 //*****************************************************************************
611 //
612 //! \brief Compensate the RTC increment based on the relative frequency offset of HPOSC
613 //!
614 //! The HPOSC (High Precision Oscillator) frequency will vary slightly with chip temperature.
615 //! This variation forces the RTC increment to be compensated if SCLK_LF is configured
616 //! to be derived from the HF clock of HPOSC.
617 //! This function must only be called if SCLK_LF is configured to be derived from
618 //! the HF clock of HPOSC. The status of this configuration can be determined
619 //! by calling the \ref OSC_IsHPOSCEnabledWithHfDerivedLfClock() function.
620 //!
621 //! This function first calculates the HPOSC frequency, defined as:
622 //! <pre>
623 //!     F_HPOSC = F_nom * (1 + d/(2^22))
624 //! </pre>
625 //! where
626 //! -   F_HPOSC is the current HPOSC frequency.
627 //! -   F_nom is the nominal oscillator frequency, assumed to be 48.000 MHz.
628 //! -   d is the relative frequency offset given by the input argument relFreqOffset.
629 //! Then the SCLK_LF frequency is calculated, defined as:
630 //! <pre>
631 //!     F_SCLK_LF = F_HPOSC / 1536
632 //! </pre>
633 //! Then the RTC increment SUBSECINC is calculated, defined as;
634 //! <pre>
635 //!     SUBSECINC = (2^38) / F_SCLK_LF
636 //! </pre>
637 //! Finally the RTC module is updated with the calculated SUBSECINC value.
638 //!
639 //! \param relFreqOffset is the relative frequency offset parameter d returned from \ref OSC_HPOSCRelativeFrequencyOffsetGet()
640 //!
641 //! \return None
642 //!
643 //
644 //*****************************************************************************
645 extern void OSC_HPOSCRtcCompensate( int32_t relFreqOffset );
646 
647 //*****************************************************************************
648 //
649 // Support for DriverLib in ROM:
650 // Redirect to implementation in ROM when available.
651 //
652 //*****************************************************************************
653 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
654     #include "../driverlib/rom.h"
655     #ifdef ROM_OSCClockSourceSet
656         #undef  OSCClockSourceSet
657         #define OSCClockSourceSet               ROM_OSCClockSourceSet
658     #endif
659     #ifdef ROM_OSCClockSourceGet
660         #undef  OSCClockSourceGet
661         #define OSCClockSourceGet               ROM_OSCClockSourceGet
662     #endif
663     #ifdef ROM_OSCHF_GetStartupTime
664         #undef  OSCHF_GetStartupTime
665         #define OSCHF_GetStartupTime            ROM_OSCHF_GetStartupTime
666     #endif
667     #ifdef ROM_OSCHF_TurnOnXosc
668         #undef  OSCHF_TurnOnXosc
669         #define OSCHF_TurnOnXosc                ROM_OSCHF_TurnOnXosc
670     #endif
671     #ifdef ROM_OSCHF_AttemptToSwitchToXosc
672         #undef  OSCHF_AttemptToSwitchToXosc
673         #define OSCHF_AttemptToSwitchToXosc     ROM_OSCHF_AttemptToSwitchToXosc
674     #endif
675     #ifdef ROM_OSCHF_SwitchToRcOscTurnOffXosc
676         #undef  OSCHF_SwitchToRcOscTurnOffXosc
677         #define OSCHF_SwitchToRcOscTurnOffXosc  ROM_OSCHF_SwitchToRcOscTurnOffXosc
678     #endif
679     #ifdef ROM_OSCHF_DebugGetCrystalAmplitude
680         #undef  OSCHF_DebugGetCrystalAmplitude
681         #define OSCHF_DebugGetCrystalAmplitude  ROM_OSCHF_DebugGetCrystalAmplitude
682     #endif
683     #ifdef ROM_OSCHF_DebugGetExpectedAverageCrystalAmplitude
684         #undef  OSCHF_DebugGetExpectedAverageCrystalAmplitude
685         #define OSCHF_DebugGetExpectedAverageCrystalAmplitude ROM_OSCHF_DebugGetExpectedAverageCrystalAmplitude
686     #endif
687     #ifdef ROM_OSC_HPOSC_Debug_InitFreqOffsetParams
688         #undef  OSC_HPOSC_Debug_InitFreqOffsetParams
689         #define OSC_HPOSC_Debug_InitFreqOffsetParams ROM_OSC_HPOSC_Debug_InitFreqOffsetParams
690     #endif
691     #ifdef ROM_OSC_HPOSCInitializeFrequencyOffsetParameters
692         #undef  OSC_HPOSCInitializeFrequencyOffsetParameters
693         #define OSC_HPOSCInitializeFrequencyOffsetParameters ROM_OSC_HPOSCInitializeFrequencyOffsetParameters
694     #endif
695     #ifdef ROM_OSC_HPOSCRelativeFrequencyOffsetGet
696         #undef  OSC_HPOSCRelativeFrequencyOffsetGet
697         #define OSC_HPOSCRelativeFrequencyOffsetGet ROM_OSC_HPOSCRelativeFrequencyOffsetGet
698     #endif
699     #ifdef ROM_OSC_AdjustXoscHfCapArray
700         #undef  OSC_AdjustXoscHfCapArray
701         #define OSC_AdjustXoscHfCapArray        ROM_OSC_AdjustXoscHfCapArray
702     #endif
703     #ifdef ROM_OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert
704         #undef  OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert
705         #define OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert ROM_OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert
706     #endif
707     #ifdef ROM_OSC_HPOSCRtcCompensate
708         #undef  OSC_HPOSCRtcCompensate
709         #define OSC_HPOSCRtcCompensate          ROM_OSC_HPOSCRtcCompensate
710     #endif
711 #endif
712 
713 //*****************************************************************************
714 //
715 // Mark the end of the C bindings section for C++ compilers.
716 //
717 //*****************************************************************************
718 #ifdef __cplusplus
719 }
720 #endif
721 
722 #endif // __OSC_H__
723 
724 //*****************************************************************************
725 //
726 //! Close the Doxygen group.
727 //! @}
728 //! @}
729 //
730 //*****************************************************************************
731