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

397 {
398  int64_t tmp, tmpBuf[6];
399 
400  multiplyColumns(col1, col2, tmpBuf, HPOSC_SHIFT1); // Keep HPOSC_D_BITS precision
401 
402  tmp = (tmpBuf[0]*col0[0] - tmpBuf[1]*col0[0] - tmpBuf[2]*col0[1] +
403  tmpBuf[3]*col0[1] + tmpBuf[4]*col0[2] - tmpBuf[5]*col0[2]) >> HPOSC_COEFF_BITS;
404 
405  return tmp;
406 }
#define HPOSC_COEFF_BITS
Definition: osc.c:359
static void multiplyColumns(int64_t *v1, int64_t *v2, int64_t *pBuf, uint8_t shift)
Definition: osc.c:385
#define HPOSC_SHIFT1
Definition: osc.c:363
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().

421 {
422  int64_t d,c0,c1,c2,cn,tmpBuf[6];
423  int32_t inputBuf[3];
424  uint8_t i;
425 
426  if(col1 == NULL) /* 1 insertion */
427  {
428  inputBuf[0] = pInput[0] - HPOSC_DC_BIAS;
429  c0 = (((int64_t)inputBuf[0] << HPOSC_D_BITS) / col0[0]);
430  c1 = 0;
431  c2 = 0;
432  }
433  else /* 3 insertion */
434  {
435  /* Apply DC bias to input data */
436  for(i = 0; i < 3; i++)
437  {
438  inputBuf[i] = pInput[i] - HPOSC_DC_BIAS;
439  }
440 
441  /* Solve intermediate parameters, d: HPOSC_D_BITS, c: HPOSC_COEFF_BITS*2 bits */
442  d = findDenominator(col0, col1, col2);
443 
444  multiplyColumns(col1, col2, tmpBuf, 0);
445  cn = findNumerator(inputBuf, tmpBuf);
446  c0 = cn / d;
447 
448  multiplyColumns(col0, col2, tmpBuf, 0);
449  cn = -1*findNumerator(inputBuf, tmpBuf);
450  c1 = cn / d;
451 
452  multiplyColumns(col0, col1, tmpBuf, 0);
453  cn = findNumerator(inputBuf, tmpBuf);
454  c2 = cn / d;
455  }
456 
457  /* Compute TCF polynomial coefficients */
458  for(i = 0; i < 4; i++)
459  {
460  cn = (((pParam->pu0c[i]*c0) >> (pParam->pu0b[i] - HPOSC_COEFF_BITS)) +
461  ((pParam->pu1c[i]*c1) >> (pParam->pu1b[i] - HPOSC_COEFF_BITS)) +
462  ((pParam->pu2c[i]*c2) >> (pParam->pu2b[i] - HPOSC_COEFF_BITS))) >> HPOSC_SHIFT1;
463 
464  if(i<3)
465  {
466  _hposcCoeffs[3-i] = cn;
467  }
468  else
469  {
470  _hposcCoeffs[0] = (cn >> HPOSC_COEFF0_SHIFT) + ((int64_t)HPOSC_DC_BIAS << HPOSC_COEFF0_BITS); // p[0] is combined with the DC bias
471  }
472  }
473 }
static int64_t findNumerator(int32_t *pInput, int64_t *pBuf)
Definition: osc.c:409
uint8_t pu2b[4]
Definition: osc.c:378
#define HPOSC_COEFF0_SHIFT
Definition: osc.c:362
#define HPOSC_COEFF_BITS
Definition: osc.c:359
#define HPOSC_DC_BIAS
Definition: osc.c:364
static int64_t findDenominator(int64_t *col0, int64_t *col1, int64_t *col2)
Definition: osc.c:396
int64_t pu0c[4]
Definition: osc.c:379
static void multiplyColumns(int64_t *v1, int64_t *v2, int64_t *pBuf, uint8_t shift)
Definition: osc.c:385
int64_t pu1c[4]
Definition: osc.c:380
#define HPOSC_COEFF0_BITS
Definition: osc.c:360
#define HPOSC_SHIFT1
Definition: osc.c:363
uint8_t pu0b[4]
Definition: osc.c:376
uint8_t pu1b[4]
Definition: osc.c:377
int64_t pu2c[4]
Definition: osc.c:381
#define HPOSC_D_BITS
Definition: osc.c:361
int32_t _hposcCoeffs[4]
Definition: osc.c:366
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().

477 {
478  uint8_t i;
479  int32_t t1,t2,t3;
480 
481  for(i = 0; i < nTemp; i++)
482  {
483  t1 = pTemp[i];
484  t2 = t1*t1;
485  t3 = t2*t1;
486 
487  pOutput[i] = (((int64_t)pCoeff[0]*t3)>>(pBits[0]-HPOSC_COEFF_BITS)) + (((int64_t)pCoeff[1]*t2)>>(pBits[1]-HPOSC_COEFF_BITS)) +
488  (((int64_t)pCoeff[2]*t1)>>(pBits[2]-HPOSC_COEFF_BITS)) + (((int64_t)pCoeff[3] )>>(pBits[3]-HPOSC_COEFF_BITS));
489  }
490 }
#define HPOSC_COEFF_BITS
Definition: osc.c:359

§ findNumerator()

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

Referenced by findHposcCoefficients().

410 {
411  int64_t tmp;
412 
413  tmp = ((int64_t)pInput[0]*pBuf[0]) - ((int64_t)pInput[0]*pBuf[1]) - ((int64_t)pInput[1]*pBuf[2]) +
414  ((int64_t)pInput[1]*pBuf[3]) + ((int64_t)pInput[2]*pBuf[4]) - ((int64_t)pInput[2]*pBuf[5]);
415 
416  return tmp;
417 }

§ multiplyColumns()

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

Referenced by findDenominator(), and findHposcCoefficients().

386 {
387  pBuf[0] = (v1[1]*v2[2]) >> shift;
388  pBuf[1] = (v1[2]*v2[1]) >> shift;
389  pBuf[2] = (v1[0]*v2[2]) >> shift;
390  pBuf[3] = (v1[2]*v2[0]) >> shift;
391  pBuf[4] = (v1[0]*v2[1]) >> shift;
392  pBuf[5] = (v1[1]*v2[0]) >> shift;
393 }

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

494 {
495  uint32_t insertionData = HWREG(regAddr);
496 
497  /* temp_stored = Temperature - 27, offset by -27C */
498  *pTemp = (((int32_t)( insertionData << ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_T1_W - FCFG1_HPOSC_MEAS_1_HPOSC_T1_S )))
499  >> ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_T1_W ));
500 
501  /* dFreq_stored = round( (Freq/12e6 - 1) * 2^22 ), 12MHz is the ideal frequency */
502  *pdFreq = (((int32_t)( insertionData << ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_D1_W - FCFG1_HPOSC_MEAS_1_HPOSC_D1_S )))
503  >> ( 32 - FCFG1_HPOSC_MEAS_1_HPOSC_D1_W ));
504  *pdFreq = *pdFreq + deltaFreq;
505 }

Variable Documentation

§ _hposcCoeffs

int32_t _hposcCoeffs[4] = {0}

§ oscHfGlobals

OscHfGlobals_t oscHfGlobals
static