⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zl5011xpac.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
         status = ZL5011X_PARAMETER_INVALID;
      }
      else
      {
         bits = halfRefPeriod << ZL5011X_DPLL_MTIE_ROUND_OFF_BITS;
         bitMask = ZL5011X_DPLL_MTIE_ROUND_OFF_MASK << ZL5011X_DPLL_MTIE_ROUND_OFF_BITS;
      }
   }

   if (status == ZL5011X_OK)
   {
      /* if the MTIE function is not required, then just set the reset bit */
      if (mtie != ZL5011X_TRUE)
      {
         bits |= ZL5011X_1BIT_MASK << ZL5011X_DPLL_MTIE_RESET_BIT;
      }

      bitMask |= (ZL5011X_1BIT_MASK << ZL5011X_DPLL_MTIE_RESET_BIT);

      status = zl5011xReadModWrite(zl5011xParams,
            ZL5011X_DPLL_CHANGE_CONTROL, bits, bitMask);

      zl5011xParams->wanIf.clock.sync.mtie = mtie;
   }

   return(status);
}

/*******************************************************************************

 Function:
    zl5011xPacDpllGetStatus

 Description:
    This function returns the status of the DPLL, with respect to the change over
    of references etc. The status is returned in a structure.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

 Outputs:
   dpllStatus     DPLL status structure

 Returns:
   zlStatusE

 Remarks:
    None

*******************************************************************************/

zlStatusE zl5011xPacDpllGetStatus(zl5011xParamsS *zl5011xParams, zl5011xDpllStatusS *dpllStatus)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T bits;

   ZL5011X_TRACE(ZL5011X_PAC_FN_ID, "zl5011xPacDpllGetStatus:", 0, 0, 0, 0, 0, 0);

   status = zl5011xRead(zl5011xParams, ZL5011X_DPLL_CHANGE_STATUS, &bits);

   if (status == ZL5011X_OK)
   {
      /* scan the bits from the register, to populate the status structure */
      dpllStatus->dpllMode = (zl5011xDpllOperationE)((bits >> ZL5011X_DPLL_STATUS_MODE_BITS) & ZL5011X_DPLL_STATUS_MODE_MASK);

      if ((bits & (ZL5011X_1BIT_MASK << ZL5011X_DPLL_STATUS_REF_BIT)) == 0)
      {
         dpllStatus->primaryRefInUse = ZL5011X_TRUE;
      }
      else
      {
         dpllStatus->primaryRefInUse = ZL5011X_FALSE;
      }

      if ((bits & (ZL5011X_1BIT_MASK << ZL5011X_DPLL_STATUS_LOCK_BIT)) == 0)
      {
         dpllStatus->locked = ZL5011X_FALSE;
      }
      else
      {
         dpllStatus->locked = ZL5011X_TRUE;
      }
   }

   return(status);
}

/*******************************************************************************

 Function:
    zl5011xPacDpllGetStatusValue

 Description:
    This function returns the status bits for the DPLL in a 32 bit word.
    The bit positions are identified in zl5011xPac.h and function
    zl5011xPacDpllGetStatus can be examined for more information on using these
    mask bits.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

 Outputs:
   dpllStatus     returns the status bits for the DPLL

 Returns:
   zlStatusE

 Remarks:
    None

*******************************************************************************/

zlStatusE zl5011xPacDpllGetStatusValue(zl5011xParamsS *zl5011xParams, Uint32T *dpllStatus)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T bits;

   ZL5011X_TRACE(ZL5011X_PAC_FN_ID, "zl5011xPacDpllGetStatusValue:", 0, 0, 0, 0, 0, 0);

   status = zl5011xRead(zl5011xParams, ZL5011X_DPLL_CHANGE_STATUS, &bits);

   if (status == ZL5011X_OK)
   {
      *dpllStatus = bits & ((ZL5011X_DPLL_STATUS_MODE_MASK << ZL5011X_DPLL_STATUS_MODE_BITS) |
            (ZL5011X_1BIT_MASK << ZL5011X_DPLL_STATUS_LOCK_BIT) |
            (ZL5011X_1BIT_MASK << ZL5011X_DPLL_STATUS_REF_BIT));
   }

   return(status);
}

