emlib/src/em_cmu.c
CMU_ClkDiv_TypeDef CMU_ClockDivGet(CMU_Clock_TypeDef clock)
{
#if defined(_SILICON_LABS_32B_SERIES_1)
  return 1 + (uint32_t)CMU_ClockPrescGet(clock);

#elif defined(_SILICON_LABS_32B_SERIES_0)
  uint32_t           divReg;
  CMU_ClkDiv_TypeDef ret;

  /* Get divisor reg id */
  divReg = (clock >> CMU_DIV_REG_POS) & CMU_DIV_REG_MASK;

  switch (divReg) {
#if defined(_CMU_CTRL_HFCLKDIV_MASK)
    case CMU_HFCLKDIV_REG:
      ret = 1 + ((CMU->CTRL & _CMU_CTRL_HFCLKDIV_MASK)
                 >> _CMU_CTRL_HFCLKDIV_SHIFT);
      break;
#endif

    case CMU_HFPERCLKDIV_REG:
      ret = (CMU_ClkDiv_TypeDef)((CMU->HFPERCLKDIV
                                  & _CMU_HFPERCLKDIV_HFPERCLKDIV_MASK)
                                 >> _CMU_HFPERCLKDIV_HFPERCLKDIV_SHIFT);
      ret = CMU_Log2ToDiv(ret);
      break;

    case CMU_HFCORECLKDIV_REG:
      ret = (CMU_ClkDiv_TypeDef)((CMU->HFCORECLKDIV
                                  & _CMU_HFCORECLKDIV_HFCORECLKDIV_MASK)
                                 >> _CMU_HFCORECLKDIV_HFCORECLKDIV_SHIFT);
      ret = CMU_Log2ToDiv(ret);
      break;

    case CMU_LFAPRESC0_REG:
      switch (clock) {
        case cmuClock_RTC:
          ret = (CMU_ClkDiv_TypeDef)((CMU->LFAPRESC0 & _CMU_LFAPRESC0_RTC_MASK)
                                     >> _CMU_LFAPRESC0_RTC_SHIFT);
          ret = CMU_Log2ToDiv(ret);
          break;

#if defined(_CMU_LFAPRESC0_LETIMER0_MASK)
        case cmuClock_LETIMER0:
          ret = (CMU_ClkDiv_TypeDef)((CMU->LFAPRESC0 & _CMU_LFAPRESC0_LETIMER0_MASK)
                                     >> _CMU_LFAPRESC0_LETIMER0_SHIFT);
          ret = CMU_Log2ToDiv(ret);
          break;
#endif

#if defined(_CMU_LFAPRESC0_LCD_MASK)
        case cmuClock_LCDpre:
          ret = (CMU_ClkDiv_TypeDef)(((CMU->LFAPRESC0 & _CMU_LFAPRESC0_LCD_MASK)
                                      >> _CMU_LFAPRESC0_LCD_SHIFT)
                                     + CMU_DivToLog2(cmuClkDiv_16));
          ret = CMU_Log2ToDiv(ret);
          break;
#endif

#if defined(_CMU_LFAPRESC0_LESENSE_MASK)
        case cmuClock_LESENSE:
          ret = (CMU_ClkDiv_TypeDef)((CMU->LFAPRESC0 & _CMU_LFAPRESC0_LESENSE_MASK)
                                     >> _CMU_LFAPRESC0_LESENSE_SHIFT);
          ret = CMU_Log2ToDiv(ret);
          break;
#endif

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

    case CMU_LFBPRESC0_REG:
      switch (clock) {
#if defined(_CMU_LFBPRESC0_LEUART0_MASK)
        case cmuClock_LEUART0:
          ret = (CMU_ClkDiv_TypeDef)((CMU->LFBPRESC0 & _CMU_LFBPRESC0_LEUART0_MASK)
                                     >> _CMU_LFBPRESC0_LEUART0_SHIFT);
          ret = CMU_Log2ToDiv(ret);
          break;
#endif

#if defined(_CMU_LFBPRESC0_LEUART1_MASK)
        case cmuClock_LEUART1:
          ret = (CMU_ClkDiv_TypeDef)((CMU->LFBPRESC0 & _CMU_LFBPRESC0_LEUART1_MASK)
                                     >> _CMU_LFBPRESC0_LEUART1_SHIFT);
          ret = CMU_Log2ToDiv(ret);
          break;
#endif

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

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

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

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

@return
The current clock point divisor/prescaler. 1 is returned
if @p clock specifies a clock point without a divisor/prescaler.
@brief Get clock divisor / prescaler . @param [ in ] clock Clock point to get divisor / prescaler for . Notice that not all clock points have a divisor / prescaler . Please refer to CMU overview in reference manual . @return The current clock point divisor / prescaler . 1 is returned if @p clock specifies a clock point without a divisor / prescaler .
CMU_ClkDiv_TypeDef CMU_ClockDivGet(CMU_Clock_TypeDef clock)
{
#if defined(_SILICON_LABS_32B_SERIES_1)
  return 1 + (uint32_t)CMU_ClockPrescGet(clock);
#elif defined(_SILICON_LABS_32B_SERIES_0)
  uint32_t           divReg;
  CMU_ClkDiv_TypeDef ret;
  divReg = (clock >> CMU_DIV_REG_POS) & CMU_DIV_REG_MASK;
  switch (divReg) {
#if defined(_CMU_CTRL_HFCLKDIV_MASK)
    case CMU_HFCLKDIV_REG:
      ret = 1 + ((CMU->CTRL & _CMU_CTRL_HFCLKDIV_MASK)
                 >> _CMU_CTRL_HFCLKDIV_SHIFT);
      break;
#endif
    case CMU_HFPERCLKDIV_REG:
      ret = (CMU_ClkDiv_TypeDef)((CMU->HFPERCLKDIV
                                  & _CMU_HFPERCLKDIV_HFPERCLKDIV_MASK)
                                 >> _CMU_HFPERCLKDIV_HFPERCLKDIV_SHIFT);
      ret = CMU_Log2ToDiv(ret);
      break;
    case CMU_HFCORECLKDIV_REG:
      ret = (CMU_ClkDiv_TypeDef)((CMU->HFCORECLKDIV
                                  & _CMU_HFCORECLKDIV_HFCORECLKDIV_MASK)
                                 >> _CMU_HFCORECLKDIV_HFCORECLKDIV_SHIFT);
      ret = CMU_Log2ToDiv(ret);
      break;
    case CMU_LFAPRESC0_REG:
      switch (clock) {
        case cmuClock_RTC:
          ret = (CMU_ClkDiv_TypeDef)((CMU->LFAPRESC0 & _CMU_LFAPRESC0_RTC_MASK)
                                     >> _CMU_LFAPRESC0_RTC_SHIFT);
          ret = CMU_Log2ToDiv(ret);
          break;
#if defined(_CMU_LFAPRESC0_LETIMER0_MASK)
        case cmuClock_LETIMER0:
          ret = (CMU_ClkDiv_TypeDef)((CMU->LFAPRESC0 & _CMU_LFAPRESC0_LETIMER0_MASK)
                                     >> _CMU_LFAPRESC0_LETIMER0_SHIFT);
          ret = CMU_Log2ToDiv(ret);
          break;
#endif
#if defined(_CMU_LFAPRESC0_LCD_MASK)
        case cmuClock_LCDpre:
          ret = (CMU_ClkDiv_TypeDef)(((CMU->LFAPRESC0 & _CMU_LFAPRESC0_LCD_MASK)
                                      >> _CMU_LFAPRESC0_LCD_SHIFT)
                                     + CMU_DivToLog2(cmuClkDiv_16));
          ret = CMU_Log2ToDiv(ret);
          break;
#endif
#if defined(_CMU_LFAPRESC0_LESENSE_MASK)
        case cmuClock_LESENSE:
          ret = (CMU_ClkDiv_TypeDef)((CMU->LFAPRESC0 & _CMU_LFAPRESC0_LESENSE_MASK)
                                     >> _CMU_LFAPRESC0_LESENSE_SHIFT);
          ret = CMU_Log2ToDiv(ret);
          break;
#endif
        default:
          EFM_ASSERT(0);
          ret = cmuClkDiv_1;
          break;
      }
      break;
    case CMU_LFBPRESC0_REG:
      switch (clock) {
#if defined(_CMU_LFBPRESC0_LEUART0_MASK)
        case cmuClock_LEUART0:
          ret = (CMU_ClkDiv_TypeDef)((CMU->LFBPRESC0 & _CMU_LFBPRESC0_LEUART0_MASK)
                                     >> _CMU_LFBPRESC0_LEUART0_SHIFT);
          ret = CMU_Log2ToDiv(ret);
          break;
#endif
#if defined(_CMU_LFBPRESC0_LEUART1_MASK)
        case cmuClock_LEUART1:
          ret = (CMU_ClkDiv_TypeDef)((CMU->LFBPRESC0 & _CMU_LFBPRESC0_LEUART1_MASK)
                                     >> _CMU_LFBPRESC0_LEUART1_SHIFT);
          ret = CMU_Log2ToDiv(ret);
          break;
#endif
        default:
          EFM_ASSERT(0);
          ret = cmuClkDiv_1;
          break;
      }
      break;
    default:
      EFM_ASSERT(0);
      ret = cmuClkDiv_1;
      break;
  }
  return ret;
#endif
}
CMU_ClkDiv_TypeDef CMU_ClockDivGet ( CMU_Clock_TypeDef clock ) { #if defined ( _SILICON_LABS_32B_SERIES_1 ) return 1 + ( uint32_t ) CMU_ClockPrescGet ( clock ) ; #elif defined ( _SILICON_LABS_32B_SERIES_0 ) uint32_t divReg ; CMU_ClkDiv_TypeDef ret ; divReg = ( clock >> CMU_DIV_REG_POS ) & CMU_DIV_REG_MASK ; switch ( divReg ) { #if defined ( _CMU_CTRL_HFCLKDIV_MASK ) case CMU_HFCLKDIV_REG : ret = 1 + ( ( CMU -> CTRL & _CMU_CTRL_HFCLKDIV_MASK ) >> _CMU_CTRL_HFCLKDIV_SHIFT ) ; break ; #endif case CMU_HFPERCLKDIV_REG : ret = ( CMU_ClkDiv_TypeDef ) ( ( CMU -> HFPERCLKDIV & _CMU_HFPERCLKDIV_HFPERCLKDIV_MASK ) >> _CMU_HFPERCLKDIV_HFPERCLKDIV_SHIFT ) ; ret = CMU_Log2ToDiv ( ret ) ; break ; case CMU_HFCORECLKDIV_REG : ret = ( CMU_ClkDiv_TypeDef ) ( ( CMU -> HFCORECLKDIV & _CMU_HFCORECLKDIV_HFCORECLKDIV_MASK ) >> _CMU_HFCORECLKDIV_HFCORECLKDIV_SHIFT ) ; ret = CMU_Log2ToDiv ( ret ) ; break ; case CMU_LFAPRESC0_REG : switch ( clock ) { case cmuClock_RTC : ret = ( CMU_ClkDiv_TypeDef ) ( ( CMU -> LFAPRESC0 & _CMU_LFAPRESC0_RTC_MASK ) >> _CMU_LFAPRESC0_RTC_SHIFT ) ; ret = CMU_Log2ToDiv ( ret ) ; break ; #if defined ( _CMU_LFAPRESC0_LETIMER0_MASK ) case cmuClock_LETIMER0 : ret = ( CMU_ClkDiv_TypeDef ) ( ( CMU -> LFAPRESC0 & _CMU_LFAPRESC0_LETIMER0_MASK ) >> _CMU_LFAPRESC0_LETIMER0_SHIFT ) ; ret = CMU_Log2ToDiv ( ret ) ; break ; #endif #if defined ( _CMU_LFAPRESC0_LCD_MASK ) case cmuClock_LCDpre : ret = ( CMU_ClkDiv_TypeDef ) ( ( ( CMU -> LFAPRESC0 & _CMU_LFAPRESC0_LCD_MASK ) >> _CMU_LFAPRESC0_LCD_SHIFT ) + CMU_DivToLog2 ( cmuClkDiv_16 ) ) ; ret = CMU_Log2ToDiv ( ret ) ; break ; #endif #if defined ( _CMU_LFAPRESC0_LESENSE_MASK ) case cmuClock_LESENSE : ret = ( CMU_ClkDiv_TypeDef ) ( ( CMU -> LFAPRESC0 & _CMU_LFAPRESC0_LESENSE_MASK ) >> _CMU_LFAPRESC0_LESENSE_SHIFT ) ; ret = CMU_Log2ToDiv ( ret ) ; break ; #endif default : EFM_ASSERT ( 0 ) ; ret = cmuClkDiv_1 ; break ; } break ; case CMU_LFBPRESC0_REG : switch ( clock ) { #if defined ( _CMU_LFBPRESC0_LEUART0_MASK ) case cmuClock_LEUART0 : ret = ( CMU_ClkDiv_TypeDef ) ( ( CMU -> LFBPRESC0 & _CMU_LFBPRESC0_LEUART0_MASK ) >> _CMU_LFBPRESC0_LEUART0_SHIFT ) ; ret = CMU_Log2ToDiv ( ret ) ; break ; #endif #if defined ( _CMU_LFBPRESC0_LEUART1_MASK ) case cmuClock_LEUART1 : ret = ( CMU_ClkDiv_TypeDef ) ( ( CMU -> LFBPRESC0 & _CMU_LFBPRESC0_LEUART1_MASK ) >> _CMU_LFBPRESC0_LEUART1_SHIFT ) ; ret = CMU_Log2ToDiv ( ret ) ; break ; #endif default : EFM_ASSERT ( 0 ) ; ret = cmuClkDiv_1 ; break ; } break ; default : EFM_ASSERT ( 0 ) ; ret = cmuClkDiv_1 ; break ; } return ret ; #endif }
@brief
   Get clock divisor/prescaler.
@brief Get clock divisor / prescaler .
/* Get divisor reg id */