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

📄 zl5011xtif.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 4 页
字号:
*******************************************************************************/

zlStatusE zl5011xTifSetDataRate(zl5011xParamsS *zl5011xParams,
      zl5011xWanIfDataRateE dataRate)
{
   Uint32T bit, bitMask;
   zlStatusE status =  ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_TIF_FN_ID, "zl5011xTifSetDataRate: %d",
         dataRate, 0, 0, 0, 0, 0);

   status = ZL5011X_CHECK_WAN_IF_DATA_RATE(dataRate);

   if (status == ZL5011X_OK)
   {
      bit = (Uint32T)dataRate <<  ZL5011X_TIF_DATA_RATE_BITS;
      bitMask = ZL5011X_TIF_DATA_RATE_MASK << ZL5011X_TIF_DATA_RATE_BITS;

      status = zl5011xUpdateRegisters(zl5011xParams, ZL5011X_TIF_CTRL_REG,
               &zl5011xParams->wanIf.wanIfControl, bit, bitMask);

      zl5011xParams->wanIf.wanDataRate = dataRate;
   }

   return(status);
}

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

 Function:
   zl5011xTifSetRefClockPolarity

 Description:
   Configures the reference clock polarity.

 Inputs:
   zl5011xParams      Pointer to the structure for this device instance
   polarity          Configures the polarity of the ref clock for TDM.

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xTifSetRefClockPolarity(zl5011xParamsS *zl5011xParams,
      zl5011xPolarityE polarity)
{
   Uint32T bit, bitMask;
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_TIF_FN_ID, "zl5011xTifSetRefClockPolarity: %d",
         polarity, 0, 0, 0, 0, 0);

   status = ZL5011X_CHECK_POLARITY(polarity);

   if (status == ZL5011X_OK)
   {
      bit = (Uint32T)polarity <<  ZL5011X_TIF_REF_POL_BIT;
      bitMask = ZL5011X_1BIT_MASK << ZL5011X_TIF_REF_POL_BIT;

      status = zl5011xUpdateRegisters(zl5011xParams, ZL5011X_TIF_CTRL_REG,
               &zl5011xParams->wanIf.wanIfControl, bit, bitMask);

      zl5011xParams->wanIf.refClkPolarity = polarity;
   }

   return(status);
}

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

 Function:
   zl5011xTifSetConnectionMode

 Description:
   Sets the fundamental operating mode of the device:
      unframed, framed, backplane

 Inputs:
   zl5011xParams      Pointer to the structure for this device instance
   mode              selects the TDM mode

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xTifSetConnectionMode(zl5011xParamsS *zl5011xParams,
      zl5011xWanIfConnectionTypeE mode)
{
   Uint32T bit, bitMask;
   zlStatusE status =  ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_TIF_FN_ID, "zl5011xTifSetConnectionMode: %d",
         mode, 0, 0, 0, 0, 0);

   status = ZL5011X_CHECK_WAN_IF_CONNECTION_TYPE(mode);

   if (status == ZL5011X_OK)
   {
      bit = (Uint32T)mode <<  ZL5011X_TIF_CONNECTION_BITS;
      bitMask = ZL5011X_TIF_CONNECTION_MASK << ZL5011X_TIF_CONNECTION_BITS;

      status = zl5011xUpdateRegisters(zl5011xParams, ZL5011X_TIF_CTRL_REG,
               &zl5011xParams->wanIf.wanIfControl, bit, bitMask);

      zl5011xParams->wanIf.wanConnectionMode = mode;
   }

   return(status);
}

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

 Function:
   zl5011xTifSetInputClockPolarity

 Description:
   Configures the input clock polarity for a given stream.

 Inputs:
   zl5011xParams      Pointer to the structure for this device instance
   streamNumber      which stream to set the polarity for
   polarity          Configures the polarity for the input TDM stream

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xTifSetInputClockPolarity(zl5011xParamsS *zl5011xParams,
      Uint8T streamNumber, zl5011xPolarityE polarity)
{
   AddressT address;    /* Address for Clock Polarity Register */
   Uint32T newBit;      /* Bit to be updated */
   Uint32T newBitMask;  /* Mask for bit to be updated */
   Uint32T wrapAddress, bitShift;
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_TIF_FN_ID, "zl5011xTifSetInputClockPolarity: stream %d, polarity %d",
         streamNumber, polarity, 0, 0, 0, 0);

   /* check input stream is in range */
   status = zl5011xCheckStreamRange(zl5011xParams, streamNumber);

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_POLARITY(polarity);
   }

   if (status == ZL5011X_OK)
   {
      /* if the stream number is greater than 32, then need to use increment
         address the address for every multiple of 32 */
      wrapAddress = streamNumber / 32;
      bitShift = streamNumber % 32;

      address = ZL5011X_TIF_CLK_IN_POL_REG0 + (wrapAddress * sizeof(Uint32T));

      newBit = (Uint32T)polarity <<  bitShift;
      newBitMask = ZL5011X_1BIT_MASK << bitShift;

      /* Update clock polarity */
      status = zl5011xUpdateRegisters(zl5011xParams, address,
         zl5011xParams->wanIf.inputClockPolarity + wrapAddress, newBit, newBitMask);
   }

   return status;
}

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

 Function:
   zl5011xTifSetOutputClockPolarity

 Description:
   Configures the output clock polarity for a given stream.

 Inputs:
   zl5011xParams      Pointer to the structure for this device instance
   streamNumber      which stream to set the polarity for
   polarity          Configures the polarity for the input TDM stream

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xTifSetOutputClockPolarity(zl5011xParamsS *zl5011xParams,
      Uint8T streamNumber, zl5011xPolarityE polarity)
{
   AddressT address;    /* Address for Clock Polarity Register */
   Uint32T newBit;      /* Bit to be updated */
   Uint32T newBitMask;  /* Mask for bit to be updated */
   Uint32T wrapAddress, bitShift;
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_TIF_FN_ID, "zl5011xTifSetOutputClockPolarity: stream %d, polarity %d",
         streamNumber, polarity, 0, 0, 0, 0);

   /* check input stream is in range */
   status = zl5011xCheckStreamRange(zl5011xParams, streamNumber);

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_POLARITY(polarity);
   }

   if (status == ZL5011X_OK)
   {
      /* if the stream number is greater than 32, then need to use increment
         address the address for every multiple of 32 */
      wrapAddress = streamNumber / 32;
      bitShift = streamNumber % 32;

      address = ZL5011X_TIF_CLK_OUT_POL_REG0 + (wrapAddress * sizeof(Uint32T));

      newBit = (Uint32T)polarity <<  bitShift;
      newBitMask = ZL5011X_1BIT_MASK << bitShift;

      /* Update clock polarity */
      status = zl5011xUpdateRegisters(zl5011xParams, address,
         zl5011xParams->wanIf.outputClockPolarity + wrapAddress, newBit, newBitMask);
   }

   return status;
}

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

 Function:
   zl5011xTifDisableAllChannels

 Description:
   Used to disable (Hi-Z) all channels.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xTifDisableAllChannels(zl5011xParamsS *zl5011xParams)
{
   Uint32T loop;
   zlStatusE status =  ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_TIF_FN_ID, "zl5011xTifDisableAllChannels:",
         0, 0, 0, 0, 0, 0);

   if (zl5011xParams->wanIf.wanConnectionMode != ZL5011X_WAN_CONNECTION_UNFRAMED)
   {
      for (loop = 0; loop < (sizeof(zl5011xParams->wanIf.channelOutputEnable) / 4); loop++)
      {
         if (status != ZL5011X_OK)
            break;

         status = zl5011xUpdateRegisters(zl5011xParams,
               ZL5011X_TIF_HIZ_REG + (loop * sizeof(Uint32T)),
               zl5011xParams->wanIf.channelOutputEnable + loop,
               0, 0xffffffff);
      }
   }

   return status;
}

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

 Function:
   zl5011xTifChannelIndexEnable

 Description:
   Used to enable / disable (Hi-Z) a channel.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   chanIndex      index that represents a stream / channel combination
   enable         enable / hi-z the channel

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   May only be called in structured / backplane mode.

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

