CC26xx Driver Library
osc.c File Reference
#include <stdlib.h>
#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 "sys_ctrl.h"
#include "setup_rom.h"

Data Structures

struct  OscHfGlobals_t
 
struct  hposc_insertions_t
 
struct  hposc_param_t
 

Macros

#define RTC_CV_TO_MS(x)   (( 1000 * ( x )) >> 16 )
 
#define RTC_CV_TO_US(x)   (( 1000000 * ( x )) >> 16 )
 
#define D1OFFSET_25C   (-16)
 
#define D2OFFSET_85C   (-23)
 
#define D3OFFSET_n40C   (5)
 
#define HPOSC_COEFF_BITS   (20)
 
#define HPOSC_COEFF0_BITS   (16)
 
#define HPOSC_D_BITS   (30)
 
#define HPOSC_COEFF0_SHIFT   (HPOSC_COEFF_BITS - HPOSC_COEFF0_BITS)
 
#define HPOSC_SHIFT1   (2*HPOSC_COEFF_BITS - HPOSC_D_BITS)
 
#define HPOSC_DC_BIAS   (100000)
 

Functions

XoscLf_Params_t _lfXoscParams __attribute__ ((weak))
 
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...
 
static void InternCapArrayAdjustWithBaseline7001F (int32_t capArrayDelta)
 
static uint32_t SpecialCapArrayWorkaroundEnabledAndNeeded (void)
 
void OSC_CapArrayAdjustWorkaround_Boot (void)
 Special XOSC_HF workaround adjustment for CC13x2 / CC26x2 XOSC_CAPARRAY_DELTA setting in CCFG (Customer configuration) More...
 
void OSC_AdjustXoscHfCapArray (int32_t capArrDelta)
 Adjust the XOSC HF cap array relative to the factory setting. More...
 
static void multiplyColumns (int64_t *v1, int64_t *v2, int64_t *pBuf, uint8_t shift)
 
static int64_t findDenominator (int64_t *col0, int64_t *col1, int64_t *col2)
 
static int64_t findNumerator (int32_t *pInput, int64_t *pBuf)
 
static void findHposcCoefficients (int32_t *pInput, int64_t *col0, int64_t *col1, int64_t *col2, hposc_param_t *pParam)
 
static void findHposcPc (int64_t *pCoeff, uint8_t *pBits, int32_t *pTemp, uint8_t nTemp, int64_t *pOutput)
 
static void readTempAndFreq (uint32_t regAddr, int32_t *pTemp, int32_t *pdFreq, int32_t deltaFreq)
 
void OSC_HPOSCInitializeFrequencyOffsetParameters (void)
 HPOSC initialization function. Must always be called before using HPOSC. More...
 
void OSC_HPOSC_Debug_InitFreqOffsetParams (HposcDebugData_t *pDebugData)
 Debug function to calculate the HPOSC polynomials for experimental data sets. More...
 
void OSC_HPOSCInitializeSingleInsertionFreqOffsParams (uint32_t measFieldAddress)
 Special HPOSC initialization function for single temperature compensation. More...
 
void OSC_LFXOSCInitStaticOffset (void)
 Initialize device specific coefficient for XOSC LF RTC compensation. More...
 
int32_t OSC_LFXOSCRelativeFrequencyOffsetGet (int32_t temperature)
 Calculates the ppm offset of XOSC LF for a given temperature. 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...
 
uint32_t OSCHF_DebugGetCrystalStartupTime (void)
 Measure the crystal startup time. More...
 

Variables

static OscHfGlobals_t oscHfGlobals
 
int32_t _hposcCoeffs [4] = {0}
 

Macro Definition Documentation

§ D1OFFSET_25C

#define D1OFFSET_25C   (-16)

§ D2OFFSET_85C

#define D2OFFSET_85C   (-23)

§ D3OFFSET_n40C

#define D3OFFSET_n40C   (5)

§ HPOSC_COEFF0_BITS

#define HPOSC_COEFF0_BITS   (16)

§ HPOSC_COEFF0_SHIFT

