emlib/src/em_emu.c
static void currentLimitersUpdate(void)
{
  uint32_t lncLimSel;
  uint32_t zdetLimSel;
  uint32_t pFetCnt;
  uint16_t maxReverseCurrent_mA;

  /* 80mA as recommended peak in Application Note AN0948.
     The peak current is the average current plus 50% of the current ripple.
     Hence, a 14mA average current is recommended in LP mode. Since LP PFETCNT is also
     a constant, we get lpcLimImSel = 1. The following calculation is provided
     for documentation only. */
  const uint32_t lpcLim = (((14 + 40) + ((14 + 40) / 2))
                           / (5 * (DCDC_LP_PFET_CNT + 1)))
                          - 1;
  const uint32_t lpcLimSel = lpcLim << _EMU_DCDCMISCCTRL_LPCLIMILIMSEL_SHIFT;

  /* Get enabled PFETs */
  pFetCnt = (EMU->DCDCMISCCTRL & _EMU_DCDCMISCCTRL_PFETCNT_MASK)
            >> _EMU_DCDCMISCCTRL_PFETCNT_SHIFT;

  /* Compute LN current limiter threshold from nominal user input current and
     LN PFETCNT as described in the register description for
     EMU_DCDCMISCCTRL_LNCLIMILIMSEL. */
  lncLimSel = (((dcdcMaxCurrent_mA + 40) + ((dcdcMaxCurrent_mA + 40) / 2))
               / (5 * (pFetCnt + 1)))
              - 1;

  /* Saturate the register field value */
  lncLimSel = SL_MIN(lncLimSel,
                     _EMU_DCDCMISCCTRL_LNCLIMILIMSEL_MASK
                     >> _EMU_DCDCMISCCTRL_LNCLIMILIMSEL_SHIFT);

  lncLimSel <<= _EMU_DCDCMISCCTRL_LNCLIMILIMSEL_SHIFT;

  /* Check for overflow */
  EFM_ASSERT((lncLimSel & ~_EMU_DCDCMISCCTRL_LNCLIMILIMSEL_MASK) == 0x0);
  EFM_ASSERT((lpcLimSel & ~_EMU_DCDCMISCCTRL_LPCLIMILIMSEL_MASK) == 0x0);

  EMU->DCDCMISCCTRL = (EMU->DCDCMISCCTRL & ~(_EMU_DCDCMISCCTRL_LNCLIMILIMSEL_MASK
                                             | _EMU_DCDCMISCCTRL_LPCLIMILIMSEL_MASK))
                      | (lncLimSel | lpcLimSel);

  /* Compute reverse current limit threshold for the zero detector from user input
     maximum reverse current and LN PFETCNT as described in the register description
     for EMU_DCDCZDETCTRL_ZDETILIMSEL. */
  if (dcdcReverseCurrentControl >= 0) {
    /* If dcdcReverseCurrentControl < 0, then EMU_DCDCZDETCTRL_ZDETILIMSEL is "don't care" */
    maxReverseCurrent_mA = (uint16_t)dcdcReverseCurrentControl;

    zdetLimSel = ( ((maxReverseCurrent_mA + 40) + ((maxReverseCurrent_mA + 40) / 2))
                   / ((2 * (pFetCnt + 1)) + ((pFetCnt + 1) / 2)) );
    /* Saturate the register field value */
    zdetLimSel = SL_MIN(zdetLimSel,
                        _EMU_DCDCZDETCTRL_ZDETILIMSEL_MASK
                        >> _EMU_DCDCZDETCTRL_ZDETILIMSEL_SHIFT);

    zdetLimSel <<= _EMU_DCDCZDETCTRL_ZDETILIMSEL_SHIFT;

    /* Check for overflow */
    EFM_ASSERT((zdetLimSel & ~_EMU_DCDCZDETCTRL_ZDETILIMSEL_MASK) == 0x0);

    EMU->DCDCZDETCTRL = (EMU->DCDCZDETCTRL & ~_EMU_DCDCZDETCTRL_ZDETILIMSEL_MASK)
                        | zdetLimSel;
  }
}
/***************************************************************************/
/**
 * @brief
 *   Compute current limiters:
 *     LNCLIMILIMSEL: LN current limiter threshold
 *     LPCLIMILIMSEL: LP current limiter threshold
 *     DCDCZDETCTRL:  zero detector limiter threshold
 ******************************************************************************/
