emlib/src/em_cmu.c
uint32_t CMU_Calibrate(uint32_t HFCycles, CMU_Osc_TypeDef ref)
{
  EFM_ASSERT(HFCycles <= (_CMU_CALCNT_CALCNT_MASK >> _CMU_CALCNT_CALCNT_SHIFT));

  /* Set reference clock source */
  switch (ref) {
    case cmuOsc_LFXO:
      CMU->CALCTRL = CMU_CALCTRL_UPSEL_LFXO;
      break;

    case cmuOsc_LFRCO:
      CMU->CALCTRL = CMU_CALCTRL_UPSEL_LFRCO;
      break;

    case cmuOsc_HFXO:
      CMU->CALCTRL = CMU_CALCTRL_UPSEL_HFXO;
      break;

    case cmuOsc_HFRCO:
      CMU->CALCTRL = CMU_CALCTRL_UPSEL_HFRCO;
      break;

    case cmuOsc_AUXHFRCO:
      CMU->CALCTRL = CMU_CALCTRL_UPSEL_AUXHFRCO;
      break;

#if defined (_CMU_USHFRCOCTRL_MASK)
    case cmuOsc_USHFRCO:
      CMU->CALCTRL = CMU_CALCTRL_UPSEL_USHFRCO;
      break;
#endif

    default:
      EFM_ASSERT(0);
      return 0;
  }

  /* Set top value */
  CMU->CALCNT = HFCycles;

  /* Start calibration */
  CMU->CMD = CMU_CMD_CALSTART;

#if defined(CMU_STATUS_CALRDY)
  /* Wait until calibration completes */
  while (!BUS_RegBitRead(&CMU->STATUS, _CMU_STATUS_CALRDY_SHIFT)) {
  }
#else
  /* Wait until calibration completes */
  while (BUS_RegBitRead(&CMU->STATUS, _CMU_STATUS_CALBSY_SHIFT)) {
  }
#endif

  return CMU->CALCNT;
}
/***************************************************************************/
/**
 * @brief
 *   Calibrate clock.
 *
 * @details
 *   Run a calibration for HFCLK against a selectable reference clock. Please
 *   refer to the reference manual, CMU chapter, for further details.
 *
 * @note
 *   This function will not return until calibration measurement is completed.
 *
 * @param[in] HFCycles
 *   The number of HFCLK cycles to run calibration. Increasing this number
 *   increases precision, but the calibration will take more time.
 *
 * @param[in] ref
 *   The reference clock used to compare HFCLK with.
 *
 * @return
 *   The number of ticks the reference clock after HFCycles ticks on the HF
 *   clock.
 ******************************************************************************/
@brief
Calibrate clock.

@details
Run a calibration for HFCLK against a selectable reference clock. Please
refer to the reference manual, CMU chapter, for further details.

@note
This function will not return until calibration measurement is completed.

@param[in] HFCycles
The number of HFCLK cycles to run calibration. Increasing this number
increases precision, but the calibration will take more time.

@param[in] ref
The reference clock used to compare HFCLK with.

@return
The number of ticks the reference clock after HFCycles ticks on the HF
clock.
@brief Calibrate clock . @details Run a calibration for HFCLK against a selectable reference clock . Please refer to the reference manual CMU chapter for further details . @note This function will not return until calibration measurement is completed . @param [ in ] HFCycles The number of HFCLK cycles to run calibration . Increasing this number increases precision but the calibration will take more time . @param [ in ] ref The reference clock used to compare HFCLK with . @return The number of ticks the reference clock after HFCycles ticks on the HF clock .
uint32_t CMU_Calibrate(uint32_t HFCycles, CMU_Osc_TypeDef ref)
{
  EFM_ASSERT(HFCycles <= (_CMU_CALCNT_CALCNT_MASK >> _CMU_CALCNT_CALCNT_SHIFT));
  switch (ref) {
    case cmuOsc_LFXO:
      CMU->CALCTRL = CMU_CALCTRL_UPSEL_LFXO;
      break;
    case cmuOsc_LFRCO:
      CMU->CALCTRL = CMU_CALCTRL_UPSEL_LFRCO;
      break;
    case cmuOsc_HFXO:
      CMU->CALCTRL = CMU_CALCTRL_UPSEL_HFXO;
      break;
    case cmuOsc_HFRCO:
      CMU->CALCTRL = CMU_CALCTRL_UPSEL_HFRCO;
      break;
    case cmuOsc_AUXHFRCO:
      CMU->CALCTRL = CMU_CALCTRL_UPSEL_AUXHFRCO;
      break;
#if defined (_CMU_USHFRCOCTRL_MASK)
    case cmuOsc_USHFRCO:
      CMU->CALCTRL = CMU_CALCTRL_UPSEL_USHFRCO;
      break;
#endif
    default:
      EFM_ASSERT(0);
      return 0;
  }
  CMU->CALCNT = HFCycles;
  CMU->CMD = CMU_CMD_CALSTART;
#if defined(CMU_STATUS_CALRDY)
  while (!BUS_RegBitRead(&CMU->STATUS, _CMU_STATUS_CALRDY_SHIFT)) {
  }
#else
  while (BUS_RegBitRead(&CMU->STATUS, _CMU_STATUS_CALBSY_SHIFT)) {
  }
#endif
  return CMU->CALCNT;
}
uint32_t CMU_Calibrate ( uint32_t HFCycles , CMU_Osc_TypeDef ref ) { EFM_ASSERT ( HFCycles <= ( _CMU_CALCNT_CALCNT_MASK >> _CMU_CALCNT_CALCNT_SHIFT ) ) ; switch ( ref ) { case cmuOsc_LFXO : CMU -> CALCTRL = CMU_CALCTRL_UPSEL_LFXO ; break ; case cmuOsc_LFRCO : CMU -> CALCTRL = CMU_CALCTRL_UPSEL_LFRCO ; break ; case cmuOsc_HFXO : CMU -> CALCTRL = CMU_CALCTRL_UPSEL_HFXO ; break ; case cmuOsc_HFRCO : CMU -> CALCTRL = CMU_CALCTRL_UPSEL_HFRCO ; break ; case cmuOsc_AUXHFRCO : CMU -> CALCTRL = CMU_CALCTRL_UPSEL_AUXHFRCO ; break ; #if defined ( _CMU_USHFRCOCTRL_MASK ) case cmuOsc_USHFRCO : CMU -> CALCTRL = CMU_CALCTRL_UPSEL_USHFRCO ; break ; #endif default : EFM_ASSERT ( 0 ) ; return 0 ; } CMU -> CALCNT = HFCycles ; CMU -> CMD = CMU_CMD_CALSTART ; #if defined ( CMU_STATUS_CALRDY ) while ( ! BUS_RegBitRead ( & CMU -> STATUS , _CMU_STATUS_CALRDY_SHIFT ) ) { } #else while ( BUS_RegBitRead ( & CMU -> STATUS , _CMU_STATUS_CALBSY_SHIFT ) ) { } #endif return CMU -> CALCNT ; }
@brief
   Calibrate clock.
@brief Calibrate clock .
/* Set reference clock source */ /* Set top value */ /* Start calibration */ /* Wait until calibration completes */ /* Wait until calibration completes */