/*******************************************************************************

 Function:
    zl5011xPacDpllSetRef

 Description:
    Configures the reference source and the divider to generate the required
    input frequency to the DPLL. This function is used to configure both the
    primary and secondary references.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   registerAddress address of the reference control register
   ref            source for the reference - stream or ext ref

 Outputs:
    None

 Returns:
   zlStatusE

 Remarks:
    None

*******************************************************************************/

zlStatusE zl5011xPacDpllSetRef(zl5011xParamsS *zl5011xParams,
      AddressT registerAddress, zl5011xRefClkConfigS ref)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T bits;
   Uint32T inputFreqHz, divider;

   ZL5011X_TRACE(ZL5011X_PAC_FN_ID,
         "zl5011xPacDpllSetRef: mode = %d, stream = %d, ref in = %d",
         ref.source, ref.stream, ref.refFreq, 0, 0, 0);

   if (status == ZL5011X_OK)
   {
      status = zl5011xPacCheckRef(zl5011xParams, &ref, &inputFreqHz);
   }

   if (status == ZL5011X_OK)
   {
      switch(ref.source)
      {
         case ZL5011X_WAN_PRIMARY_REF :
            bits = ZL5011X_PAC_PRIMARY_REF_SOURCE << ZL5011X_PAC_REF_SOURCE_BITS;
            break;

         case ZL5011X_WAN_SECONDARY_REF :
            bits = ZL5011X_PAC_SECONDARY_REF_SOURCE << ZL5011X_PAC_REF_SOURCE_BITS;
            break;

         case ZL5011X_WAN_STREAM_REF :
            bits = ref.stream << ZL5011X_PAC_REF_SOURCE_BITS;
            break;

         default :
            bits = 0;
            status = ZL5011X_PARAMETER_INVALID;
      }
   }

   if (status == ZL5011X_OK)
   {
      divider = inputFreqHz / zl5011xParams->wanIf.clock.sync.refInputFreqHz;

      bits |= (divider & ZL5011X_PAC_REF_DIVIDE_MASK) << ZL5011X_PAC_REF_DIVIDE_BITS;

      status = zl5011xWrite(zl5011xParams, registerAddress, bits);
   }

   return(status);
}

/*******************************************************************************

 Function:
    zl5011xPacDpllSetPrimaryRef

 Description:
    Configures the primary reference source and the divider to generate
    the required input frequency to the DPLL.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   ref            source for the reference - stream or ext ref

 Outputs:
    None

 Returns:
   zlStatusE

 Remarks:
    None

*******************************************************************************/

zlStatusE zl5011xPacDpllSetPrimaryRef(zl5011xParamsS *zl5011xParams, zl5011xRefClkConfigS ref)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PAC_FN_ID, "zl5011xPacDpllSetPrimaryRef:", 0, 0, 0, 0, 0, 0);

   status = zl5011xPacDpllSetRef(zl5011xParams, ZL5011X_PAC_PRIMARY_REF_CONTROL, ref);

   (void)memcpy(&(zl5011xParams->wanIf.clock.sync.primaryRef), &ref, sizeof(ref));

   return(status);
}

/*******************************************************************************

 Function:
    zl5011xPacDpllSetSecondaryRef

 Description:
    Configures the secondary reference source and the divider to generate
    the required input frequency to the DPLL.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   ref            source for the reference - stream or ext ref

 Outputs:
    None

 Returns:
   zlStatusE

 Remarks:
    None

*******************************************************************************/

zlStatusE zl5011xPacDpllSetSecondaryRef(zl5011xParamsS *zl5011xParams,
      zl5011xRefClkConfigS ref)
{
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_PAC_FN_ID, "zl5011xPacDpllSetSecondaryRef:", 0, 0, 0, 0, 0, 0);

   status = zl5011xPacDpllSetRef(zl5011xParams, ZL5011X_PAC_SECONDARY_REF_CONTROL, ref);

   (void)memcpy(&(zl5011xParams->wanIf.clock.sync.secondaryRef), &ref, sizeof(ref));

   return(status);
}

/*******************************************************************************

 Function:
    zl5011xPacConfigPrimaryRef

 Description:
    Configures the reference source and allows the divider to be
    explicitly set. This is useful when requiring general clock muxing
    functionality as opposed to DPLL usage.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   ref            source for the reference - stream or ext ref
   divider        divide ratio to apply to the reference i/p

 Outputs:
    None

 Returns:
   zlStatusE

 Remarks:
    None

*******************************************************************************/

