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

Variables

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

Macro Definition Documentation

#define D1OFFSET_25C   (-16)
#define D2OFFSET_85C   (-23)
#define D3OFFSET_n40C   (5)
#define HPOSC_COEFF0_BITS   (16)
#define HPOSC_COEFF_BITS   (20)
#define HPOSC_D_BITS   (30)

Referenced by findHposcCoefficients().

#define HPOSC_DC_BIAS   (100000)

Referenced by findHposcCoefficients().

#define HPOSC_SHIFT1   (2*HPOSC_COEFF_BITS - HPOSC_D_BITS)
#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 int64_t findDenominator ( int64_t *  col0,
int64_t *  col1,
int64_t *  col2 
)
static

Referenced by findHposcCoefficients().

382 {
383  int64_t tmp, tmpBuf[6];
384 
385  multiplyColumns(col1, col2, tmpBuf, HPOSC_SHIFT1); // Keep HPOSC_D_BITS precision
386 
387  tmp = (tmpBuf[0]*col0[0] - tmpBuf[1]*col0[0] - tmpBuf[2]*col0[1] +
388  tmpBuf[3]*col0[1] + tmpBuf[4]*col0[2] - tmpBuf[5]*col0[2]) >> HPOSC_COEFF_BITS;
389 
390  return tmp;
391 }
#define HPOSC_COEFF_BITS
Definition: osc.c:344
static void multiplyColumns(int64_t *v1, int64_t *v2, int64_t *pBuf, uint8_t shift)
Definition: osc.c:370
#define HPOSC_SHIFT1
Definition: osc.c:348

Here is the call graph for this function:

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

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

Here is the call graph for this function:

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

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

Referenced by findHposcCoefficients().

395 {
396  int64_t tmp;
397 
398  tmp = ((int64_t)pInput[0]*pBuf[0]) - ((int64_t)pInput[0]*pBuf[1]) - ((int64_t)pInput[1]*pBuf[2]) +
399  ((int64_t)pInput[1]*pBuf[3]) + ((int64_t)pInput[2]*pBuf[4]) - ((int64_t)pInput[2]*pBuf[5]);
400 
401  return tmp;
402 }
static void multiplyColumns ( int64_t *  v1,
int64_t *  v2,
int64_t *  pBuf,
uint8_t  shift 
)
static

Referenced by findDenominator(), and findHposcCoefficients().

371 {
372  pBuf[0] = (v1[1]*v2[2]) >> shift;
373  pBuf[1] = (v1[2]*v2[1]) >> shift;
374  pBuf[2] = (v1[0]*v2[2]) >> shift;
375  pBuf[3] = (v1[2]*v2[0]) >> shift;
376  pBuf[4] = (v1[0]*v2[1]) >> shift;
377  pBuf[5] = (v1[1]*v2[0]) >> shift;
378 }
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().

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

Variable Documentation

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