§ HPOSC_COEFF_BITS

#define HPOSC_COEFF_BITS   (20)

§ HPOSC_D_BITS

#define HPOSC_D_BITS   (30)

Referenced by findHposcCoefficients().

§ HPOSC_DC_BIAS

#define HPOSC_DC_BIAS   (100000)

Referenced by findHposcCoefficients().

§ HPOSC_SHIFT1

#define HPOSC_SHIFT1   (2*HPOSC_COEFF_BITS - HPOSC_D_BITS)

§ RTC_CV_TO_MS

#define RTC_CV_TO_MS (   x)    (( 1000 * ( x )) >> 16 )

Referenced by OSCHF_GetStartupTime().

§ RTC_CV_TO_US

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

Function Documentation

§ __attribute__()

XoscLf_Params_t _lfXoscParams __attribute__ ( (weak)  )

§ findDenominator()

static int64_t findDenominator ( int64_t *  col0,
int64_t *  col1,
int64_t *  col2 
)
static

Referenced by findHposcCoefficients().

462 {
463  int64_t tmp, tmpBuf[6];
464 
465  multiplyColumns(col1, col2, tmpBuf, HPOSC_SHIFT1); // Keep HPOSC_D_BITS precision
466 
467  tmp = (tmpBuf[0]*col0[0] - tmpBuf[1]*col0[0] - tmpBuf[2]*col0[1] +
468  tmpBuf[3]*col0[1] + tmpBuf[4]*col0[2] - tmpBuf[5]*col0[2]) >> HPOSC_COEFF_BITS;
469 
470  return tmp;
471 }
#define HPOSC_COEFF_BITS
Definition: osc.c:424
static void multiplyColumns(int64_t *v1, int64_t *v2, int64_t *pBuf, uint8_t shift)
Definition: osc.c:450
#define HPOSC_SHIFT1
Definition: osc.c:428
Here is the call graph for this function:

§ findHposcCoefficients()

static void findHposcCoefficients ( int32_t *  pInput,
int64_t *  col0,
int64_t *  col1,
int64_t *  col2,
hposc_param_t pParam 
)
static

Referenced by OSC_HPOSC_Debug_InitFreqOffsetParams(), OSC_HPOSCInitializeFrequencyOffsetParameters(), and OSC_HPOSCInitializeSingleInsertionFreqOffsParams().

