emlib/src/em_cmu.c
uint32_t CMU_ClockPrescGet(CMU_Clock_TypeDef clock)
{
  uint32_t  prescReg;
  uint32_t  ret;

  /* Get prescaler register id. */
  prescReg = (clock >> CMU_PRESC_REG_POS) & CMU_PRESC_REG_MASK;

  switch (prescReg) {
    case CMU_HFPRESC_REG:
      ret = (CMU->HFPRESC & _CMU_HFPRESC_PRESC_MASK)
            >> _CMU_HFPRESC_PRESC_SHIFT;
      break;

    case CMU_HFEXPPRESC_REG:
      ret = (CMU->HFEXPPRESC & _CMU_HFEXPPRESC_PRESC_MASK)
            >> _CMU_HFEXPPRESC_PRESC_SHIFT;
      break;

    case CMU_HFCLKLEPRESC_REG:
      ret = (CMU->HFPRESC & _CMU_HFPRESC_HFCLKLEPRESC_MASK)
            >> _CMU_HFPRESC_HFCLKLEPRESC_SHIFT;
      break;

    case CMU_HFPERPRESC_REG:
      ret = (CMU->HFPERPRESC & _CMU_HFPERPRESC_PRESC_MASK)
            >> _CMU_HFPERPRESC_PRESC_SHIFT;
      break;

    case CMU_HFCOREPRESC_REG:
      ret = (CMU->HFCOREPRESC & _CMU_HFCOREPRESC_PRESC_MASK)
            >> _CMU_HFCOREPRESC_PRESC_SHIFT;
      break;

    case CMU_LFAPRESC0_REG:
      switch (clock) {
#if defined(_CMU_LFAPRESC0_LETIMER0_MASK)
        case cmuClock_LETIMER0:
          ret = (CMU->LFAPRESC0 & _CMU_LFAPRESC0_LETIMER0_MASK)
                >> _CMU_LFAPRESC0_LETIMER0_SHIFT;
          /* Convert the exponent to prescaler value. */
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif

#if defined(_CMU_LFAPRESC0_LESENSE_MASK)
        case cmuClock_LESENSE:
          ret = (CMU->LFAPRESC0 & _CMU_LFAPRESC0_LESENSE_MASK)
                >> _CMU_LFAPRESC0_LESENSE_SHIFT;
          /* Convert the exponent to prescaler value. */
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif

#if defined(_CMU_LFAPRESC0_LETIMER1_MASK)
        case cmuClock_LETIMER1:
          ret = (CMU->LFAPRESC0 & _CMU_LFAPRESC0_LETIMER1_MASK)
                >> _CMU_LFAPRESC0_LETIMER1_SHIFT;
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif

#if defined(_CMU_LFAPRESC0_LCD_MASK)
        case cmuClock_LCD:
        case cmuClock_LCDpre:
          ret = (CMU->LFAPRESC0 & _CMU_LFAPRESC0_LCD_MASK)
                >> _CMU_LFAPRESC0_LCD_SHIFT;
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif

#if defined(_CMU_LFAPRESC0_RTC_MASK)
        case cmuClock_RTC:
          ret = (CMU->LFAPRESC0 & _CMU_LFAPRESC0_RTC_MASK)
                >> _CMU_LFAPRESC0_RTC_SHIFT;
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif

        default:
          EFM_ASSERT(0);
          ret = 0U;
          break;
      }
      break;

    case CMU_LFBPRESC0_REG:
      switch (clock) {
#if defined(_CMU_LFBPRESC0_LEUART0_MASK)
        case cmuClock_LEUART0:
          ret = (CMU->LFBPRESC0 & _CMU_LFBPRESC0_LEUART0_MASK)
                >> _CMU_LFBPRESC0_LEUART0_SHIFT;
          /* Convert the exponent to prescaler value. */
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif

#if defined(_CMU_LFBPRESC0_LEUART1_MASK)
        case cmuClock_LEUART1:
          ret = (CMU->LFBPRESC0 & _CMU_LFBPRESC0_LEUART1_MASK)
                >> _CMU_LFBPRESC0_LEUART1_SHIFT;
          /* Convert the exponent to prescaler value. */
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif

#if defined(_CMU_LFBPRESC0_CSEN_MASK)
        case cmuClock_CSEN_LF:
          ret = (CMU->LFBPRESC0 & _CMU_LFBPRESC0_CSEN_MASK)
                >> _CMU_LFBPRESC0_CSEN_SHIFT;
          /* Convert the exponent to prescaler value. */
          ret = CMU_Log2ToDiv(ret + 4) - 1U;
          break;
#endif

        default:
          EFM_ASSERT(0);
          ret = 0U;
          break;
      }
      break;

    case CMU_LFEPRESC0_REG:
      switch (clock) {
#if defined(RTCC_PRESENT)
        case cmuClock_RTCC:
          /* No need to compute with LFEPRESC0_RTCC - DIV1 is the only  */
          /* allowed value. Convert the exponent to prescaler value.    */
          ret = _CMU_LFEPRESC0_RTCC_DIV1;
          break;

        default:
          EFM_ASSERT(0);
          ret = 0U;
          break;
#endif
      }
      break;

    case CMU_ADCASYNCDIV_REG:
      switch (clock) {
#if defined(_CMU_ADCCTRL_ADC0CLKDIV_MASK)
        case cmuClock_ADC0ASYNC:
          ret = (CMU->ADCCTRL & _CMU_ADCCTRL_ADC0CLKDIV_MASK)
                >> _CMU_ADCCTRL_ADC0CLKDIV_SHIFT;
          break;
#endif
#if defined(_CMU_ADCCTRL_ADC1CLKDIV_MASK)
        case cmuClock_ADC1ASYNC:
          ret = (CMU->ADCCTRL & _CMU_ADCCTRL_ADC1CLKDIV_MASK)
                >> _CMU_ADCCTRL_ADC1CLKDIV_SHIFT;
          break;
#endif
        default:
          EFM_ASSERT(0);
          ret = 0U;
          break;
      }
      break;

    default:
      EFM_ASSERT(0);
      ret = 0U;
      break;
  }

  return ret;
}
/***************************************************************************/
/**
 * @brief
 *   Get clock prescaler.
 *
 * @param[in] clock
 *   Clock point to get the prescaler for. Notice that not all clock points
 *   have a prescaler. Please refer to CMU overview in reference manual.
 *
 * @return
 *   The prescaler value of the current clock point. 0 is returned
 *   if @p clock specifies a clock point without a prescaler.
 ******************************************************************************/