zlStatusE zl5011xPacConfigPrimaryRef(zl5011xParamsS *zl5011xParams, zl5011xRefClkConfigS ref, Uint32T divider)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T bits;

   ZL5011X_TRACE(ZL5011X_PAC_FN_ID, "zl5011xPacConfigPrimaryRef:", 0, 0, 0, 0, 0, 0);

   if ((divider & ~ZL5011X_PAC_REF_DIVIDE_MASK) != 0)
   {
      status = ZL5011X_PARAMETER_INVALID;
   }

   if (status == ZL5011X_OK)
   {
      switch(ref.source)
      {
         case ZL5011X_WAN_PRIMARY_REF :
            bits = ZL5011X_PAC_PRIMARY_REF_SOURCE << ZL5011X_PAC_REF_SOURCE_BITS;
            break;

         case ZL5011X_WAN_SECONDARY_REF :
            bits = ZL5011X_PAC_SECONDARY_REF_SOURCE << ZL5011X_PAC_REF_SOURCE_BITS;
            break;

         case ZL5011X_WAN_STREAM_REF :
            bits = ref.stream << ZL5011X_PAC_REF_SOURCE_BITS;
            break;

         default :
            bits = 0;
            status = ZL5011X_PARAMETER_INVALID;
      }
   }

   if (status == ZL5011X_OK)
   {
      bits |= (divider & ZL5011X_PAC_REF_DIVIDE_MASK) << ZL5011X_PAC_REF_DIVIDE_BITS;

      status = zl5011xWrite(zl5011xParams, ZL5011X_PAC_PRIMARY_REF_CONTROL, bits);
   }

   (void)memcpy(&(zl5011xParams->wanIf.clock.sync.primaryRef), &ref, sizeof(ref));

   return(status);
}

/*******************************************************************************

 Function:
    zl5011xPacConfigSecondaryRef

 Description:
    Configures the reference source and allows the divider to be
    explicitly set. This is useful when requiring general clock muxing
    functionality as opposed to DPLL usage.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   ref            source for the reference - stream or ext ref
   divider        divide ratio to apply to the reference i/p

 Outputs:
    None

 Returns:
   zlStatusE

 Remarks:
    None

*******************************************************************************/

zlStatusE zl5011xPacConfigSecondaryRef(zl5011xParamsS *zl5011xParams, zl5011xRefClkConfigS ref, Uint32T divider)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T bits;

   ZL5011X_TRACE(ZL5011X_PAC_FN_ID, "zl5011xPacConfigSecondaryRef:", 0, 0, 0, 0, 0, 0);

   if ((divider & ~ZL5011X_PAC_REF_DIVIDE_MASK) != 0)
   {
      status = ZL5011X_PARAMETER_INVALID;
   }

   if (status == ZL5011X_OK)
   {
      switch(ref.source)
      {
         case ZL5011X_WAN_PRIMARY_REF :
            bits = ZL5011X_PAC_PRIMARY_REF_SOURCE << ZL5011X_PAC_REF_SOURCE_BITS;
            break;

         case ZL5011X_WAN_SECONDARY_REF :
            bits = ZL5011X_PAC_SECONDARY_REF_SOURCE << ZL5011X_PAC_REF_SOURCE_BITS;
            break;

         case ZL5011X_WAN_STREAM_REF :
            bits = ref.stream << ZL5011X_PAC_REF_SOURCE_BITS;
            break;

         default :
            bits = 0;
            status = ZL5011X_PARAMETER_INVALID;
      }
   }

   if (status == ZL5011X_OK)
   {
      bits |= (divider & ZL5011X_PAC_REF_DIVIDE_MASK) << ZL5011X_PAC_REF_DIVIDE_BITS;

      status = zl5011xWrite(zl5011xParams, ZL5011X_PAC_SECONDARY_REF_CONTROL, bits);
   }

   (void)memcpy(&(zl5011xParams->wanIf.clock.sync.secondaryRef), &ref, sizeof(ref));

   return(status);
}

/*******************************************************************************

 Function:
    zl5011xPacDpllRefSetSingleLimit

 Description:
   Sets the high and low limits for the single period check on the reference
   input.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   secondaryRef   ZL5011X_FALSE for primary reference
                  ZL5011X_TRUE for secondary reference
   highLimit      upper limit used for determining a valid reference
   lowLimit       lower limit used for determining a valid reference

 Outputs:
    None

 Returns:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -