CC26xx Driver Library
[osc.h] Oscillator

Data Structures

struct  HposcDebugData_t
 Data structure for experimental HPOSC polynomials calculation. More...
 

Functions

static void OSCXHfPowerModeSet (uint32_t ui32Mode)
 Set Power Mode for High Frequency XTAL Oscillator. More...
 
static void OSCClockLossEventEnable (void)
 Enables OSC clock loss event detection. More...
 
static void OSCClockLossEventDisable (void)
 Disables OSC clock loss event detection. More...
 
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...
 
static bool OSCHfSourceReady (void)
 Check if the HF clock source is ready to be switched. More...
 
static void OSCHfSourceSwitch (void)
 Switch the high frequency clock. More...
 
static bool OSC_IsHPOSCEnabled (void)
 Identifies if HPOSC is enabled. More...
 
static bool OSC_IsHPOSCEnabledWithHfDerivedLfClock (void)
 Identifies if HPOSC is enabled and that SCLK_LF is derived from XOSC_HF. 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...
 
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...
 
void OSC_HPOSC_Debug_InitFreqOffsetParams (HposcDebugData_t *pDebugData)
 Debug function to calculate the HPOSC polynomials for experimental data sets. More...
 
void OSC_HPOSCInitializeFrequencyOffsetParameters (void)
 HPOSC initialization function. Must always be called before using HPOSC. More...
 
int32_t OSC_HPOSCRelativeFrequencyOffsetGet (int32_t tempDegC)
 Calculate the temperature dependent relative frequency offset of HPOSC. More...
 
void OSC_AdjustXoscHfCapArray (int32_t capArrDelta)
 Adjust the XOSC HF cap array relative to the factory setting. 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...
 

Detailed Description

Function Documentation

void OSC_AdjustXoscHfCapArray ( int32_t  capArrDelta)

Adjust the XOSC HF cap array relative to the factory setting.

The cap array factory setting (FCFG) can be converted to a number in the range 0 - 63. Both this function and the customer configuration (CCFG) setting can apply a delta to the FCFG setting. The CCFG setting is automatically applied at boot time (See ../startup_files/ccfg.c). Calling this function will discard the CCFG setting and adjust relative to the FCFG setting.

Note
Adjusted value will not take effect before XOSC_HF is stopped and restarted
Parameters
capArrDeltaspecifies number of step to adjust the cap array relative to the factory setting.
Returns
None
332 {
333  // read the MODE_CONF register in CCFG
334  uint32_t ccfg_ModeConfReg = HWREG( CCFG_BASE + CCFG_O_MODE_CONF );
335  // Clear CAP_MODE and the CAPARRAY_DELATA field
337  // Insert new delta value
338  ccfg_ModeConfReg |= ((((uint32_t)capArrDelta) << CCFG_MODE_CONF_XOSC_CAPARRAY_DELTA_S ) & CCFG_MODE_CONF_XOSC_CAPARRAY_DELTA_M );
339  // Update the HW register with the new delta value
341 }
uint32_t SetupGetTrimForAnabypassValue1(uint32_t ccfg_ModeConfReg)
Returns the trim value to be used for the ANABYPASS_VALUE1 register in OSC_DIG.
Definition: setup_rom.c:438
void DDI32RegWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Val)
Write a 32 bit value to a register in the DDI slave.
Definition: ddi.c:66

Here is the call graph for this function:

void OSC_HPOSC_Debug_InitFreqOffsetParams ( HposcDebugData_t pDebugData)

Debug function to calculate the HPOSC polynomials for experimental data sets.

Parameters
pDebugDatapointer to the input data collected in HposcDebugData_t
Returns
None
See also
OSC_HPOSCInitializeFrequencyOffsetParameters()
438 {
439  // Calculate the curve fitting parameters from temp insertion measurements
440  // But first adjust the measurements with constants found in characterization
441  insertion_t pMeasurment[ 3 ];
442 
443  InitializeMeasurmentSet( &pMeasurment[ 0 ], (uint32_t)&pDebugData->meas_1, pDebugData->offsetD1, pDebugData->polyP3 );
444  InitializeMeasurmentSet( &pMeasurment[ 1 ], (uint32_t)&pDebugData->meas_2, pDebugData->offsetD2, pDebugData->polyP3 );
445  InitializeMeasurmentSet( &pMeasurment[ 2 ], (uint32_t)&pDebugData->meas_3, pDebugData->offsetD3, pDebugData->polyP3 );
446 
447  FindPolynomialsAndUpdateGlobals( pMeasurment );
448 }
int32_t polyP3
The P3 polynomial.
Definition: osc.h:501
static void FindPolynomialsAndUpdateGlobals(insertion_t *pMeasurment)
Definition: osc.c:377
int32_t offsetD3
Offset to measurement set 3.
Definition: osc.h:500
int32_t offsetD1
Offset to measurement set 1.
Definition: osc.h:498
uint32_t meas_1
Measurement set 1 (typically at room temp)
Definition: osc.h:495
Definition: osc.c:358
uint32_t meas_3
Measurement set 3 (typically at low temp)
Definition: osc.h:497
int32_t offsetD2
Offset to measurement set 2.
Definition: osc.h:499
static void InitializeMeasurmentSet(insertion_t *pInsertion, uint32_t registerAddress, int32_t deltaOffset, int32_t p3PolOffset)
Definition: osc.c:364
uint32_t meas_2
Measurement set 2 (typically at high temp)
Definition: osc.h:496