@brief
Get clock prescaler.

@param[in] clock
Clock point to get the prescaler for. Notice that not all clock points
have a prescaler. Please refer to CMU overview in reference manual.

@return
The prescaler value of the current clock point. 0 is returned
if @p clock specifies a clock point without a prescaler.
@brief Get clock prescaler . @param [ in ] clock Clock point to get the prescaler for . Notice that not all clock points have a prescaler . Please refer to CMU overview in reference manual . @return The prescaler value of the current clock point . 0 is returned if @p clock specifies a clock point without a prescaler .
uint32_t CMU_ClockPrescGet(CMU_Clock_TypeDef clock)
{
  uint32_t  prescReg;
  uint32_t  ret;
  prescReg = (clock >> CMU_PRESC_REG_POS) & CMU_PRESC_REG_MASK;
  switch (prescReg) {
    case CMU_HFPRESC_REG:
      ret = (CMU->HFPRESC & _CMU_HFPRESC_PRESC_MASK)
            >> _CMU_HFPRESC_PRESC_SHIFT;
      break;
    case CMU_HFEXPPRESC_REG:
      ret = (CMU->HFEXPPRESC & _CMU_HFEXPPRESC_PRESC_MASK)
            >> _CMU_HFEXPPRESC_PRESC_SHIFT;
      break;
    case CMU_HFCLKLEPRESC_REG:
      ret = (CMU->HFPRESC & _CMU_HFPRESC_HFCLKLEPRESC_MASK)
            >> _CMU_HFPRESC_HFCLKLEPRESC_SHIFT;
      break;
    case CMU_HFPERPRESC_REG:
      ret = (CMU->HFPERPRESC & _CMU_HFPERPRESC_PRESC_MASK)
            >> _CMU_HFPERPRESC_PRESC_SHIFT;
      break;
    case CMU_HFCOREPRESC_REG:
      ret = (CMU->HFCOREPRESC & _CMU_HFCOREPRESC_PRESC_MASK)
            >> _CMU_HFCOREPRESC_PRESC_SHIFT;
      break;
    case CMU_LFAPRESC0_REG:
      switch (clock) {
#if defined(_CMU_LFAPRESC0_LETIMER0_MASK)
        case cmuClock_LETIMER0:
          ret = (CMU->LFAPRESC0 & _CMU_LFAPRESC0_LETIMER0_MASK)
                >> _CMU_LFAPRESC0_LETIMER0_SHIFT;
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif
#if defined(_CMU_LFAPRESC0_LESENSE_MASK)
        case cmuClock_LESENSE:
          ret = (CMU->LFAPRESC0 & _CMU_LFAPRESC0_LESENSE_MASK)
                >> _CMU_LFAPRESC0_LESENSE_SHIFT;
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif
#if defined(_CMU_LFAPRESC0_LETIMER1_MASK)
        case cmuClock_LETIMER1:
          ret = (CMU->LFAPRESC0 & _CMU_LFAPRESC0_LETIMER1_MASK)
                >> _CMU_LFAPRESC0_LETIMER1_SHIFT;
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif
#if defined(_CMU_LFAPRESC0_LCD_MASK)
        case cmuClock_LCD:
        case cmuClock_LCDpre:
          ret = (CMU->LFAPRESC0 & _CMU_LFAPRESC0_LCD_MASK)
                >> _CMU_LFAPRESC0_LCD_SHIFT;
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif
#if defined(_CMU_LFAPRESC0_RTC_MASK)
        case cmuClock_RTC:
          ret = (CMU->LFAPRESC0 & _CMU_LFAPRESC0_RTC_MASK)
                >> _CMU_LFAPRESC0_RTC_SHIFT;
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif
        default:
          EFM_ASSERT(0);
          ret = 0U;
          break;
      }
      break;
    case CMU_LFBPRESC0_REG:
      switch (clock) {
#if defined(_CMU_LFBPRESC0_LEUART0_MASK)
        case cmuClock_LEUART0:
          ret = (CMU->LFBPRESC0 & _CMU_LFBPRESC0_LEUART0_MASK)
                >> _CMU_LFBPRESC0_LEUART0_SHIFT;
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif
#if defined(_CMU_LFBPRESC0_LEUART1_MASK)
        case cmuClock_LEUART1:
          ret = (CMU->LFBPRESC0 & _CMU_LFBPRESC0_LEUART1_MASK)
                >> _CMU_LFBPRESC0_LEUART1_SHIFT;
          ret = CMU_Log2ToDiv(ret) - 1U;
          break;
#endif
#if defined(_CMU_LFBPRESC0_CSEN_MASK)
        case cmuClock_CSEN_LF:
          ret = (CMU->LFBPRESC0 & _CMU_LFBPRESC0_CSEN_MASK)
                >> _CMU_LFBPRESC0_CSEN_SHIFT;
          ret = CMU_Log2ToDiv(ret + 4) - 1U;
          break;
#endif
        default:
          EFM_ASSERT(0);
          ret = 0U;
          break;
      }
      break;
    case CMU_LFEPRESC0_REG:
      switch (clock) {
#if defined(RTCC_PRESENT)
        case cmuClock_RTCC:
          ret = _CMU_LFEPRESC0_RTCC_DIV1;
          break;
        default:
          EFM_ASSERT(0);
          ret = 0U;
          break;
#endif
      }
      break;
    case CMU_ADCASYNCDIV_REG:
      switch (clock) {
#if defined(_CMU_ADCCTRL_ADC0CLKDIV_MASK)
        case cmuClock_ADC0ASYNC:
          ret = (CMU->ADCCTRL & _CMU_ADCCTRL_ADC0CLKDIV_MASK)
                >> _CMU_ADCCTRL_ADC0CLKDIV_SHIFT;
          break;
#endif
#if defined(_CMU_ADCCTRL_ADC1CLKDIV_MASK)
        case cmuClock_ADC1ASYNC:
          ret = (CMU->ADCCTRL & _CMU_ADCCTRL_ADC1CLKDIV_MASK)
                >> _CMU_ADCCTRL_ADC1CLKDIV_SHIFT;
          break;
#endif
        default:
          EFM_ASSERT(0);
          ret = 0U;
          break;
      }
      break;
    default:
      EFM_ASSERT(0);
      ret = 0U;
      break;
  }
  return ret;
}
uint32_t CMU_ClockPrescGet ( CMU_Clock_TypeDef clock ) { uint32_t prescReg ; uint32_t ret ; prescReg = ( clock >> CMU_PRESC_REG_POS ) & CMU_PRESC_REG_MASK ; switch ( prescReg ) { case CMU_HFPRESC_REG : ret = ( CMU -> HFPRESC & _CMU_HFPRESC_PRESC_MASK ) >> _CMU_HFPRESC_PRESC_SHIFT ; break ; case CMU_HFEXPPRESC_REG : ret = ( CMU -> HFEXPPRESC & _CMU_HFEXPPRESC_PRESC_MASK ) >> _CMU_HFEXPPRESC_PRESC_SHIFT ; break ; case CMU_HFCLKLEPRESC_REG : ret = ( CMU -> HFPRESC & _CMU_HFPRESC_HFCLKLEPRESC_MASK ) >> _CMU_HFPRESC_HFCLKLEPRESC_SHIFT ; break ; case CMU_HFPERPRESC_REG : ret = ( CMU -> HFPERPRESC & _CMU_HFPERPRESC_PRESC_MASK ) >> _CMU_HFPERPRESC_PRESC_SHIFT ; break ; case CMU_HFCOREPRESC_REG : ret = ( CMU -> HFCOREPRESC & _CMU_HFCOREPRESC_PRESC_MASK ) >> _CMU_HFCOREPRESC_PRESC_SHIFT ; break ; case CMU_LFAPRESC0_REG : switch ( clock ) { #if defined ( _CMU_LFAPRESC0_LETIMER0_MASK ) case cmuClock_LETIMER0 : ret = ( CMU -> LFAPRESC0 & _CMU_LFAPRESC0_LETIMER0_MASK ) >> _CMU_LFAPRESC0_LETIMER0_SHIFT ; ret = CMU_Log2ToDiv ( ret ) - 1U ; break ; #endif #if defined ( _CMU_LFAPRESC0_LESENSE_MASK ) case cmuClock_LESENSE : ret = ( CMU -> LFAPRESC0 & _CMU_LFAPRESC0_LESENSE_MASK ) >> _CMU_LFAPRESC0_LESENSE_SHIFT ; ret = CMU_Log2ToDiv ( ret ) - 1U ; break ; #endif #if defined ( _CMU_LFAPRESC0_LETIMER1_MASK ) case cmuClock_LETIMER1 : ret = ( CMU -> LFAPRESC0 & _CMU_LFAPRESC0_LETIMER1_MASK ) >> _CMU_LFAPRESC0_LETIMER1_SHIFT ; ret = CMU_Log2ToDiv ( ret ) - 1U ; break ; #endif #if defined ( _CMU_LFAPRESC0_LCD_MASK ) case cmuClock_LCD : case cmuClock_LCDpre : ret = ( CMU -> LFAPRESC0 & _CMU_LFAPRESC0_LCD_MASK ) >> _CMU_LFAPRESC0_LCD_SHIFT ; ret = CMU_Log2ToDiv ( ret ) - 1U ; break ; #endif #if defined ( _CMU_LFAPRESC0_RTC_MASK ) case cmuClock_RTC : ret = ( CMU -> LFAPRESC0 & _CMU_LFAPRESC0_RTC_MASK ) >> _CMU_LFAPRESC0_RTC_SHIFT ; ret = CMU_Log2ToDiv ( ret ) - 1U ; break ; #endif default : EFM_ASSERT ( 0 ) ; ret = 0U ; break ; } break ; case CMU_LFBPRESC0_REG : switch ( clock ) { #if defined ( _CMU_LFBPRESC0_LEUART0_MASK ) case cmuClock_LEUART0 : ret = ( CMU -> LFBPRESC0 & _CMU_LFBPRESC0_LEUART0_MASK ) >> _CMU_LFBPRESC0_LEUART0_SHIFT ; ret = CMU_Log2ToDiv ( ret ) - 1U ; break ; #endif #if defined ( _CMU_LFBPRESC0_LEUART1_MASK ) case cmuClock_LEUART1 : ret = ( CMU -> LFBPRESC0 & _CMU_LFBPRESC0_LEUART1_MASK ) >> _CMU_LFBPRESC0_LEUART1_SHIFT ; ret = CMU_Log2ToDiv ( ret ) - 1U ; break ; #endif #if defined ( _CMU_LFBPRESC0_CSEN_MASK ) case cmuClock_CSEN_LF : ret = ( CMU -> LFBPRESC0 & _CMU_LFBPRESC0_CSEN_MASK ) >> _CMU_LFBPRESC0_CSEN_SHIFT ; ret = CMU_Log2ToDiv ( ret + 4 ) - 1U ; break ; #endif default : EFM_ASSERT ( 0 ) ; ret = 0U ; break ; } break ; case CMU_LFEPRESC0_REG : switch ( clock ) { #if defined ( RTCC_PRESENT ) case cmuClock_RTCC : ret = _CMU_LFEPRESC0_RTCC_DIV1 ; break ; default : EFM_ASSERT ( 0 ) ; ret = 0U ; break ; #endif } break ; case CMU_ADCASYNCDIV_REG : switch ( clock ) { #if defined ( _CMU_ADCCTRL_ADC0CLKDIV_MASK ) case cmuClock_ADC0ASYNC : ret = ( CMU -> ADCCTRL & _CMU_ADCCTRL_ADC0CLKDIV_MASK ) >> _CMU_ADCCTRL_ADC0CLKDIV_SHIFT ; break ; #endif #if defined ( _CMU_ADCCTRL_ADC1CLKDIV_MASK ) case cmuClock_ADC1ASYNC : ret = ( CMU -> ADCCTRL & _CMU_ADCCTRL_ADC1CLKDIV_MASK ) >> _CMU_ADCCTRL_ADC1CLKDIV_SHIFT ; break ; #endif default : EFM_ASSERT ( 0 ) ; ret = 0U ; break ; } break ; default : EFM_ASSERT ( 0 ) ; ret = 0U ; break ; } return ret ; }
@brief
   Get clock prescaler.
@brief Get clock prescaler .
/* Get prescaler register id. */ /* Convert the exponent to prescaler value. */ /* Convert the exponent to prescaler value. */ /* Convert the exponent to prescaler value. */ /* Convert the exponent to prescaler value. */ /* Convert the exponent to prescaler value. */ /* No need to compute with LFEPRESC0_RTCC - DIV1 is the only  */ /* allowed value. Convert the exponent to prescaler value.    */