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

385 {
386  int64_t tmp, tmpBuf[6];
387 
388  multiplyColumns(col1, col2, tmpBuf, HPOSC_SHIFT1); // Keep HPOSC_D_BITS precision
389 
390  tmp = (tmpBuf[0]*col0[0] - tmpBuf[1]*col0[0] - tmpBuf[2]*col0[1] +
391  tmpBuf[3]*col0[1] + tmpBuf[4]*col0[2] - tmpBuf[5]*col0[2]) >> HPOSC_COEFF_BITS;
392 
393  return tmp;
394 }
#define HPOSC_COEFF_BITS
Definition: osc.c:347
static void multiplyColumns(int64_t *v1, int64_t *v2, int64_t *pBuf, uint8_t shift)
Definition: osc.c:373
#define HPOSC_SHIFT1
Definition: osc.c:351
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().

409 {
410  int64_t d,c0,c1,c2,cn,tmpBuf[6];
411  int32_t inputBuf[3];
412  uint8_t i;
413 
414  if(col1 == NULL) /* 1 insertion */
415  {
416  inputBuf[0] = pInput[0] - HPOSC_DC_BIAS;
417  c0 = (((int64_t)inputBuf[0] << HPOSC_D_BITS) / col0[0]);
418  c1 = 0;
419  c2 = 0;
420  }
421  else /* 3 insertion */
422  {
423  /* Apply DC bias to input data */
424  for(i = 0; i < 3; i++)
425  {
426  inputBuf[i] = pInput[i] - HPOSC_DC_BIAS;
427  }
428 
429  /* Solve intermediate parameters, d: HPOSC_D_BITS, c: HPOSC_COEFF_BITS*2 bits */
430  d = findDenominator(col0, col1, col2);
431 
432  multiplyColumns(col1, col2, tmpBuf, 0);
433  cn = findNumerator(inputBuf, tmpBuf);
434  c0 = cn / d;
435 
436  multiplyColumns(col0, col2, tmpBuf, 0);
437  cn = -1*findNumerator(inputBuf, tmpBuf);
438  c1 = cn / d;
439 
440  multiplyColumns(col0, col1, tmpBuf, 0);
441  cn = findNumerator(inputBuf, tmpBuf);
442  c2 = cn / d;
443  }
444 
445  /* Compute TCF polynomial coefficients */
446  for(i = 0; i < 4; i++)
447  {
448  cn = (((pParam->pu0c[i]*c0) >> (pParam->pu0b[i] - HPOSC_COEFF_BITS)) +
449  ((pParam->pu1c[i]*c1) >> (pParam->pu1b[i] - HPOSC_COEFF_BITS)) +
450  ((pParam->pu2c[i]*c2) >> (pParam->pu2b[i] - HPOSC_COEFF_BITS))) >> HPOSC_SHIFT1;
451 
452  if(i<3)
453  {
454  _hposcCoeffs[3-i] = cn;
455  }
456  else
457  {
458  _hposcCoeffs[0] = (cn >> HPOSC_COEFF0_SHIFT) + ((int64_t)HPOSC_DC_BIAS << HPOSC_COEFF0_BITS); // p[0] is combined with the DC bias
459  }
460  }
461 }
static int64_t findNumerator(int32_t *pInput, int64_t *pBuf)
Definition: osc.c:397
uint8_t pu2b[4]
Definition: osc.c:366
#define HPOSC_COEFF0_SHIFT
Definition: osc.c:350
#define HPOSC_COEFF_BITS
Definition: osc.c:347
#define HPOSC_DC_BIAS
Definition: osc.c:352
static int64_t findDenominator(int64_t *col0, int64_t *col1, int64_t *col2)
Definition: osc.c:384
int64_t pu0c[4]
Definition: osc.c:367
static void multiplyColumns(int64_t *v1, int64_t *v2, int64_t *pBuf, uint8_t shift)
Definition: osc.c:373
int64_t pu1c[4]
Definition: osc.c:368
#define HPOSC_COEFF0_BITS
Definition: osc.c:348
#define HPOSC_SHIFT1
Definition: osc.c:351
uint8_t pu0b[4]
Definition: osc.c:364
uint8_t pu1b[4]
Definition: osc.c:365
int64_t pu2c[4]
Definition: osc.c:369
#define HPOSC_D_BITS
Definition: osc.c:349
int32_t _hposcCoeffs[4]
Definition: osc.c:354
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().

465 {
466  uint8_t i;
467  int32_t t1,t2,t3;
468 
469  for(i = 0; i < nTemp; i++)
470  {
471  t1 = pTemp[i];
472  t2 = t1*t1;
473  t3 = t2*t1;
474 
475  pOutput[i] = (((int64_t)pCoeff[0]*t3)>>(pBits[0]-HPOSC_COEFF_BITS)) + (((int64_t)pCoeff[1]*t2)>>(pBits[1]-HPOSC_COEFF_BITS)) +
476  (((int64_t)pCoeff[2]*t1)>>(pBits[2]-HPOSC_COEFF_BITS)) + (((int64_t)pCoeff[3] )>>(pBits[3]-HPOSC_COEFF_BITS));
477  }
478 }
#define HPOSC_COEFF_BITS
Definition: osc.c:347

§ findNumerator()

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

Referenced by findHposcCoefficients().

398 {
399  int64_t tmp;
400 
401  tmp = ((int64_t)pInput[0]*pBuf[0]) - ((int64_t)pInput[0]*pBuf[1]) - ((int64_t)pInput[1]*pBuf[2]) +
402  ((int64_t)pInput[1]*pBuf[3]) + ((int64_t)pInput[2]*pBuf[4]) - ((int64_t)pInput[2]*pBuf[5]);
403 
404  return tmp;
405 }

§ multiplyColumns()

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

Referenced by findDenominator(), and findHposcCoefficients().

374 {
375  pBuf[0] = (v1[1]*v2[2]) >> shift;
376  pBuf[1] = (v1[2]*v2[1]) >> shift;
377  pBuf[2] = (v1[0]*v2[2]) >> shift;
378  pBuf[3] = (v1[2]*v2[0]) >> shift;
379  pBuf[4] = (v1[0]*v2[1]) >> shift;
380  pBuf[5] = (v1[1]*v2[0]) >> shift;
381 }

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

482 {
483  uint32_t insertionData = HWREG(regAddr);
484 
485  /* temp_stored = Temperature - 27, offset by -27C */
486  *pTemp = (((int32_t)( insertionData << ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_T1_W - FCFG1_HPOSC_MEAS_1_HPOSC_T1_S )))
487  >> ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_T1_W ));
488 
489  /* dFreq_stored = round( (Freq/12e6 - 1) * 2^22 ), 12MHz is the ideal frequency */
490  *pdFreq = (((int32_t)( insertionData << ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_D1_W - FCFG1_HPOSC_MEAS_1_HPOSC_D1_S )))
491  >> ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_D1_W ));
492  *pdFreq = *pdFreq + deltaFreq;
493 }

Variable Documentation

§ _hposcCoeffs

int32_t _hposcCoeffs[4] = {0}

§ oscHfGlobals

OscHfGlobals_t oscHfGlobals
static