emlib/src/em_cmu.c
void CMU_HFRCOBandSet(CMU_HFRCOBand_TypeDef band)
{
  uint32_t           tuning;
  uint32_t           freq;
  CMU_Select_TypeDef osc;

  /* Read tuning value from calibration table */
  switch (band) {
    case cmuHFRCOBand_1MHz:
      tuning = (DEVINFO->HFRCOCAL0 & _DEVINFO_HFRCOCAL0_BAND1_MASK)
               >> _DEVINFO_HFRCOCAL0_BAND1_SHIFT;
      break;

    case cmuHFRCOBand_7MHz:
      tuning = (DEVINFO->HFRCOCAL0 & _DEVINFO_HFRCOCAL0_BAND7_MASK)
               >> _DEVINFO_HFRCOCAL0_BAND7_SHIFT;
      break;

    case cmuHFRCOBand_11MHz:
      tuning = (DEVINFO->HFRCOCAL0 & _DEVINFO_HFRCOCAL0_BAND11_MASK)
               >> _DEVINFO_HFRCOCAL0_BAND11_SHIFT;
      break;

    case cmuHFRCOBand_14MHz:
      tuning = (DEVINFO->HFRCOCAL0 & _DEVINFO_HFRCOCAL0_BAND14_MASK)
               >> _DEVINFO_HFRCOCAL0_BAND14_SHIFT;
      break;

    case cmuHFRCOBand_21MHz:
      tuning = (DEVINFO->HFRCOCAL1 & _DEVINFO_HFRCOCAL1_BAND21_MASK)
               >> _DEVINFO_HFRCOCAL1_BAND21_SHIFT;
      break;

#if defined(_CMU_HFRCOCTRL_BAND_28MHZ)
    case cmuHFRCOBand_28MHz:
      tuning = (DEVINFO->HFRCOCAL1 & _DEVINFO_HFRCOCAL1_BAND28_MASK)
               >> _DEVINFO_HFRCOCAL1_BAND28_SHIFT;
      break;
#endif

    default:
      EFM_ASSERT(0);
      return;
  }

  /* If HFRCO is used for core clock, we have to consider flash access WS. */
  osc = CMU_ClockSelectGet(cmuClock_HF);
  if (osc == cmuSelect_HFRCO) {
    /* Configure worst case wait states for flash access before setting divider */
    flashWaitStateMax();
  }

  /* Set band/tuning */
  CMU->HFRCOCTRL = (CMU->HFRCOCTRL
                    & ~(_CMU_HFRCOCTRL_BAND_MASK | _CMU_HFRCOCTRL_TUNING_MASK))
                   | (band << _CMU_HFRCOCTRL_BAND_SHIFT)
                   | (tuning << _CMU_HFRCOCTRL_TUNING_SHIFT);

  /* If HFRCO is used for core clock, optimize flash WS */
  if (osc == cmuSelect_HFRCO) {
    /* Call SystemCoreClockGet() to update CMSIS core clock variable. */
    freq = SystemCoreClockGet();
    CMU_UpdateWaitStates(freq, VSCALE_DEFAULT);
  }

#if defined(CMU_MAX_FREQ_HFLE)
  /* Reduce HFLE frequency if possible. */
  setHfLeConfig(CMU_ClockFreqGet(cmuClock_HFLE));
#endif
}
/***************************************************************************/
/**
 * @brief
 *   Set HFRCO band and the tuning value based on the value in the calibration
 *   table made during production.
 *
 * @param[in] band
 *   HFRCO band to activate.
 ******************************************************************************/
@brief
Set HFRCO band and the tuning value based on the value in the calibration
table made during production.