486 {
487  int64_t d,c0,c1,c2,cn,tmpBuf[6];
488  int32_t inputBuf[3];
489  uint8_t i;
490 
491  if(col1 == NULL) /* 1 insertion */
492  {
493  inputBuf[0] = pInput[0] - HPOSC_DC_BIAS;
494  c0 = (((int64_t)inputBuf[0] << HPOSC_D_BITS) / col0[0]);
495  c1 = 0;
496  c2 = 0;
497  }
498  else /* 3 insertion */
499  {
500  /* Apply DC bias to input data */
501  for(i = 0; i < 3; i++)
502  {
503  inputBuf[i] = pInput[i] - HPOSC_DC_BIAS;
504  }
505 
506  /* Solve intermediate parameters, d: HPOSC_D_BITS, c: HPOSC_COEFF_BITS*2 bits */
507  d = findDenominator(col0, col1, col2);
508 
509  multiplyColumns(col1, col2, tmpBuf, 0);
510  cn = findNumerator(inputBuf, tmpBuf);
511  c0 = cn / d;
512 
513  multiplyColumns(col0, col2, tmpBuf, 0);
514  cn = -1*findNumerator(inputBuf, tmpBuf);
515  c1 = cn / d;
516 
517  multiplyColumns(col0, col1, tmpBuf, 0);
518  cn = findNumerator(inputBuf, tmpBuf);
519  c2 = cn / d;
520  }
521 
522  /* Compute TCF polynomial coefficients */
523  for(i = 0; i < 4; i++)
524  {
525  cn = (((pParam->pu0c[i]*c0) >> (pParam->pu0b[i] - HPOSC_COEFF_BITS)) +
526  ((pParam->pu1c[i]*c1) >> (pParam->pu1b[i] - HPOSC_COEFF_BITS)) +
527  ((pParam->pu2c[i]*c2) >> (pParam->pu2b[i] - HPOSC_COEFF_BITS))) >> HPOSC_SHIFT1;
528 
529  if(i<3)
530  {
531  _hposcCoeffs[3-i] = cn;
532  }
533  else
534  {
535  _hposcCoeffs[0] = (cn >> HPOSC_COEFF0_SHIFT) + ((int64_t)HPOSC_DC_BIAS << HPOSC_COEFF0_BITS); // p[0] is combined with the DC bias
536  }
537  }
538 }
static int64_t findNumerator(int32_t *pInput, int64_t *pBuf)
Definition: osc.c:474
uint8_t pu2b[4]
Definition: osc.c:443
#define HPOSC_COEFF0_SHIFT
Definition: osc.c:427
#define HPOSC_COEFF_BITS
Definition: osc.c:424
#define HPOSC_DC_BIAS
Definition: osc.c:429
static int64_t findDenominator(int64_t *col0, int64_t *col1, int64_t *col2)
Definition: osc.c:461
int64_t pu0c[4]
Definition: osc.c:444
static void multiplyColumns(int64_t *v1, int64_t *v2, int64_t *pBuf, uint8_t shift)
Definition: osc.c:450
int64_t pu1c[4]
Definition: osc.c:445
#define HPOSC_COEFF0_BITS
Definition: osc.c:425
#define HPOSC_SHIFT1
Definition: osc.c:428
uint8_t pu0b[4]
Definition: osc.c:441
uint8_t pu1b[4]
Definition: osc.c:442
int64_t pu2c[4]
Definition: osc.c:446
#define HPOSC_D_BITS
Definition: osc.c:426
int32_t _hposcCoeffs[4]
Definition: osc.c:431
Here is the call graph for this function:

§ findHposcPc()

static void findHposcPc ( int64_t *  pCoeff,
uint8_t *  pBits,
int32_t *  pTemp,
uint8_t  nTemp,
int64_t *  pOutput 
)
static

Referenced by OSC_HPOSC_Debug_InitFreqOffsetParams(), OSC_HPOSCInitializeFrequencyOffsetParameters(), and OSC_HPOSCInitializeSingleInsertionFreqOffsParams().

542 {
543  uint8_t i;
544  int32_t t1,t2,t3;
545 
546  for(i = 0; i < nTemp; i++)
547  {
548  t1 = pTemp[i];
549  t2 = t1*t1;
550  t3 = t2*t1;
551 
552  pOutput[i] = (((int64_t)pCoeff[0]*t3)>>(pBits[0]-HPOSC_COEFF_BITS)) + (((int64_t)pCoeff[1]*t2)>>(pBits[1]-HPOSC_COEFF_BITS)) +
553  (((int64_t)pCoeff[2]*t1)>>(pBits[2]-HPOSC_COEFF_BITS)) + (((int64_t)pCoeff[3] )>>(pBits[3]-HPOSC_COEFF_BITS));
554  }
555 }
#define HPOSC_COEFF_BITS
Definition: osc.c:424

§ findNumerator()

static int64_t findNumerator ( int32_t *  pInput,
int64_t *  pBuf 
)
static

Referenced by findHposcCoefficients().

475 {
476  int64_t tmp;
477 
478  tmp = ((int64_t)pInput[0]*pBuf[0]) - ((int64_t)pInput[0]*pBuf[1]) - ((int64_t)pInput[1]*pBuf[2]) +
479  ((int64_t)pInput[1]*pBuf[3]) + ((int64_t)pInput[2]*pBuf[4]) - ((int64_t)pInput[2]*pBuf[5]);
480 
481  return tmp;
482 }

§ InternCapArrayAdjustWithBaseline7001F()

static void InternCapArrayAdjustWithBaseline7001F ( int32_t  capArrayDelta)
static

Referenced by OSC_AdjustXoscHfCapArray(), and OSC_CapArrayAdjustWorkaround_Boot().

