CC26xx Driver Library
osc.c File Reference
#include "../inc/hw_types.h"
#include "../inc/hw_ccfg.h"
#include "../inc/hw_fcfg1.h"
#include "aon_batmon.h"
#include "aon_rtc.h"
#include "osc.h"
#include "setup_rom.h"

Data Structures

struct  OscHfGlobals_t
 
struct  insertion_t
 

Macros

#define RTC_CV_TO_MS(x)   (( 1000 * ( x )) >> 16 )
 
#define RTC_CV_TO_US(x)   (( 1000000 * ( x )) >> 16 )
 
#define D1OFFSET_p25C   -24
 
#define D2OFFSET_p85C   -36
 
#define D3OFFSET_m40C   18
 
#define P3_POLYNOMIAL   -47
 
#define N_INSERTIONS   3
 

Functions

void OSCClockSourceSet (uint32_t ui32SrcClk, uint32_t ui32Osc)
 Configure the oscillator input to the a source clock. More...
 
uint32_t OSCClockSourceGet (uint32_t ui32SrcClk)
 Get the source clock settings. More...
 
uint32_t OSCHF_GetStartupTime (uint32_t timeUntilWakeupInMs)
 Returns maximum startup time (in microseconds) of XOSC_HF. More...
 
void OSCHF_TurnOnXosc (void)
 Turns on XOSC_HF (but without switching to XOSC_HF). More...
 
bool OSCHF_AttemptToSwitchToXosc (void)
 Switch to XOSC_HF if XOSC_HF is ready. More...
 
void OSCHF_SwitchToRcOscTurnOffXosc (void)
 Switch to RCOSC_HF and turn off XOSC_HF. More...
 
void OSC_AdjustXoscHfCapArray (int32_t capArrDelta)
 Adjust the XOSC HF cap array relative to the factory setting. More...
 
static void InitializeMeasurmentSet (insertion_t *pInsertion, uint32_t registerAddress, int32_t deltaOffset, int32_t p3PolOffset)
 
static void FindPolynomialsAndUpdateGlobals (insertion_t *pMeasurment)
 
void OSC_HPOSC_Debug_InitFreqOffsetParams (HposcDebugData_t *pDebugData)
 Debug function to calculate the HPOSC polynomials for experimental data sets. More...
 
void OSC_HPOSCInitializeFrequencyOffsetParameters (void)
 HPOSC initialization function. Must always be called before using HPOSC. More...
 
int32_t OSC_HPOSCRelativeFrequencyOffsetGet (int32_t tempDegC)
 Calculate the temperature dependent relative frequency offset of HPOSC. More...
 
int16_t OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert (int32_t HPOSC_RelFreqOffset)
 Converts the relative frequency offset of HPOSC to the RF Core parameter format. More...
 
void OSC_HPOSCRtcCompensate (int32_t relFreqOffset)
 Compensate the RTC increment based on the relative frequency offset of HPOSC. More...
 
uint32_t OSCHF_DebugGetCrystalAmplitude (void)
 Get crystal amplitude (assuming crystal is running). More...
 
uint32_t OSCHF_DebugGetExpectedAverageCrystalAmplitude (void)
 Get the expected average crystal amplitude. More...
 

Variables

static int16_t _hpOscPolynomials [4]
 
static OscHfGlobals_t oscHfGlobals
 

Macro Definition Documentation

#define D1OFFSET_p25C   -24
#define D2OFFSET_p85C   -36
#define D3OFFSET_m40C   18
#define N_INSERTIONS   3
#define P3_POLYNOMIAL   -47
#define RTC_CV_TO_MS (   x)    (( 1000 * ( x )) >> 16 )

Referenced by OSCHF_GetStartupTime().

#define RTC_CV_TO_US (   x)    (( 1000000 * ( x )) >> 16 )

Function Documentation

static void FindPolynomialsAndUpdateGlobals ( insertion_t pMeasurment)
static

Referenced by OSC_HPOSC_Debug_InitFreqOffsetParams(), and OSC_HPOSCInitializeFrequencyOffsetParameters().