@brief
Compute current limiters:
LNCLIMILIMSEL: LN current limiter threshold
LPCLIMILIMSEL: LP current limiter threshold
DCDCZDETCTRL:  zero detector limiter threshold
@brief Compute current limiters : LNCLIMILIMSEL : LN current limiter threshold LPCLIMILIMSEL : LP current limiter threshold DCDCZDETCTRL : zero detector limiter threshold
static void currentLimitersUpdate(void)
{
  uint32_t lncLimSel;
  uint32_t zdetLimSel;
  uint32_t pFetCnt;
  uint16_t maxReverseCurrent_mA;
  const uint32_t lpcLim = (((14 + 40) + ((14 + 40) / 2))
                           / (5 * (DCDC_LP_PFET_CNT + 1)))
                          - 1;
  const uint32_t lpcLimSel = lpcLim << _EMU_DCDCMISCCTRL_LPCLIMILIMSEL_SHIFT;
  pFetCnt = (EMU->DCDCMISCCTRL & _EMU_DCDCMISCCTRL_PFETCNT_MASK)
            >> _EMU_DCDCMISCCTRL_PFETCNT_SHIFT;
  lncLimSel = (((dcdcMaxCurrent_mA + 40) + ((dcdcMaxCurrent_mA + 40) / 2))
               / (5 * (pFetCnt + 1)))
              - 1;
  lncLimSel = SL_MIN(lncLimSel,
                     _EMU_DCDCMISCCTRL_LNCLIMILIMSEL_MASK
                     >> _EMU_DCDCMISCCTRL_LNCLIMILIMSEL_SHIFT);
  lncLimSel <<= _EMU_DCDCMISCCTRL_LNCLIMILIMSEL_SHIFT;
  EFM_ASSERT((lncLimSel & ~_EMU_DCDCMISCCTRL_LNCLIMILIMSEL_MASK) == 0x0);
  EFM_ASSERT((lpcLimSel & ~_EMU_DCDCMISCCTRL_LPCLIMILIMSEL_MASK) == 0x0);
  EMU->DCDCMISCCTRL = (EMU->DCDCMISCCTRL & ~(_EMU_DCDCMISCCTRL_LNCLIMILIMSEL_MASK
                                             | _EMU_DCDCMISCCTRL_LPCLIMILIMSEL_MASK))
                      | (lncLimSel | lpcLimSel);
  if (dcdcReverseCurrentControl >= 0) {
    maxReverseCurrent_mA = (uint16_t)dcdcReverseCurrentControl;
    zdetLimSel = ( ((maxReverseCurrent_mA + 40) + ((maxReverseCurrent_mA + 40) / 2))
                   / ((2 * (pFetCnt + 1)) + ((pFetCnt + 1) / 2)) );
    zdetLimSel = SL_MIN(zdetLimSel,
                        _EMU_DCDCZDETCTRL_ZDETILIMSEL_MASK
                        >> _EMU_DCDCZDETCTRL_ZDETILIMSEL_SHIFT);
    zdetLimSel <<= _EMU_DCDCZDETCTRL_ZDETILIMSEL_SHIFT;
    EFM_ASSERT((zdetLimSel & ~_EMU_DCDCZDETCTRL_ZDETILIMSEL_MASK) == 0x0);
    EMU->DCDCZDETCTRL = (EMU->DCDCZDETCTRL & ~_EMU_DCDCZDETCTRL_ZDETILIMSEL_MASK)
                        | zdetLimSel;
  }
}
static void currentLimitersUpdate ( void ) { uint32_t lncLimSel ; uint32_t zdetLimSel ; uint32_t pFetCnt ; uint16_t maxReverseCurrent_mA ; const uint32_t lpcLim = ( ( ( 14 + 40 ) + ( ( 14 + 40 ) / 2 ) ) / ( 5 * ( DCDC_LP_PFET_CNT + 1 ) ) ) - 1 ; const uint32_t lpcLimSel = lpcLim << _EMU_DCDCMISCCTRL_LPCLIMILIMSEL_SHIFT ; pFetCnt = ( EMU -> DCDCMISCCTRL & _EMU_DCDCMISCCTRL_PFETCNT_MASK ) >> _EMU_DCDCMISCCTRL_PFETCNT_SHIFT ; lncLimSel = ( ( ( dcdcMaxCurrent_mA + 40 ) + ( ( dcdcMaxCurrent_mA + 40 ) / 2 ) ) / ( 5 * ( pFetCnt + 1 ) ) ) - 1 ; lncLimSel = SL_MIN ( lncLimSel , _EMU_DCDCMISCCTRL_LNCLIMILIMSEL_MASK >> _EMU_DCDCMISCCTRL_LNCLIMILIMSEL_SHIFT ) ; lncLimSel <<= _EMU_DCDCMISCCTRL_LNCLIMILIMSEL_SHIFT ; EFM_ASSERT ( ( lncLimSel & ~ _EMU_DCDCMISCCTRL_LNCLIMILIMSEL_MASK ) == 0x0 ) ; EFM_ASSERT ( ( lpcLimSel & ~ _EMU_DCDCMISCCTRL_LPCLIMILIMSEL_MASK ) == 0x0 ) ; EMU -> DCDCMISCCTRL = ( EMU -> DCDCMISCCTRL & ~ ( _EMU_DCDCMISCCTRL_LNCLIMILIMSEL_MASK | _EMU_DCDCMISCCTRL_LPCLIMILIMSEL_MASK ) ) | ( lncLimSel | lpcLimSel ) ; if ( dcdcReverseCurrentControl >= 0 ) { maxReverseCurrent_mA = ( uint16_t ) dcdcReverseCurrentControl ; zdetLimSel = ( ( ( maxReverseCurrent_mA + 40 ) + ( ( maxReverseCurrent_mA + 40 ) / 2 ) ) / ( ( 2 * ( pFetCnt + 1 ) ) + ( ( pFetCnt + 1 ) / 2 ) ) ) ; zdetLimSel = SL_MIN ( zdetLimSel , _EMU_DCDCZDETCTRL_ZDETILIMSEL_MASK >> _EMU_DCDCZDETCTRL_ZDETILIMSEL_SHIFT ) ; zdetLimSel <<= _EMU_DCDCZDETCTRL_ZDETILIMSEL_SHIFT ; EFM_ASSERT ( ( zdetLimSel & ~ _EMU_DCDCZDETCTRL_ZDETILIMSEL_MASK ) == 0x0 ) ; EMU -> DCDCZDETCTRL = ( EMU -> DCDCZDETCTRL & ~ _EMU_DCDCZDETCTRL_ZDETILIMSEL_MASK ) | zdetLimSel ; } }
@brief
   Compute current limiters:
     LNCLIMILIMSEL: LN current limiter threshold
     LPCLIMILIMSEL: LP current limiter threshold
     DCDCZDETCTRL:  zero detector limiter threshold
@brief Compute current limiters : LNCLIMILIMSEL : LN current limiter threshold LPCLIMILIMSEL : LP current limiter threshold DCDCZDETCTRL : zero detector limiter threshold
/* 80mA as recommended peak in Application Note AN0948.
     The peak current is the average current plus 50% of the current ripple.
     Hence, a 14mA average current is recommended in LP mode. Since LP PFETCNT is also
     a constant, we get lpcLimImSel = 1. The following calculation is provided
     for documentation only. */ /* Get enabled PFETs */ /* Compute LN current limiter threshold from nominal user input current and
     LN PFETCNT as described in the register description for
     EMU_DCDCMISCCTRL_LNCLIMILIMSEL. */ /* Saturate the register field value */ /* Check for overflow */ /* Compute reverse current limit threshold for the zero detector from user input
     maximum reverse current and LN PFETCNT as described in the register description
     for EMU_DCDCZDETCTRL_ZDETILIMSEL. */ /* If dcdcReverseCurrentControl < 0, then EMU_DCDCZDETCTRL_ZDETILIMSEL is "don't care" */ /* Saturate the register field value */ /* Check for overflow */