Here is the call graph for this function:

void OSC_HPOSCInitializeFrequencyOffsetParameters ( void  )

HPOSC initialization function. Must always be called before using HPOSC.

Calculates the fitting curve parameters (polynomials) to used by the HPOSC temperature compensation.

Returns
None
See also
OSC_HPOSC_Debug_InitFreqOffsetParams()
455 {
456  {
457  // Calculate the curve fitting parameters from temp insertion measurements
458  // But first adjust the measurements with constants found in characterization
459  insertion_t pMeasurment[ 3 ];
460 
464 
465  FindPolynomialsAndUpdateGlobals( pMeasurment );
466  }
467 }
static void FindPolynomialsAndUpdateGlobals(insertion_t *pMeasurment)
Definition: osc.c:377
#define P3_POLYNOMIAL
Definition: osc.c:355
Definition: osc.c:358
#define D1OFFSET_p25C
Definition: osc.c:352
static void InitializeMeasurmentSet(insertion_t *pInsertion, uint32_t registerAddress, int32_t deltaOffset, int32_t p3PolOffset)
Definition: osc.c:364
#define D3OFFSET_m40C
Definition: osc.c:354
#define D2OFFSET_p85C
Definition: osc.c:353

Here is the call graph for this function:

int32_t OSC_HPOSCRelativeFrequencyOffsetGet ( int32_t  tempDegC)

Calculate the temperature dependent relative frequency offset of HPOSC.

The HPOSC (High Precision Oscillator) frequency will vary slightly with chip temperature. The frequency offset from the nominal value can be predicted based on second order linear interpolation using coefficients measured in chip production and stored as factory configuration parameters.

This function calculates the relative frequency offset, defined as:

    F_HPOSC = F_nom * (1 + d/(2^22))

where

  • F_HPOSC is the current HPOSC frequency.
  • F_nom is the nominal oscillator frequency, assumed to be 48.000 MHz.
  • d is the relative frequency offset (the value returned).

By knowing the relative frequency offset it is then possible to compensate any timing related values accordingly.

Parameters
tempDegCis the chip temperature in degrees Celsius. Use the function AONBatMonTemperatureGetDegC() to get current chip temperature.
Returns
Returns the relative frequency offset parameter d.
See also
OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert(), AONBatMonTemperatureGetDegC()
476 {
477  // Estimate HPOSC frequency, using temperature and curve fitting parameters
478 
479  int32_t paramP0 = _hpOscPolynomials[ 0 ];
480  int32_t paramP1 = _hpOscPolynomials[ 1 ];
481  int32_t paramP2 = _hpOscPolynomials[ 2 ];
482  int32_t paramP3 = _hpOscPolynomials[ 3 ];
483 
484  // Now we can find the HPOSC freq offset, given as a signed variable d, expressed by:
485  //
486  // F_HPOSC = F_nom * (1 + d/(2^22)) , where: F_HPOSC = HPOSC frequency
487  // F_nom = nominal clock source frequency (e.g. 48.000 MHz)
488  // d = describes relative freq offset
489 
490  // We can estimate the d variable, using temperature compensation parameters:
491  //
492  // d = P0 + P1*(t - T0) + P2*(t - T0)^2 + P3*(t - T0)^3, where: P0,P1,P2,P3 are curve fitting parameters from FCFG1
493  // t = current temperature (from temp sensor) in deg C
494  // T0 = 27 deg C (fixed temperature constant)
495  int32_t tempDelta = (tempDegC - 27);
496  int32_t tempDeltaX2 = tempDelta * tempDelta;
497  int32_t d = paramP0 + ((tempDelta*paramP1)>>3) + ((tempDeltaX2*paramP2)>>10) + ((tempDeltaX2*tempDelta*paramP3)>>18);
498 
499  return ( d );
500 }
static int16_t _hpOscPolynomials[4]
Definition: osc.c:94
int16_t OSC_HPOSCRelativeFrequencyOffsetToRFCoreFormatConvert ( int32_t  HPOSC_RelFreqOffset)

Converts the relative frequency offset of HPOSC to the RF Core parameter format.

The HPOSC (High Precision Oscillator) clock is used by the RF Core. To compensate for a frequency offset in the frequency of the clock source, a frequency offset parameter can be provided as part of the radio configuration override setting list to enable compensation of the RF synthesizer frequency, symbol timing, and radio timer to still achieve correct frequencies.

The RF Core takes a relative frequency offset parameter defined differently compared to the relative frequency offset parameter returned from function OSC_HPOSCRelativeFrequencyOffsetGet() and thus needs to be converted:

    F_nom = F_HPOSC * (1 + RfCoreRelFreqOffset/(2^22))

where

  • F_nom is the nominal oscillator frequency, assumed to be 48.000 MHz.
  • F_HPOSC is the current HPOSC frequency.
  • RfCoreRelFreqOffset is the relative frequency offset in the "RF Core" format (the value returned).
Parameters
HPOSC_RelFreqOffsetis the relative frequency offset parameter d returned from OSC_HPOSCRelativeFrequencyOffsetGet()
Returns
Returns the relative frequency offset in RF Core format.
See also
OSC_HPOSCRelativeFrequencyOffsetGet()
509 {
510  // The input argument, hereby referred to simply as "d", describes the frequency offset
511  // of the HPOSC relative to the nominal frequency in this way:
512  //
513  // F_HPOSC = F_nom * (1 + d/(2^22))
514  //
515  // But for use by the radio, to compensate the frequency error, we need to find the
516  // frequency offset "rfcFreqOffset" defined in the following format:
517  //
518  // F_nom = F_HPOSC * (1 + rfCoreFreqOffset/(2^22))
519  //
520  // To derive "rfCoreFreqOffset" from "d" we combine the two above equations and get:
521  //
522  // (1 + rfCoreFreqOffset/(2^22)) = (1 + d/(2^22))^-1
523  //
524  // Which can be rewritten into:
525  //
526  // rfCoreFreqOffset = -d*(2^22) / ((2^22) + d)
527  //
528  // = -d * [ 1 / (1 + d/(2^22)) ]
529  //
530  // To avoid doing a 64-bit division due to the (1 + d/(2^22))^-1 expression,
531  // we can use Taylor series (Maclaurin series) to approximate it:
532  //
533  // 1 / (1 - x) ~= 1 + x + x^2 + x^3 + x^4 + ... etc (Maclaurin series)
534  //
535  // In our case, we have x = - d/(2^22), and we only include up to the first
536  // order term of the series, as the second order term ((d^2)/(2^44)) is very small:
537  //
538  // freqError ~= -d + d^2/(2^22) (+ small approximation error)
539  //
540  // The approximation error is negligible for our use.
541 
542  int32_t rfCoreFreqOffset = -HPOSC_RelFreqOffset + (( HPOSC_RelFreqOffset * HPOSC_RelFreqOffset ) >> 22 );
543 
544  return ( rfCoreFreqOffset );
545 }
void OSC_HPOSCRtcCompensate ( int32_t  relFreqOffset)

Compensate the RTC increment based on the relative frequency offset of HPOSC.

The HPOSC (High Precision Oscillator) frequency will vary slightly with chip temperature. This variation forces the RTC increment to be compensated if SCLK_LF is configured to be derived from the HF clock of HPOSC. This function must only be called if SCLK_LF is configured to be derived from the HF clock of HPOSC. The status of this configuration can be determined by calling the OSC_IsHPOSCEnabledWithHfDerivedLfClock() function.

This function first calculates the HPOSC frequency, defined as:

    F_HPOSC = F_nom * (1 + d/(2^22))

where

  • F_HPOSC is the current HPOSC frequency.
  • F_nom is the nominal oscillator frequency, assumed to be 48.000 MHz.
  • d is the relative frequency offset given by the input argument relFreqOffset. Then the SCLK_LF frequency is calculated, defined as:
        F_SCLK_LF = F_HPOSC / 1536
    
    Then the RTC increment SUBSECINC is calculated, defined as;
        SUBSECINC = (2^38) / F_SCLK_LF
    
    Finally the RTC module is updated with the calculated SUBSECINC value.
