emlib/src/em_cmu.c
void CMU_CalibrateConfig(uint32_t downCycles, CMU_Osc_TypeDef downSel,
                         CMU_Osc_TypeDef upSel)
{
  /* Keep untouched configuration settings */
  uint32_t calCtrl = CMU->CALCTRL
                     & ~(_CMU_CALCTRL_UPSEL_MASK | _CMU_CALCTRL_DOWNSEL_MASK);

  /* 20 bits of precision to calibration count register */
  EFM_ASSERT(downCycles <= (_CMU_CALCNT_CALCNT_MASK >> _CMU_CALCNT_CALCNT_SHIFT));

  /* Set down counting clock source - down counter */
  switch (downSel) {
    case cmuOsc_LFXO:
      calCtrl |= CMU_CALCTRL_DOWNSEL_LFXO;
      break;

    case cmuOsc_LFRCO:
      calCtrl |= CMU_CALCTRL_DOWNSEL_LFRCO;
      break;

    case cmuOsc_HFXO:
      calCtrl |= CMU_CALCTRL_DOWNSEL_HFXO;
      break;

    case cmuOsc_HFRCO:
      calCtrl |= CMU_CALCTRL_DOWNSEL_HFRCO;
      break;

    case cmuOsc_AUXHFRCO:
      calCtrl |= CMU_CALCTRL_DOWNSEL_AUXHFRCO;
      break;

#if defined (_CMU_USHFRCOCTRL_MASK)
    case cmuOsc_USHFRCO:
      calCtrl |= CMU_CALCTRL_DOWNSEL_USHFRCO;
      break;
#endif

    default:
      EFM_ASSERT(0);
      break;
  }

  /* Set top value to be counted down by the downSel clock */
  CMU->CALCNT = downCycles;

  /* Set reference clock source - up counter */
  switch (upSel) {
    case cmuOsc_LFXO:
      calCtrl |= CMU_CALCTRL_UPSEL_LFXO;
      break;

    case cmuOsc_LFRCO:
      calCtrl |= CMU_CALCTRL_UPSEL_LFRCO;
      break;

    case cmuOsc_HFXO:
      calCtrl |= CMU_CALCTRL_UPSEL_HFXO;
      break;

    case cmuOsc_HFRCO:
      calCtrl |= CMU_CALCTRL_UPSEL_HFRCO;
      break;

    case cmuOsc_AUXHFRCO:
      calCtrl |= CMU_CALCTRL_UPSEL_AUXHFRCO;
      break;

#if defined (_CMU_USHFRCOCTRL_MASK)
    case cmuOsc_USHFRCO:
      calCtrl |= CMU_CALCTRL_UPSEL_USHFRCO;
      break;
#endif

    default:
      EFM_ASSERT(0);
      break;
  }

  CMU->CALCTRL = calCtrl;
}
/***************************************************************************/
/**
 * @brief
 *   Configure clock calibration
 *
 * @details
 *   Configure a calibration for a selectable clock source against another
 *   selectable reference clock.
 *   Refer to the reference manual, CMU chapter, for further details.
 *
 * @note
 *   After configuration, a call to CMU_CalibrateStart() is required, and
 *   the resulting calibration value can be read out with the
 *   CMU_CalibrateCountGet() function call.
 *
 * @param[in] downCycles
 *   The number of downSel clock cycles to run calibration. Increasing this
 *   number increases precision, but the calibration will take more time.
 *
 * @param[in] downSel
 *   The clock which will be counted down downCycles
 *
 * @param[in] upSel
 *   The reference clock, the number of cycles generated by this clock will
 *   be counted and added up, the result can be given with the
 *   CMU_CalibrateCountGet() function call.
 ******************************************************************************/
@brief
Configure clock calibration

@details
Configure a calibration for a selectable clock source against another
selectable reference clock.
Refer to the reference manual, CMU chapter, for further details.

@note
After configuration, a call to CMU_CalibrateStart() is required, and
the resulting calibration value can be read out with the
CMU_CalibrateCountGet() function call.

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

@param[in] downSel
The clock which will be counted down downCycles

