emlib/src/em_emu.c
void EMU_VScaleEM01(EMU_VScaleEM01_TypeDef voltage, bool wait)
{
  uint32_t hfSrcClockFrequency;
  uint32_t hfPresc = 1U + ((CMU->HFPRESC & _CMU_HFPRESC_PRESC_MASK)
                           >> _CMU_HFPRESC_PRESC_SHIFT);
  uint32_t hfFreq = SystemHFClockGet();
  EMU_VScaleEM01_TypeDef current = EMU_VScaleGet();

  if (current == voltage) {
    /* Voltage is already at correct level. */
    return;
  }

  hfSrcClockFrequency = hfFreq * hfPresc;

  if (voltage == emuVScaleEM01_LowPower) {
    EFM_ASSERT(hfSrcClockFrequency <= CMU_VSCALEEM01_LOWPOWER_VOLTAGE_CLOCK_MAX);
    /* Update wait states before scaling down voltage */
    CMU_UpdateWaitStates(hfFreq, emuVScaleEM01_LowPower);
  }

  EMU->CMD = vScaleEM01Cmd(voltage);

  if (voltage == emuVScaleEM01_HighPerformance) {
    /* Update wait states after scaling up voltage */
    CMU_UpdateWaitStates(hfFreq, emuVScaleEM01_HighPerformance);
  }

  if (wait) {
    EMU_VScaleWait();
  }
}
/***************************************************************************/
/**
 * @brief
 *   Force voltage scaling in EM0 and 1 to a specific voltage level.
 *
 * @param[in] voltage
 *   Target VSCALE voltage level.
 * @param[in] wait
 *   Wait for scaling to complate.
 *
 * @note
 *   This function is useful for upscaling before programming Flash from @ref MSC,
 *   and downscaling after programming is done. Flash programming is only supported
 *   at @ref emuVScaleEM01_HighPerformance.
 *
 * @note
 *  This function ignores @ref vScaleEM01LowPowerVoltageEnable set from @ref
 *  EMU_EM01Init().
 ******************************************************************************/
@brief
Force voltage scaling in EM0 and 1 to a specific voltage level.

@param[in] voltage
Target VSCALE voltage level.
@param[in] wait
Wait for scaling to complate.

@note
This function is useful for upscaling before programming Flash from @ref MSC,
and downscaling after programming is done. Flash programming is only supported
at @ref emuVScaleEM01_HighPerformance.

@note
This function ignores @ref vScaleEM01LowPowerVoltageEnable set from @ref
EMU_EM01Init().
@brief Force voltage scaling in EM0 and 1 to a specific voltage level . @param [ in ] voltage Target VSCALE voltage level . @param [ in ] wait Wait for scaling to complate . @note This function is useful for upscaling before programming Flash from @ref MSC and downscaling after programming is done . Flash programming is only supported at @ref emuVScaleEM01_HighPerformance . @note This function ignores @ref vScaleEM01LowPowerVoltageEnable set from @ref EMU_EM01Init () .
void EMU_VScaleEM01(EMU_VScaleEM01_TypeDef voltage, bool wait)
{
  uint32_t hfSrcClockFrequency;
  uint32_t hfPresc = 1U + ((CMU->HFPRESC & _CMU_HFPRESC_PRESC_MASK)
                           >> _CMU_HFPRESC_PRESC_SHIFT);
  uint32_t hfFreq = SystemHFClockGet();
  EMU_VScaleEM01_TypeDef current = EMU_VScaleGet();
  if (current == voltage) {
    return;
  }
  hfSrcClockFrequency = hfFreq * hfPresc;
  if (voltage == emuVScaleEM01_LowPower) {
    EFM_ASSERT(hfSrcClockFrequency <= CMU_VSCALEEM01_LOWPOWER_VOLTAGE_CLOCK_MAX);
    CMU_UpdateWaitStates(hfFreq, emuVScaleEM01_LowPower);
  }
  EMU->CMD = vScaleEM01Cmd(voltage);
  if (voltage == emuVScaleEM01_HighPerformance) {
    CMU_UpdateWaitStates(hfFreq, emuVScaleEM01_HighPerformance);
  }
  if (wait) {
    EMU_VScaleWait();
  }
}
void EMU_VScaleEM01 ( EMU_VScaleEM01_TypeDef voltage , bool wait ) { uint32_t hfSrcClockFrequency ; uint32_t hfPresc = 1U + ( ( CMU -> HFPRESC & _CMU_HFPRESC_PRESC_MASK ) >> _CMU_HFPRESC_PRESC_SHIFT ) ; uint32_t hfFreq = SystemHFClockGet ( ) ; EMU_VScaleEM01_TypeDef current = EMU_VScaleGet ( ) ; if ( current == voltage ) { return ; } hfSrcClockFrequency = hfFreq * hfPresc ; if ( voltage == emuVScaleEM01_LowPower ) { EFM_ASSERT ( hfSrcClockFrequency <= CMU_VSCALEEM01_LOWPOWER_VOLTAGE_CLOCK_MAX ) ; CMU_UpdateWaitStates ( hfFreq , emuVScaleEM01_LowPower ) ; } EMU -> CMD = vScaleEM01Cmd ( voltage ) ; if ( voltage == emuVScaleEM01_HighPerformance ) { CMU_UpdateWaitStates ( hfFreq , emuVScaleEM01_HighPerformance ) ; } if ( wait ) { EMU_VScaleWait ( ) ; } }
@brief
   Force voltage scaling in EM0 and 1 to a specific voltage level.
@brief Force voltage scaling in EM0 and 1 to a specific voltage level .
/* Voltage is already at correct level. */ /* Update wait states before scaling down voltage */ /* Update wait states after scaling up voltage */