Parameters
relFreqOffsetis the relative frequency offset parameter d returned from OSC_HPOSCRelativeFrequencyOffsetGet()
Returns
None
554 {
555  uint32_t rtcSubSecInc;
556  uint32_t lfClkFrequency;
557  uint32_t hfFreq;
558  int64_t calcFactor;
559 
560  // Calculate SCLK_HF frequency, defined as:
561  // hfFreq = 48000000 * (1 + relFreqOffset/(2^22))
562  if( relFreqOffset >= 0 )
563  {
564  calcFactor = ( ( 48000000 * (int64_t)relFreqOffset ) + 0x200000 ) / 0x400000;
565  }
566  else
567  {
568  calcFactor = ( ( 48000000 * (int64_t)relFreqOffset ) - 0x200000 ) / 0x400000;
569  }
570  hfFreq = 48000000 + calcFactor;
571 
572  // Calculate SCLK_LF frequency, defined as SCLK_LF_FREQ = SCLK_HF_FREQ / 1536
573  lfClkFrequency = ( hfFreq + 768 ) / 1536;
574 
575  // Calculate SUBSECINC, defined as: SUBSECINC = 2^38 / SCLK_LF_FREQ
576  rtcSubSecInc = 0x4000000000 / lfClkFrequency;
577 
578  /* Update SUBSECINC value */
579  SetupSetAonRtcSubSecInc(rtcSubSecInc);
580 }
void SetupSetAonRtcSubSecInc(uint32_t subSecInc)
Doing the tricky stuff needed to enter new RTCSUBSECINC value.
Definition: setup_rom.c:929

Here is the call graph for this function:

static bool OSC_IsHPOSCEnabled ( void  )
inlinestatic

Identifies if HPOSC is enabled.

This function checks if the device supports HPOSC and that HPOSC is selected as HF oscillator for use when the radio is active.

Returns
Returns status of HPOSC functionality:
  • true : HPOSC is enabled.
  • false : HPOSC is not enabled.
352 {
353  bool enabled = false;
354 
357  {
358  enabled = true;
359  }
360 
361  return (enabled);
362 }
static bool OSC_IsHPOSCEnabledWithHfDerivedLfClock ( void  )
inlinestatic

Identifies if HPOSC is enabled and that SCLK_LF is derived from XOSC_HF.

This function checks if the device supports HPOSC and that HPOSC is selected as HF oscillator for use when the radio is active and also that SCLK_LF is derived from XOSC_HF.

Returns
Returns status of HPOSC and SCLK_LF configuration:
  • true : HPOSC is enabled and SCLK_LF is derived from XOSC_HF.
  • false : Either HPOSC not enabled or SCLK_LF is not derived from XOSC_HF.
379 {
380  bool enabled = false;
381 
382  // Check configuration by reading lower half of the 32-bit CTL0 register
383  uint16_t regVal = HWREGH(AUX_DDI0_OSC_BASE + DDI_0_OSC_O_CTL0);
386  {
387  enabled = true;
388  }
389 
390  return (enabled);
391 }
static void OSCClockLossEventDisable ( void  )
inlinestatic

Disables OSC clock loss event detection.

Disabling the OSC clock loss event does also clear the clock loss event flag.

Note
OSC clock loss event must be disabled before SCLK_LF clock source is changed (by calling OSCClockSourceSet()) and remain disabled until the change is confirmed (by calling OSCClockSourceGet()).
Returns
None
See also
OSCClockLossEventEnable()
203 {
207 }
void DDI16BitfieldWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask, uint32_t ui32Shift, uint16_t ui32Data)
Write a bit field via the DDI using 16-bit maskable write.
Definition: ddi.c:117

Here is the call graph for this function:

static void OSCClockLossEventEnable ( void  )
inlinestatic

Enables OSC clock loss event detection.

Enables the clock loss event flag to be raised if a clock loss is detected.

Note
OSC clock loss event must be disabled before SCLK_LF clock source is changed (by calling OSCClockSourceSet()) and remain disabled until the change is confirmed (by calling OSCClockSourceGet()).
Returns
None
See also
OSCClockLossEventDisable()
180 {
184 }
void DDI16BitfieldWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask, uint32_t ui32Shift, uint16_t ui32Data)
Write a bit field via the DDI using 16-bit maskable write.
Definition: ddi.c:117

Here is the call graph for this function:

uint32_t OSCClockSourceGet ( uint32_t  ui32SrcClk)

Get the source clock settings.

Use this function to get the oscillator source for one of the system source clocks.

Parameters
ui32SrcClkis the source clock to check.
Returns
Returns the type of oscillator that drives the clock source.
See also
OSCClockSourceSet(), OSCHfSourceSwitch()

Referenced by OSCHF_AttemptToSwitchToXosc(), OSCHF_SwitchToRcOscTurnOffXosc(), and SetupAfterColdResetWakeupFromShutDownCfg3().

159 {
160  uint32_t ui32ClockSource;
161 
162  // Check the arguments.
163  ASSERT((ui32SrcClk & OSC_SRC_CLK_LF) ||
164  (ui32SrcClk & OSC_SRC_CLK_HF));
165 
166  // Return the source for the selected clock.
167  if(ui32SrcClk == OSC_SRC_CLK_LF)
168  {
172  }
173  else
174  {
178  }
179  return (ui32ClockSource);
180 }
#define OSC_SRC_CLK_HF
Definition: osc.h:118
#define OSC_SRC_CLK_LF
Definition: osc.h:119
uint16_t DDI16BitfieldRead(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask, uint32_t ui32Shift)
Read a bit field via the DDI using 16-bit read.
Definition: ddi.c:185
#define ASSERT(expr)
Definition: debug.h:73

Here is the call graph for this function:

void OSCClockSourceSet ( uint32_t  ui32SrcClk,
uint32_t  ui32Osc 
)

Configure the oscillator input to the a source clock.

Use this function to set the oscillator source for one or more of the system source clocks.

When selecting the high frequency clock source (OSC_SRC_CLK_HF), this function will not do the actual switch. Enabling the high frequency XTAL can take several hundred micro seconds, so the actual switch is done in a separate function, OSCHfSourceSwitch(), leaving System CPU free to perform other tasks as the XTAL starts up.

Note
The High Frequency (OSC_SRC_CLK_HF) can only be derived from the high frequency oscillator. The Low Frequency source clock (OSC_SRC_CLK_LF) can be derived from all 4 oscillators.
If enabling OSC_XOSC_LF it is not safe to go to powerdown/shutdown until the LF clock is running which can be checked using OSCClockSourceGet().
Clock loss reset generation must be disabled before SCLK_LF (OSC_SRC_CLK_LF) clock source is changed and remain disabled until the change is confirmed.
Parameters
ui32SrcClkis the source clocks to configure.
ui32Oscis the oscillator that drives the source clock.
See also
OSCClockSourceGet(), OSCHfSourceSwitch()
Returns
None

Referenced by OSCHF_SwitchToRcOscTurnOffXosc(), OSCHF_TurnOnXosc(), and SetupAfterColdResetWakeupFromShutDownCfg3().

122 {
123  // Check the arguments.
124  ASSERT((ui32SrcClk & OSC_SRC_CLK_LF) ||
125  (ui32SrcClk & OSC_SRC_CLK_HF));
126  ASSERT((ui32Osc == OSC_RCOSC_HF) ||
127  (ui32Osc == OSC_RCOSC_LF) ||
128  (ui32Osc == OSC_XOSC_HF) ||
129  (ui32Osc == OSC_XOSC_LF));
130 
131  // Request the high frequency source clock (using 24 MHz XTAL)
132  if(ui32SrcClk & OSC_SRC_CLK_HF)
133  {
134  // Enable the HF XTAL as HF clock source
138  ui32Osc);
139  }
140 
141  // Configure the low frequency source clock.
142  if(ui32SrcClk & OSC_SRC_CLK_LF)
143  {
144  // Change the clock source.
148  ui32Osc);
149  }
150 }
void DDI16BitfieldWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask, uint32_t ui32Shift, uint16_t ui32Data)
Write a bit field via the DDI using 16-bit maskable write.
Definition: ddi.c:117
#define OSC_SRC_CLK_HF
Definition: osc.h:118
#define OSC_RCOSC_HF
Definition: osc.h:121
#define OSC_XOSC_HF
Definition: osc.h:122
#define OSC_SRC_CLK_LF
Definition: osc.h:119
#define ASSERT(expr)
Definition: debug.h:73
#define OSC_RCOSC_LF
Definition: osc.h:123
#define OSC_XOSC_LF
Definition: osc.h:124

Here is the call graph for this function:

bool OSCHF_AttemptToSwitchToXosc ( void  )

Switch to XOSC_HF if XOSC_HF is ready.

This is a non-blocking function checking if the XOSC_HF is ready and performs the switching if ready. The function is somewhat blocking in the case where switching is performed.

Returns
Returns status of the XOSC_HF switching:
  • true : Switching to XOSC_HF has occurred.
  • false : Switching has not occurred.
266 {
267  uint32_t startupTimeInUs;
268  uint32_t prevLimmit25InUs;
269 
270 #if ( defined( ROM_OSCClockSourceGet ))
272 #else
274 #endif
275  {
276  // Already on XOSC - nothing to do
277  return ( 1 );
278  }
279  if ( OSCHfSourceReady()) {
281 
282  // Store startup time, but limit to 25 percent reduction each time.
285  prevLimmit25InUs = oscHfGlobals.previousStartupTimeInUs;
286  prevLimmit25InUs -= ( prevLimmit25InUs >> 2 ); // 25 percent margin
287  oscHfGlobals.previousStartupTimeInUs = startupTimeInUs;
288  if ( prevLimmit25InUs > startupTimeInUs ) {
289  oscHfGlobals.previousStartupTimeInUs = prevLimmit25InUs;
290  }
291  return ( 1 );
292  }
293  return ( 0 );
294 }
static void OSCHfSourceSwitch(void)
Switch the high frequency clock.
Definition: osc.h:313
#define ROM_OSCClockSourceGet
Definition: rom.h:702
uint32_t timeXoscStable_CV
Definition: osc.c:109
uint32_t OSCClockSourceGet(uint32_t ui32SrcClk)
Get the source clock settings.
Definition: osc.c:158
#define OSC_SRC_CLK_HF
Definition: osc.h:118
static bool OSCHfSourceReady(void)
Check if the HF clock source is ready to be switched.
Definition: osc.h:285
#define OSC_XOSC_HF
Definition: osc.h:122
uint32_t previousStartupTimeInUs
Definition: osc.c:106
static OscHfGlobals_t oscHfGlobals
Definition: osc.c:113
uint32_t timeXoscOn_CV
Definition: osc.c:108
#define RTC_CV_TO_US(x)
Definition: osc.c:103
static uint32_t AONRTCCurrentCompareValueGet(void)
Get the current value of the RTC counter in a format that matches RTC compare values.
Definition: aon_rtc.h:819

