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

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

§ findDenominator()

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

Referenced by findHposcCoefficients().

450 {
451  int64_t tmp, tmpBuf[6];
452 
453  multiplyColumns(col1, col2, tmpBuf, HPOSC_SHIFT1); // Keep HPOSC_D_BITS precision
454 
455  tmp = (tmpBuf[0]*col0[0] - tmpBuf[1]*col0[0] - tmpBuf[2]*col0[1] +
456  tmpBuf[3]*col0[1] + tmpBuf[4]*col0[2] - tmpBuf[5]*col0[2]) >> HPOSC_COEFF_BITS;
457 
458  return tmp;
459 }
#define HPOSC_COEFF_BITS
Definition: osc.c:412
static void multiplyColumns(int64_t *v1, int64_t *v2, int64_t *pBuf, uint8_t shift)
Definition: osc.c:438
#define HPOSC_SHIFT1
Definition: osc.c:416
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().

474 {
475  int64_t d,c0,c1,c2,cn,tmpBuf[6];
476  int32_t inputBuf[3];
477  uint8_t i;
478 
479  if(col1 == NULL) /* 1 insertion */
480  {
481  inputBuf[0] = pInput[0] - HPOSC_DC_BIAS;
482  c0 = (((int64_t)inputBuf[0] << HPOSC_D_BITS) / col0[0]);
483  c1 = 0;
484  c2 = 0;
485  }
486  else /* 3 insertion */
487  {
488  /* Apply DC bias to input data */
489  for(i = 0; i < 3; i++)
490  {
491  inputBuf[i] = pInput[i] - HPOSC_DC_BIAS;
492  }
493 
494  /* Solve intermediate parameters, d: HPOSC_D_BITS, c: HPOSC_COEFF_BITS*2 bits */
495  d = findDenominator(col0, col1, col2);
496 
497  multiplyColumns(col1, col2, tmpBuf, 0);
498  cn = findNumerator(inputBuf, tmpBuf);
499  c0 = cn / d;
500 
501  multiplyColumns(col0, col2, tmpBuf, 0);
502  cn = -1*findNumerator(inputBuf, tmpBuf);
503  c1 = cn / d;
504 
505  multiplyColumns(col0, col1, tmpBuf, 0);
506  cn = findNumerator(inputBuf, tmpBuf);
507  c2 = cn / d;
508  }
509 
510  /* Compute TCF polynomial coefficients */
511  for(i = 0; i < 4; i++)
512  {
513  cn = (((pParam->pu0c[i]*c0) >> (pParam->pu0b[i] - HPOSC_COEFF_BITS)) +
514  ((pParam->pu1c[i]*c1) >> (pParam->pu1b[i] - HPOSC_COEFF_BITS)) +
515  ((pParam->pu2c[i]*c2) >> (pParam->pu2b[i] - HPOSC_COEFF_BITS))) >> HPOSC_SHIFT1;
516 
517  if(i<3)
518  {
519  _hposcCoeffs[3-i] = cn;
520  }
521  else
522  {
523  _hposcCoeffs[0] = (cn >> HPOSC_COEFF0_SHIFT) + ((int64_t)HPOSC_DC_BIAS << HPOSC_COEFF0_BITS); // p[0] is combined with the DC bias
524  }
525  }
526 }
static int64_t findNumerator(int32_t *pInput, int64_t *pBuf)
Definition: osc.c:462
uint8_t pu2b[4]
Definition: osc.c:431
#define HPOSC_COEFF0_SHIFT
Definition: osc.c:415
#define HPOSC_COEFF_BITS
Definition: osc.c:412
#define HPOSC_DC_BIAS
Definition: osc.c:417
static int64_t findDenominator(int64_t *col0, int64_t *col1, int64_t *col2)
Definition: osc.c:449
int64_t pu0c[4]
Definition: osc.c:432
static void multiplyColumns(int64_t *v1, int64_t *v2, int64_t *pBuf, uint8_t shift)
Definition: osc.c:438
int64_t pu1c[4]
Definition: osc.c:433
#define HPOSC_COEFF0_BITS
Definition: osc.c:413
#define HPOSC_SHIFT1
Definition: osc.c:416
uint8_t pu0b[4]
Definition: osc.c:429
uint8_t pu1b[4]
Definition: osc.c:430
int64_t pu2c[4]
Definition: osc.c:434
#define HPOSC_D_BITS
Definition: osc.c:414
int32_t _hposcCoeffs[4]
Definition: osc.c:419
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().

530 {
531  uint8_t i;
532  int32_t t1,t2,t3;
533 
534  for(i = 0; i < nTemp; i++)
535  {
536  t1 = pTemp[i];
537  t2 = t1*t1;
538  t3 = t2*t1;
539 
540  pOutput[i] = (((int64_t)pCoeff[0]*t3)>>(pBits[0]-HPOSC_COEFF_BITS)) + (((int64_t)pCoeff[1]*t2)>>(pBits[1]-HPOSC_COEFF_BITS)) +
541  (((int64_t)pCoeff[2]*t1)>>(pBits[2]-HPOSC_COEFF_BITS)) + (((int64_t)pCoeff[3] )>>(pBits[3]-HPOSC_COEFF_BITS));
542  }
543 }
#define HPOSC_COEFF_BITS
Definition: osc.c:412

§ findNumerator()

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

Referenced by findHposcCoefficients().

463 {
464  int64_t tmp;
465 
466  tmp = ((int64_t)pInput[0]*pBuf[0]) - ((int64_t)pInput[0]*pBuf[1]) - ((int64_t)pInput[1]*pBuf[2]) +
467  ((int64_t)pInput[1]*pBuf[3]) + ((int64_t)pInput[2]*pBuf[4]) - ((int64_t)pInput[2]*pBuf[5]);
468 
469  return tmp;
470 }

§ InternCapArrayAdjustWithBaseline7001F()

static void InternCapArrayAdjustWithBaseline7001F ( int32_t  capArrayDelta)
static

Referenced by OSC_AdjustXoscHfCapArray(), and OSC_CapArrayAdjustWorkaround_Boot().

326 {
327  int32_t capArrayIndex ;
328  uint32_t row ;
329  uint32_t col ;
330 
331  capArrayIndex = 36 + capArrayDelta ; // index = 36 corresponds to row/col 7/001F (which corresponds to 6.1pF)
332  if ( capArrayIndex < 0 ) capArrayIndex = 0 ;
333  if ( capArrayIndex > 63 ) capArrayIndex = 63 ;
334  row = 0xF >> ( 3 - ( capArrayIndex >> 4 ));
335  col = 0xFFFF >> ( 15 - ( capArrayIndex & 0xF ));
336  HWREG( AUX_DDI0_OSC_BASE + DDI_0_OSC_O_ANABYPASSVAL1 ) = (( row << DDI_0_OSC_ANABYPASSVAL1_XOSC_HF_ROW_Q12_S ) |
337  ( col << DDI_0_OSC_ANABYPASSVAL1_XOSC_HF_COLUMN_Q12_S ) );
338 }

§ multiplyColumns()

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

Referenced by findDenominator(), and findHposcCoefficients().

439 {
440  pBuf[0] = (v1[1]*v2[2]) >> shift;
441  pBuf[1] = (v1[2]*v2[1]) >> shift;
442  pBuf[2] = (v1[0]*v2[2]) >> shift;
443  pBuf[3] = (v1[2]*v2[0]) >> shift;
444  pBuf[4] = (v1[0]*v2[1]) >> shift;
445  pBuf[5] = (v1[1]*v2[0]) >> shift;
446 }

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

547 {
548  uint32_t insertionData = HWREG(regAddr);
549 
550  /* temp_stored = Temperature - 27, offset by -27C */
551  *pTemp = (((int32_t)( insertionData << ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_T1_W - FCFG1_HPOSC_MEAS_1_HPOSC_T1_S )))
552  >> ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_T1_W ));
553 
554  /* dFreq_stored = round( (Freq/12e6 - 1) * 2^22 ), 12MHz is the ideal frequency */
555  *pdFreq = (((int32_t)( insertionData << ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_D1_W - FCFG1_HPOSC_MEAS_1_HPOSC_D1_S )))
556  >> ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_D1_W ));
557  *pdFreq = *pdFreq + deltaFreq;
558 }

§ SpecialCapArrayWorkaroundEnabledAndNeeded()

static uint32_t SpecialCapArrayWorkaroundEnabledAndNeeded ( void  )
static

Referenced by OSC_AdjustXoscHfCapArray(), and OSC_CapArrayAdjustWorkaround_Boot().

342 {
343  if ((( HWREG( CCFG_BASE + CCFG_O_SIZE_AND_DIS_FLAGS ) & CCFG_SIZE_AND_DIS_FLAGS_DIS_LINEAR_CAPARRAY_DELTA_WORKAROUND ) == 0 ) &&
344  ((( HWREG( FCFG1_BASE + FCFG1_O_CONFIG_OSC_TOP ) >> FCFG1_CONFIG_OSC_TOP_XOSC_HF_COLUMN_Q12_S ) & 0x000FFFF1 ) == 0x000701F0 ) )
345  {
346  return ( 1 );
347  } else {
348  return ( 0 );
349  }
350 }

Variable Documentation

§ _hposcCoeffs

int32_t _hposcCoeffs[4] = {0}

§ oscHfGlobals

OscHfGlobals_t oscHfGlobals
static