@param[in] band
HFRCO band to activate.
@brief Set HFRCO band and the tuning value based on the value in the calibration table made during production . @param [ in ] band HFRCO band to activate .
void CMU_HFRCOBandSet(CMU_HFRCOBand_TypeDef band)
{
  uint32_t           tuning;
  uint32_t           freq;
  CMU_Select_TypeDef osc;
  switch (band) {
    case cmuHFRCOBand_1MHz:
      tuning = (DEVINFO->HFRCOCAL0 & _DEVINFO_HFRCOCAL0_BAND1_MASK)
               >> _DEVINFO_HFRCOCAL0_BAND1_SHIFT;
      break;
    case cmuHFRCOBand_7MHz:
      tuning = (DEVINFO->HFRCOCAL0 & _DEVINFO_HFRCOCAL0_BAND7_MASK)
               >> _DEVINFO_HFRCOCAL0_BAND7_SHIFT;
      break;
    case cmuHFRCOBand_11MHz:
      tuning = (DEVINFO->HFRCOCAL0 & _DEVINFO_HFRCOCAL0_BAND11_MASK)
               >> _DEVINFO_HFRCOCAL0_BAND11_SHIFT;
      break;
    case cmuHFRCOBand_14MHz:
      tuning = (DEVINFO->HFRCOCAL0 & _DEVINFO_HFRCOCAL0_BAND14_MASK)
               >> _DEVINFO_HFRCOCAL0_BAND14_SHIFT;
      break;
    case cmuHFRCOBand_21MHz:
      tuning = (DEVINFO->HFRCOCAL1 & _DEVINFO_HFRCOCAL1_BAND21_MASK)
               >> _DEVINFO_HFRCOCAL1_BAND21_SHIFT;
      break;
#if defined(_CMU_HFRCOCTRL_BAND_28MHZ)
    case cmuHFRCOBand_28MHz:
      tuning = (DEVINFO->HFRCOCAL1 & _DEVINFO_HFRCOCAL1_BAND28_MASK)
               >> _DEVINFO_HFRCOCAL1_BAND28_SHIFT;
      break;
#endif
    default:
      EFM_ASSERT(0);
      return;
  }
  osc = CMU_ClockSelectGet(cmuClock_HF);
  if (osc == cmuSelect_HFRCO) {
    flashWaitStateMax();
  }
  CMU->HFRCOCTRL = (CMU->HFRCOCTRL
                    & ~(_CMU_HFRCOCTRL_BAND_MASK | _CMU_HFRCOCTRL_TUNING_MASK))
                   | (band << _CMU_HFRCOCTRL_BAND_SHIFT)
                   | (tuning << _CMU_HFRCOCTRL_TUNING_SHIFT);
  if (osc == cmuSelect_HFRCO) {
    freq = SystemCoreClockGet();
    CMU_UpdateWaitStates(freq, VSCALE_DEFAULT);
  }
#if defined(CMU_MAX_FREQ_HFLE)
  setHfLeConfig(CMU_ClockFreqGet(cmuClock_HFLE));
#endif
}
void CMU_HFRCOBandSet ( CMU_HFRCOBand_TypeDef band ) { uint32_t tuning ; uint32_t freq ; CMU_Select_TypeDef osc ; switch ( band ) { case cmuHFRCOBand_1MHz : tuning = ( DEVINFO -> HFRCOCAL0 & _DEVINFO_HFRCOCAL0_BAND1_MASK ) >> _DEVINFO_HFRCOCAL0_BAND1_SHIFT ; break ; case cmuHFRCOBand_7MHz : tuning = ( DEVINFO -> HFRCOCAL0 & _DEVINFO_HFRCOCAL0_BAND7_MASK ) >> _DEVINFO_HFRCOCAL0_BAND7_SHIFT ; break ; case cmuHFRCOBand_11MHz : tuning = ( DEVINFO -> HFRCOCAL0 & _DEVINFO_HFRCOCAL0_BAND11_MASK ) >> _DEVINFO_HFRCOCAL0_BAND11_SHIFT ; break ; case cmuHFRCOBand_14MHz : tuning = ( DEVINFO -> HFRCOCAL0 & _DEVINFO_HFRCOCAL0_BAND14_MASK ) >> _DEVINFO_HFRCOCAL0_BAND14_SHIFT ; break ; case cmuHFRCOBand_21MHz : tuning = ( DEVINFO -> HFRCOCAL1 & _DEVINFO_HFRCOCAL1_BAND21_MASK ) >> _DEVINFO_HFRCOCAL1_BAND21_SHIFT ; break ; #if defined ( _CMU_HFRCOCTRL_BAND_28MHZ ) case cmuHFRCOBand_28MHz : tuning = ( DEVINFO -> HFRCOCAL1 & _DEVINFO_HFRCOCAL1_BAND28_MASK ) >> _DEVINFO_HFRCOCAL1_BAND28_SHIFT ; break ; #endif default : EFM_ASSERT ( 0 ) ; return ; } osc = CMU_ClockSelectGet ( cmuClock_HF ) ; if ( osc == cmuSelect_HFRCO ) { flashWaitStateMax ( ) ; } CMU -> HFRCOCTRL = ( CMU -> HFRCOCTRL & ~ ( _CMU_HFRCOCTRL_BAND_MASK | _CMU_HFRCOCTRL_TUNING_MASK ) ) | ( band << _CMU_HFRCOCTRL_BAND_SHIFT ) | ( tuning << _CMU_HFRCOCTRL_TUNING_SHIFT ) ; if ( osc == cmuSelect_HFRCO ) { freq = SystemCoreClockGet ( ) ; CMU_UpdateWaitStates ( freq , VSCALE_DEFAULT ) ; } #if defined ( CMU_MAX_FREQ_HFLE ) setHfLeConfig ( CMU_ClockFreqGet ( cmuClock_HFLE ) ) ; #endif }
@brief
   Set HFRCO band and the tuning value based on the value in the calibration
   table made during production.
@brief Set HFRCO band and the tuning value based on the value in the calibration table made during production .
/* Read tuning value from calibration table */ /* If HFRCO is used for core clock, we have to consider flash access WS. */ /* Configure worst case wait states for flash access before setting divider */ /* Set band/tuning */ /* If HFRCO is used for core clock, optimize flash WS */ /* Call SystemCoreClockGet() to update CMSIS core clock variable. */ /* Reduce HFLE frequency if possible. */