Here is the call graph for this function:

uint32_t OSCHF_DebugGetCrystalAmplitude ( void  )

Get crystal amplitude (assuming crystal is running).

Note
This is a debug function only. It is hence not recommended to call this function in normal operation.

This function uses an on-chip ADC and peak detector for reading the crystal amplitude. The measurement time is set to 4 milliseconds and this function does not return before the measurement is done.

Expected value is OSCHF_DebugGetExpectedAverageCrystalAmplitude +/- 50 millivolt.

Returns
Returns crystal amplitude in millivolt.
See also
OSCHF_DebugGetExpectedAverageCrystalAmplitude()
589 {
590  uint32_t oscCfgRegCopy ;
591  uint32_t startTime ;
592  uint32_t deltaTime ;
593  uint32_t ampValue ;
594 
595  // The specified method is as follows:
596  // 1. Set minimum interval between oscillator amplitude calibrations.
597  // (Done by setting PER_M=0 and PER_E=1)
598  // 2. Wait approximately 4 milliseconds in order to measure over a
599  // moderately large number of calibrations.
600  // 3. Read out the crystal amplitude value from the peek detector.
601  // 4. Restore original oscillator amplitude calibrations interval.
602  // 5. Return crystal amplitude value converted to millivolt.
603  oscCfgRegCopy = HWREG( AON_PMCTL_BASE + AON_PMCTL_O_OSCCFG );
605  startTime = AONRTCCurrentCompareValueGet();
606  do {
607  deltaTime = AONRTCCurrentCompareValueGet() - startTime;
608  } while ( deltaTime < ((uint32_t)( 0.004 * FACTOR_SEC_TO_COMP_VAL_FORMAT )));
609  ampValue = ( HWREG( AUX_DDI0_OSC_BASE + DDI_0_OSC_O_STAT1 ) &
612  HWREG( AON_PMCTL_BASE + AON_PMCTL_O_OSCCFG ) = oscCfgRegCopy;
613 
614  return ( ampValue * 15 );
615 }
#define FACTOR_SEC_TO_COMP_VAL_FORMAT
Definition: aon_rtc.h:150
static uint32_t AONRTCCurrentCompareValueGet(void)
Get the current value of the RTC counter in a format that matches RTC compare values.
Definition: aon_rtc.h:819

Here is the call graph for this function:

uint32_t OSCHF_DebugGetExpectedAverageCrystalAmplitude ( void  )

Get the expected average crystal amplitude.

Note
This is a debug function only. It is hence not recommended to call this function in normal operation.

This function read the configured high and low thresholds and returns the mean value converted to millivolt.

Returns
Returns expected average crystal amplitude in millivolt.
See also
OSCHF_DebugGetCrystalAmplitude()
624 {
625  uint32_t ampCompTh1 ;
626  uint32_t highThreshold ;
627  uint32_t lowThreshold ;
628 
629  ampCompTh1 = HWREG( AUX_DDI0_OSC_BASE + DDI_0_OSC_O_AMPCOMPTH1 );
630  highThreshold = ( ampCompTh1 & DDI_0_OSC_AMPCOMPTH1_HPMRAMP3_HTH_M ) >>
632  lowThreshold = ( ampCompTh1 & DDI_0_OSC_AMPCOMPTH1_HPMRAMP3_LTH_M ) >>
634 
635  return ((( highThreshold + lowThreshold ) * 15 ) >> 1 );
636 }
uint32_t OSCHF_GetStartupTime ( uint32_t  timeUntilWakeupInMs)

Returns maximum startup time (in microseconds) of XOSC_HF.

The startup time depends on several factors. This function calculates the maximum startup time based on statistical information.

Parameters
timeUntilWakeupInMsindicates how long time (milliseconds) to the startup will occur.
Returns
Time margin to use in microseconds.
189 {
190  uint32_t deltaTimeSinceXoscOnInMs ;
191  int32_t deltaTempSinceXoscOn ;
192  uint32_t newStartupTimeInUs ;
193 
194  // Check CCFG to determine if device is configured for TCXO.
196  {
197  // Device configured for TCXO. Report fixed startup time located in CCFG with
198  // coversion from number of 100us to number of us.
199  newStartupTimeInUs = (( HWREG( CCFG_BASE + CCFG_O_MODE_CONF_1 ) & CCFG_MODE_CONF_1_TCXO_MAX_START_M ) >>
201  }
202  else
203  {
204  deltaTimeSinceXoscOnInMs = RTC_CV_TO_MS( AONRTCCurrentCompareValueGet() - oscHfGlobals.timeXoscOn_CV );
205  deltaTempSinceXoscOn = AONBatMonTemperatureGetDegC() - oscHfGlobals.tempXoscOff;
206 
207  if ( deltaTempSinceXoscOn < 0 ) {
208  deltaTempSinceXoscOn = -deltaTempSinceXoscOn;
209  }
210 
211  if ( (( timeUntilWakeupInMs + deltaTimeSinceXoscOnInMs ) > 3000 ) ||
212  ( deltaTempSinceXoscOn > 5 ) ||
215  {
216  newStartupTimeInUs = 2000;
218  newStartupTimeInUs = (( HWREG( CCFG_BASE + CCFG_O_MODE_CONF_1 ) &
221  // Note: CCFG startup time is "in units of 100us" adding 25% margin results in *125
222  }
223  } else {
225  newStartupTimeInUs += ( newStartupTimeInUs >> 2 ); // Add 25 percent margin
226  if ( newStartupTimeInUs < oscHfGlobals.previousStartupTimeInUs ) {
227  newStartupTimeInUs = oscHfGlobals.previousStartupTimeInUs;
228  }
229  }
230 
231  if ( newStartupTimeInUs < 200 ) {
232  newStartupTimeInUs = 200;
233  }
234  if ( newStartupTimeInUs > 4000 ) {
235  newStartupTimeInUs = 4000;
236  }
237  }
238  return ( newStartupTimeInUs );
239 }
uint32_t timeXoscStable_CV
Definition: osc.c:109
int32_t AONBatMonTemperatureGetDegC(void)
Get the current temperature measurement as a signed value in Deg Celsius.
Definition: aon_batmon.c:60
uint32_t previousStartupTimeInUs
Definition: osc.c:106
static OscHfGlobals_t oscHfGlobals
Definition: osc.c:113
int32_t tempXoscOff
Definition: osc.c:110
uint32_t timeXoscOn_CV
Definition: osc.c:108
#define RTC_CV_TO_US(x)
Definition: osc.c:103
static uint32_t AONRTCCurrentCompareValueGet(void)
Get the current value of the RTC counter in a format that matches RTC compare values.
Definition: aon_rtc.h:819
#define RTC_CV_TO_MS(x)
Definition: osc.c:102

Here is the call graph for this function:

void OSCHF_SwitchToRcOscTurnOffXosc ( void  )

Switch to RCOSC_HF and turn off XOSC_HF.

This operation takes approximately 50 microseconds (can be shorter if RCOSC_HF already was running).

Returns
None
304 {
305 #if ( defined( ROM_OSCClockSourceSet ))
307 #else
309 #endif
310 
311  // Do the switching if not already running on RCOSC_HF
312 #if ( defined( ROM_OSCClockSourceGet ))
314 #else
316 #endif
317  {
319  }
320 
323 }
static void OSCHfSourceSwitch(void)
Switch the high frequency clock.
Definition: osc.h:313
#define ROM_OSCClockSourceSet
Definition: rom.h:706
uint32_t timeXoscOff_CV
Definition: osc.c:107
#define ROM_OSCClockSourceGet
Definition: rom.h:702
int32_t AONBatMonTemperatureGetDegC(void)
Get the current temperature measurement as a signed value in Deg Celsius.
Definition: aon_batmon.c:60
uint32_t OSCClockSourceGet(uint32_t ui32SrcClk)
Get the source clock settings.
Definition: osc.c:158
#define OSC_SRC_CLK_HF
Definition: osc.h:118
#define OSC_RCOSC_HF
Definition: osc.h:121
static OscHfGlobals_t oscHfGlobals
Definition: osc.c:113
int32_t tempXoscOff
Definition: osc.c:110
void OSCClockSourceSet(uint32_t ui32SrcClk, uint32_t ui32Osc)
Configure the oscillator input to the a source clock.
Definition: osc.c:121
static uint32_t AONRTCCurrentCompareValueGet(void)
Get the current value of the RTC counter in a format that matches RTC compare values.
Definition: aon_rtc.h:819

Here is the call graph for this function:

void OSCHF_TurnOnXosc ( void  )

Turns on XOSC_HF (but without switching to XOSC_HF).

This function simply indicates the need for XOSC_HF to the hardware which initiates the XOSC_HF startup.

Returns
None
249 {
250 #if ( defined( ROM_OSCClockSourceSet ))
252 #else
254 #endif
256 }
#define ROM_OSCClockSourceSet
Definition: rom.h:706
#define OSC_SRC_CLK_HF
Definition: osc.h:118
#define OSC_XOSC_HF
Definition: osc.h:122
static OscHfGlobals_t oscHfGlobals
Definition: osc.c:113
uint32_t timeXoscOn_CV
Definition: osc.c:108
void OSCClockSourceSet(uint32_t ui32SrcClk, uint32_t ui32Osc)
Configure the oscillator input to the a source clock.
Definition: osc.c:121
static uint32_t AONRTCCurrentCompareValueGet(void)
Get the current value of the RTC counter in a format that matches RTC compare values.
Definition: aon_rtc.h:819

Here is the call graph for this function:

static bool OSCHfSourceReady ( void  )
inlinestatic

Check if the HF clock source is ready to be switched.

If a request to switch the HF clock source has been made, this function can be used to check if the clock source is ready to be switched.

Once the HF clock source is ready the switch can be performed by calling the OSCHfSourceSwitch()

Returns
Returns status of HF clock source:
  • true : HF clock source is ready.
  • false : HF clock source is not ready.

Referenced by OSCHF_AttemptToSwitchToXosc().

286 {
287  // Return the readiness of the HF clock source
291  true : false;
292 }
uint16_t DDI16BitfieldRead(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask, uint32_t ui32Shift)
Read a bit field via the DDI using 16-bit read.
Definition: ddi.c:185

Here is the call graph for this function:

static void OSCHfSourceSwitch ( void  )
inlinestatic

Switch the high frequency clock.

When switching the HF clock source the clock period might be prolonged leaving the clock 'stuck-at' high or low for a few cycles. To ensure that this does not coincide with a read access to the Flash, potentially freezing the device, the HF clock source switch must be executed from ROM.

Note
This function will not return until the clock source has been switched. It is left to the programmer to ensure, that there is a pending request for a HF clock source switch before this function is called.
Returns
None
See also
OSCClockSourceSet()

Referenced by OSCHF_AttemptToSwitchToXosc(), and OSCHF_SwitchToRcOscTurnOffXosc().

314 {
315  // Read target clock (lower half of the 32-bit CTL0 register)
317 
318  // If target clock source is RCOSC, change clock source for DCDC to RCOSC
320  {
321  // Force DCDC to use RCOSC before switching SCLK_HF to RCOSC
323  // Dummy read to ensure that the write has propagated
325  }
326 
327  // Switch the HF clock source
329 
330  // If target clock source is XOSC, change clock source for DCDC to "auto"
332  {
333  // Set DCDC clock source back to "auto" after SCLK_HF was switched to XOSC
334  HWREG(AUX_DDI0_OSC_BASE + DDI_O_MASK16B + (DDI_0_OSC_O_CTL0 << 1) + 4) = DDI_0_OSC_CTL0_CLK_DCDC_SRC_SEL_M;
335  }
336 }
#define HapiHFSourceSafeSwitch()
Definition: rom.h:153
static void OSCXHfPowerModeSet ( uint32_t  ui32Mode)
inlinestatic

Set Power Mode for High Frequency XTAL Oscillator.

Parameters
ui32Modeis the power mode for the HF XTAL.
Returns
None
153 {
154  // Check the arguments.
155  ASSERT((ui32Mode == LOW_POWER_XOSC) ||
156  (ui32Mode == HIGH_POWER_XOSC));
157 
158  // Change the power mode.
160  ui32Mode);
161 }
#define LOW_POWER_XOSC
Definition: osc.h:110
void DDI16BitWrite(uint32_t ui32Base, uint32_t ui32Reg, uint32_t ui32Mask, uint32_t ui32WrData)
Write a single bit using a 16-bit maskable write.
Definition: ddi.c:83
#define HIGH_POWER_XOSC
Definition: osc.h:111
#define ASSERT(expr)
Definition: debug.h:73

Here is the call graph for this function:

Macro Definition Documentation

#define HIGH_POWER_XOSC   0

Referenced by OSCXHfPowerModeSet().

#define LOW_POWER_XOSC   1

Referenced by OSCXHfPowerModeSet().

#define OSC_RCOSC_HF   0x00000000
#define OSC_RCOSC_LF   0x00000002
#define OSC_SRC_CLK_LF   0x00000004
#define OSC_XOSC_LF   0x00000003
#define SCLK_HF_RCOSC_HF   0
#define SCLK_HF_XOSC_HF   1
#define SCLK_LF_FROM_RCOSC_HF   0
#define SCLK_LF_FROM_RCOSC_LF   2
#define SCLK_LF_FROM_XOSC_HF   1
#define SCLK_LF_FROM_XOSC_LF   3