367 {
368  uint32_t loopCount ;
369  int32_t polynomial_0 ;
370  int32_t polynomial_1 ;
371  int32_t polynomial_2 ;
372 
373  int32_t Syi_ = 0 ;
374  int32_t Sxi_ = 0 ;
375  int32_t Sxi2_ = 0 ;
376  int32_t Sxiyi_ = 0 ;
377  int32_t Sxi2yi_ = 0 ;
378  int32_t Sxi3_ = 0 ;
379  int32_t Sxi4_ = 0 ;
380 
381  for ( loopCount = 0 ; loopCount < N_INSERTIONS ; loopCount++ ) {
382  int32_t x ;
383  int32_t x2 ;
384  int32_t y ;
385 
386  x = pMeasurment[ loopCount ].temp ;
387  x2 = ( x * x );
388  y = pMeasurment[ loopCount ].dFreq ;
389 
390  Syi_ += ( y );
391  Sxi_ += ( x );
392  Sxi2_ += ( x2 );
393  Sxiyi_ += ( x * y );
394  Sxi2yi_ += ( x2 * y );
395  Sxi3_ += ( x2 * x );
396  Sxi4_ += ( x2 * x2 );
397  }
398 
399  int32_t Sxx_ = ( Sxi2_ * N_INSERTIONS ) - ( Sxi_ * Sxi_ );
400  int32_t Sxy_ = ( Sxiyi_ * N_INSERTIONS ) - ( Sxi_ * Syi_ );
401  int32_t Sxx2_ = ( Sxi3_ * N_INSERTIONS ) - ( Sxi_ * Sxi2_ );
402  int32_t Sx2y_ = ( Sxi2yi_ * N_INSERTIONS ) - ( Sxi2_ * Syi_ );
403  int32_t Sx2x2_ = ( Sxi4_ * N_INSERTIONS ) - ( Sxi2_ * Sxi2_ );
404 
405  int32_t divisor = ((((int64_t) Sxx_ * Sx2x2_ ) - ((int64_t) Sxx2_ * Sxx2_ )) + (1<<9)) >> 10 ;
406  if ( divisor == 0 ) {
407  polynomial_2 = 0 ;
408  polynomial_1 = 0 ;
409  } else {
410  polynomial_2 = (((int64_t) Sx2y_ * Sxx_ ) - ((int64_t) Sxy_ * Sxx2_ )) / divisor ;
411  polynomial_1 = (((int64_t) Sxy_ * Sx2x2_ ) - ((int64_t) Sx2y_ * Sxx2_ )) / divisor ;
412  }
413  polynomial_0 = ( Syi_ - (((( polynomial_1 * Sxi_ ) + ( polynomial_2 * Sxi2_ )) + (1<<9)) >> 10 )) / N_INSERTIONS ;
414  polynomial_1 = ( polynomial_1 + (1<<6)) >> 7 ;
415 
416  _hpOscPolynomials[ 0 ] = polynomial_0 ;
417  _hpOscPolynomials[ 1 ] = polynomial_1 ;
418  _hpOscPolynomials[ 2 ] = polynomial_2 ;
420 }
int32_t dFreq
Definition: osc.c:348
#define N_INSERTIONS
Definition: osc.c:345
#define P3_POLYNOMIAL
Definition: osc.c:344
static int16_t _hpOscPolynomials[4]
Definition: osc.c:94
int32_t temp
Definition: osc.c:349
static void InitializeMeasurmentSet ( insertion_t pInsertion,
uint32_t  registerAddress,
int32_t  deltaOffset,
int32_t  p3PolOffset 
)
static

Referenced by OSC_HPOSC_Debug_InitFreqOffsetParams(), and OSC_HPOSCInitializeFrequencyOffsetParameters().

354 {
355  // Doing the following adjustment to the deltaFrequence before finding the polynomials P0, P1, P2
356  // Dx = Dx + DxOFFSET - ((P3*Tx^3)/2^18)
357  uint32_t insertionData = HWREG( registerAddress );
358  pInsertion->dFreq = (((int32_t)( insertionData << ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_D1_W - FCFG1_HPOSC_MEAS_1_HPOSC_D1_S )))
359  >> ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_D1_W ));
360  pInsertion->temp = (((int32_t)( insertionData << ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_T1_W - FCFG1_HPOSC_MEAS_1_HPOSC_T1_S )))
361  >> ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_T1_W ));
362  pInsertion->dFreq = pInsertion->dFreq + deltaOffset - (( p3PolOffset * pInsertion->temp * pInsertion->temp * pInsertion->temp ) >> 18 );
363 }
int32_t dFreq
Definition: osc.c:348
int32_t temp
Definition: osc.c:349

Variable Documentation

int16_t _hpOscPolynomials[4]
static
OscHfGlobals_t oscHfGlobals
static