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().

378 {
379  uint32_t loopCount ;
380  int32_t polynomial_0 ;
381  int32_t polynomial_1 ;
382  int32_t polynomial_2 ;
383 
384  int32_t Syi_ = 0 ;
385  int32_t Sxi_ = 0 ;
386  int32_t Sxi2_ = 0 ;
387  int32_t Sxiyi_ = 0 ;
388  int32_t Sxi2yi_ = 0 ;
389  int32_t Sxi3_ = 0 ;
390  int32_t Sxi4_ = 0 ;
391 
392  for ( loopCount = 0 ; loopCount < N_INSERTIONS ; loopCount++ ) {
393  int32_t x ;
394  int32_t x2 ;
395  int32_t y ;
396 
397  x = pMeasurment[ loopCount ].temp ;
398  x2 = ( x * x );
399  y = pMeasurment[ loopCount ].dFreq ;
400 
401  Syi_ += ( y );
402  Sxi_ += ( x );
403  Sxi2_ += ( x2 );
404  Sxiyi_ += ( x * y );
405  Sxi2yi_ += ( x2 * y );
406  Sxi3_ += ( x2 * x );
407  Sxi4_ += ( x2 * x2 );
408  }
409 
410  int32_t Sxx_ = ( Sxi2_ * N_INSERTIONS ) - ( Sxi_ * Sxi_ );
411  int32_t Sxy_ = ( Sxiyi_ * N_INSERTIONS ) - ( Sxi_ * Syi_ );
412  int32_t Sxx2_ = ( Sxi3_ * N_INSERTIONS ) - ( Sxi_ * Sxi2_ );
413  int32_t Sx2y_ = ( Sxi2yi_ * N_INSERTIONS ) - ( Sxi2_ * Syi_ );
414  int32_t Sx2x2_ = ( Sxi4_ * N_INSERTIONS ) - ( Sxi2_ * Sxi2_ );
415 
416  int32_t divisor = ((((int64_t) Sxx_ * Sx2x2_ ) - ((int64_t) Sxx2_ * Sxx2_ )) + (1<<9)) >> 10 ;
417  if ( divisor == 0 ) {
418  polynomial_2 = 0 ;
419  polynomial_1 = 0 ;
420  } else {
421  polynomial_2 = (((int64_t) Sx2y_ * Sxx_ ) - ((int64_t) Sxy_ * Sxx2_ )) / divisor ;
422  polynomial_1 = (((int64_t) Sxy_ * Sx2x2_ ) - ((int64_t) Sx2y_ * Sxx2_ )) / divisor ;
423  }
424  polynomial_0 = ( Syi_ - (((( polynomial_1 * Sxi_ ) + ( polynomial_2 * Sxi2_ )) + (1<<9)) >> 10 )) / N_INSERTIONS ;
425  polynomial_1 = ( polynomial_1 + (1<<6)) >> 7 ;
426 
427  _hpOscPolynomials[ 0 ] = polynomial_0 ;
428  _hpOscPolynomials[ 1 ] = polynomial_1 ;
429  _hpOscPolynomials[ 2 ] = polynomial_2 ;
431 }
int32_t dFreq
Definition: osc.c:359
#define N_INSERTIONS
Definition: osc.c:356
#define P3_POLYNOMIAL
Definition: osc.c:355
static int16_t _hpOscPolynomials[4]
Definition: osc.c:94
int32_t temp
Definition: osc.c:360
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().

365 {
366  // Doing the following adjustment to the deltaFrequence before finding the polynomials P0, P1, P2
367  // Dx = Dx + DxOFFSET - ((P3*Tx^3)/2^18)
368  uint32_t insertionData = HWREG( registerAddress );
369  pInsertion->dFreq = (((int32_t)( insertionData << ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_D1_W - FCFG1_HPOSC_MEAS_1_HPOSC_D1_S )))
370  >> ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_D1_W ));
371  pInsertion->temp = (((int32_t)( insertionData << ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_T1_W - FCFG1_HPOSC_MEAS_1_HPOSC_T1_S )))
372  >> ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_T1_W ));
373  pInsertion->dFreq = pInsertion->dFreq + deltaOffset - (( p3PolOffset * pInsertion->temp * pInsertion->temp * pInsertion->temp ) >> 18 );
374 }
int32_t dFreq
Definition: osc.c:359
int32_t temp
Definition: osc.c:360

Variable Documentation

int16_t _hpOscPolynomials[4]
static
OscHfGlobals_t oscHfGlobals
static