@param[in] upSel
The reference clock, the number of cycles generated by this clock will
be counted and added up, the result can be given with the
CMU_CalibrateCountGet() function call.
@brief Configure clock calibration @details Configure a calibration for a selectable clock source against another selectable reference clock . Refer to the reference manual CMU chapter for further details . @note After configuration a call to CMU_CalibrateStart () is required and the resulting calibration value can be read out with the CMU_CalibrateCountGet () function call . @param [ in ] downCycles The number of downSel clock cycles to run calibration . Increasing this number increases precision but the calibration will take more time . @param [ in ] downSel The clock which will be counted down downCycles @param [ in ] upSel The reference clock the number of cycles generated by this clock will be counted and added up the result can be given with the CMU_CalibrateCountGet () function call .
void CMU_CalibrateConfig(uint32_t downCycles, CMU_Osc_TypeDef downSel,
                         CMU_Osc_TypeDef upSel)
{
  uint32_t calCtrl = CMU->CALCTRL
                     & ~(_CMU_CALCTRL_UPSEL_MASK | _CMU_CALCTRL_DOWNSEL_MASK);
  EFM_ASSERT(downCycles <= (_CMU_CALCNT_CALCNT_MASK >> _CMU_CALCNT_CALCNT_SHIFT));
  switch (downSel) {
    case cmuOsc_LFXO:
      calCtrl |= CMU_CALCTRL_DOWNSEL_LFXO;
      break;
    case cmuOsc_LFRCO:
      calCtrl |= CMU_CALCTRL_DOWNSEL_LFRCO;
      break;
    case cmuOsc_HFXO:
      calCtrl |= CMU_CALCTRL_DOWNSEL_HFXO;
      break;
    case cmuOsc_HFRCO:
      calCtrl |= CMU_CALCTRL_DOWNSEL_HFRCO;
      break;
    case cmuOsc_AUXHFRCO:
      calCtrl |= CMU_CALCTRL_DOWNSEL_AUXHFRCO;
      break;
#if defined (_CMU_USHFRCOCTRL_MASK)
    case cmuOsc_USHFRCO:
      calCtrl |= CMU_CALCTRL_DOWNSEL_USHFRCO;
      break;
#endif
    default:
      EFM_ASSERT(0);
      break;
  }
  CMU->CALCNT = downCycles;
  switch (upSel) {
    case cmuOsc_LFXO:
      calCtrl |= CMU_CALCTRL_UPSEL_LFXO;
      break;
    case cmuOsc_LFRCO:
      calCtrl |= CMU_CALCTRL_UPSEL_LFRCO;
      break;
    case cmuOsc_HFXO:
      calCtrl |= CMU_CALCTRL_UPSEL_HFXO;
      break;
    case cmuOsc_HFRCO:
      calCtrl |= CMU_CALCTRL_UPSEL_HFRCO;
      break;
    case cmuOsc_AUXHFRCO:
      calCtrl |= CMU_CALCTRL_UPSEL_AUXHFRCO;
      break;
#if defined (_CMU_USHFRCOCTRL_MASK)
    case cmuOsc_USHFRCO:
      calCtrl |= CMU_CALCTRL_UPSEL_USHFRCO;
      break;
#endif
    default:
      EFM_ASSERT(0);
      break;
  }
  CMU->CALCTRL = calCtrl;
}
void CMU_CalibrateConfig ( uint32_t downCycles , CMU_Osc_TypeDef downSel , CMU_Osc_TypeDef upSel ) { uint32_t calCtrl = CMU -> CALCTRL & ~ ( _CMU_CALCTRL_UPSEL_MASK | _CMU_CALCTRL_DOWNSEL_MASK ) ; EFM_ASSERT ( downCycles <= ( _CMU_CALCNT_CALCNT_MASK >> _CMU_CALCNT_CALCNT_SHIFT ) ) ; switch ( downSel ) { case cmuOsc_LFXO : calCtrl |= CMU_CALCTRL_DOWNSEL_LFXO ; break ; case cmuOsc_LFRCO : calCtrl |= CMU_CALCTRL_DOWNSEL_LFRCO ; break ; case cmuOsc_HFXO : calCtrl |= CMU_CALCTRL_DOWNSEL_HFXO ; break ; case cmuOsc_HFRCO : calCtrl |= CMU_CALCTRL_DOWNSEL_HFRCO ; break ; case cmuOsc_AUXHFRCO : calCtrl |= CMU_CALCTRL_DOWNSEL_AUXHFRCO ; break ; #if defined ( _CMU_USHFRCOCTRL_MASK ) case cmuOsc_USHFRCO : calCtrl |= CMU_CALCTRL_DOWNSEL_USHFRCO ; break ; #endif default : EFM_ASSERT ( 0 ) ; break ; } CMU -> CALCNT = downCycles ; switch ( upSel ) { case cmuOsc_LFXO : calCtrl |= CMU_CALCTRL_UPSEL_LFXO ; break ; case cmuOsc_LFRCO : calCtrl |= CMU_CALCTRL_UPSEL_LFRCO ; break ; case cmuOsc_HFXO : calCtrl |= CMU_CALCTRL_UPSEL_HFXO ; break ; case cmuOsc_HFRCO : calCtrl |= CMU_CALCTRL_UPSEL_HFRCO ; break ; case cmuOsc_AUXHFRCO : calCtrl |= CMU_CALCTRL_UPSEL_AUXHFRCO ; break ; #if defined ( _CMU_USHFRCOCTRL_MASK ) case cmuOsc_USHFRCO : calCtrl |= CMU_CALCTRL_UPSEL_USHFRCO ; break ; #endif default : EFM_ASSERT ( 0 ) ; break ; } CMU -> CALCTRL = calCtrl ; }
@brief
   Configure clock calibration
@brief Configure clock calibration
/* Keep untouched configuration settings */ /* 20 bits of precision to calibration count register */ /* Set down counting clock source - down counter */ /* Set top value to be counted down by the downSel clock */ /* Set reference clock source - up counter */