zlStatusE zl5011xTifChannelIndexEnable(zl5011xParamsS *zl5011xParams,
      Uint32T chanIndex, zl5011xWanIfOutputEnableE enable)
{
   AddressT address;
   Uint32T newBit;      /* Bit to be updated */
   Uint32T newBitMask;  /* Mask for bit to be updated */
   Uint32T wrapAddress, bitShift;
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_TIF_FN_ID, "zl5011xTifChannelIndexEnable: chanIndex %3d, enable %d",
         chanIndex, enable, 0, 0, 0, 0);

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_WAN_IF_OUTPUT_ENABLE(enable);
   }

   if (status == ZL5011X_OK)
   {
      if (zl5011xParams->wanIf.wanConnectionMode == ZL5011X_WAN_CONNECTION_UNFRAMED)
      {
         status = ZL5011X_INVALID_MODE;
      }
      else
      {
         /* if the channel number is greater than 32, then need to use increment
         address the address for every multiple of 32 */
         wrapAddress = chanIndex / 32;
         bitShift = chanIndex % 32;

         address = ZL5011X_TIF_HIZ_REG + (wrapAddress * sizeof(Uint32T));

         newBit = (Uint32T)enable <<  bitShift;
         newBitMask = ZL5011X_1BIT_MASK << bitShift;

         /* Update output enable */
         status = zl5011xUpdateRegisters(zl5011xParams, address,
               zl5011xParams->wanIf.channelOutputEnable + wrapAddress,
               newBit, newBitMask);
      }
   }

   return status;
}

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

 Function:
   zl5011xTifChannelEnable

 Description:
   Used to enable / disable (Hi-Z) a channel.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   tdm            stream / channel to enable
   enable         enable / hi-z the channel

 Outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   May only be called in structured / backplane mode.

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

zlStatusE zl5011xTifChannelEnable(zl5011xParamsS *zl5011xParams,
      zl5011xWanChannelS tdm, zl5011xWanIfOutputEnableE enable)
{
   Uint32T chanIndex;
   zlStatusE status = ZL5011X_OK;

   ZL5011X_TRACE(ZL5011X_TIF_FN_ID, "zl5011xTifChannelEnable: stream %2d, channel %3d, enable %d",
         tdm.stream, tdm.channel, enable, 0, 0, 0);

   /* check input stream is in range */
   status = zl5011xCheckTdm(zl5011xParams, tdm, &chanIndex);

   if (status == ZL5011X_OK)
   {
      status = zl5011xTifChannelIndexEnable(zl5011xParams, chanIndex, enable);
   }

   return status;
}

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

 Function:
   zl5011xTifReverseBitOrder

 Description:
   This function determines how the TIF constructs the bytes from the input
   stream (and vice-versa).
   The default is to use the first bit as the MSB. The reversed order is for
   the first bit to be the LSB.

⌨️ 快捷键说明

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