338 {
339  int32_t capArrayIndex ;
340  uint32_t row ;
341  uint32_t col ;
342 
343  capArrayIndex = 36 + capArrayDelta ; // index = 36 corresponds to row/col 7/001F (which corresponds to 6.1pF)
344  if ( capArrayIndex < 0 ) capArrayIndex = 0 ;
345  if ( capArrayIndex > 63 ) capArrayIndex = 63 ;
346  row = 0xF >> ( 3 - ( capArrayIndex >> 4 ));
347  col = 0xFFFF >> ( 15 - ( capArrayIndex & 0xF ));
348  HWREG( AUX_DDI0_OSC_BASE + DDI_0_OSC_O_ANABYPASSVAL1 ) = (( row << DDI_0_OSC_ANABYPASSVAL1_XOSC_HF_ROW_Q12_S ) |
349  ( col << DDI_0_OSC_ANABYPASSVAL1_XOSC_HF_COLUMN_Q12_S ) );
350 }

§ multiplyColumns()

static void multiplyColumns ( int64_t *  v1,
int64_t *  v2,
int64_t *  pBuf,
uint8_t  shift 
)
static

Referenced by findDenominator(), and findHposcCoefficients().

451 {
452  pBuf[0] = (v1[1]*v2[2]) >> shift;
453  pBuf[1] = (v1[2]*v2[1]) >> shift;
454  pBuf[2] = (v1[0]*v2[2]) >> shift;
455  pBuf[3] = (v1[2]*v2[0]) >> shift;
456  pBuf[4] = (v1[0]*v2[1]) >> shift;
457  pBuf[5] = (v1[1]*v2[0]) >> shift;
458 }

§ readTempAndFreq()

static void readTempAndFreq ( uint32_t  regAddr,
int32_t *  pTemp,
int32_t *  pdFreq,
int32_t  deltaFreq 
)
static

Referenced by OSC_HPOSC_Debug_InitFreqOffsetParams(), OSC_HPOSCInitializeFrequencyOffsetParameters(), and OSC_HPOSCInitializeSingleInsertionFreqOffsParams().

559 {
560  uint32_t insertionData = HWREG(regAddr);
561 
562  /* temp_stored = Temperature - 27, offset by -27C */
563  *pTemp = (((int32_t)( insertionData << ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_T1_W - FCFG1_HPOSC_MEAS_1_HPOSC_T1_S )))
564  >> ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_T1_W ));
565 
566  /* dFreq_stored = round( (Freq/12e6 - 1) * 2^22 ), 12MHz is the ideal frequency */
567  *pdFreq = (((int32_t)( insertionData << ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_D1_W - FCFG1_HPOSC_MEAS_1_HPOSC_D1_S )))
568  >> ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_D1_W ));
569  *pdFreq = *pdFreq + deltaFreq;
570 }

§ SpecialCapArrayWorkaroundEnabledAndNeeded()

static uint32_t SpecialCapArrayWorkaroundEnabledAndNeeded ( void  )
static

Referenced by OSC_AdjustXoscHfCapArray(), and OSC_CapArrayAdjustWorkaround_Boot().

354 {
355  if ((( HWREG( CCFG_BASE + CCFG_O_SIZE_AND_DIS_FLAGS ) & CCFG_SIZE_AND_DIS_FLAGS_DIS_LINEAR_CAPARRAY_DELTA_WORKAROUND ) == 0 ) &&
356  ((( HWREG( FCFG1_BASE + FCFG1_O_CONFIG_OSC_TOP ) >> FCFG1_CONFIG_OSC_TOP_XOSC_HF_COLUMN_Q12_S ) & 0x000FFFF1 ) == 0x000701F0 ) )
357  {
358  return ( 1 );
359  } else {
360  return ( 0 );
361  }
362 }

Variable Documentation

§ _hposcCoeffs

int32_t _hposcCoeffs[4] = {0}

§ oscHfGlobals

OscHfGlobals_t oscHfGlobals
static