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

📄 zl5011xtdm.c

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

   return status;
}

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

 Function:
   zl5011xContextCreateTx

 Description:
   Function to create a Wan Tx context (that is Wan Tx from the device).
   Checks that the context is not currently in use and sets it to the INIT
   state. For unframed operation, the context relates directly to the stream
   number, so for this instance, also add the first channel (0) for the stream.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   par            Pointer to the structure for configuration items. See below:

 Structure inputs:
   context     context number for creation
   flow        routing through the device for the context - can be left as value
               specified in StructInit function for default operation.
   unframedStream.underrunMode   for unstructured operation, the behaviour on
                                 packet underrun can be set to repeat or
                                 playout a fixed pattern
   unframedStream.underrunByte   the fixed pattern to playout during underrun
   osExclusionEnable ZL5011X_TRUE to enable OS exclusion

 Structure outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xContextCreateTx(zl5011xParamsS *zl5011xParams, zl5011xContextCreateS *par)
{
   zlStatusE status = ZL5011X_OK;
   zl5011xWanChannelS tdm;
   zl5011xBooleanE gotDevice = ZL5011X_FALSE;

   /* do some parameter checking */
   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_RUNNING(zl5011xParams);
   }

   if ((status == ZL5011X_OK) && (par->osExclusionEnable == ZL5011X_TRUE))
   {
      /* get access to the device */
      status = zl5011xGetDevice(zl5011xParams, ZL5011X_GET_DEVICE_TIMEOUT_MODE);

      if (status == ZL5011X_OK)
      {
         gotDevice = ZL5011X_TRUE;
      }
   }

   /* check that the Wan Tx context is valid */
   if (status == ZL5011X_OK)
   {
      status = zl5011xContextCheckTx(zl5011xParams, par->context, ZL5011X_CHECK_CONTEXT_NUMBER);
   }

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE_CONTEXT(ZL5011X_TDM_FN_ID, par->context,
            "zl5011xContextCreateTx: ctxt %3d",
            par->context, 0, 0, 0, 0, 0);
   }

   if (status == ZL5011X_OK)
   {
      /* if the context is tearing down, then check to see if it has completed */
      if (zl5011xParams->wanIf.tfmCurrent.context[par->context].state == ZL5011X_STATE_TEARING_DOWN)
      {
         status = zl5011xTfmCheckContextTeardown(zl5011xParams, par->context);

         /* if the teardown has completed, then reset the error code and
            continue */
         if (status == ZL5011X_CONTEXT_TEARDOWN_COMPLETE)
         {
            status = ZL5011X_OK;
         }
      }
   }

   if (status == ZL5011X_OK)
   {
      /* check that the context is not currently in use */
      if (zl5011xParams->wanIf.tfmCurrent.context[par->context].state != ZL5011X_STATE_NOT_IN_USE)
      {
         status = ZL5011X_CONTEXT_IN_USE;
      }
   }

   if (status == ZL5011X_OK)
   {
      if (par->flow == (zl5011xFlowTypeE)ZL5011X_INVALID)
      {
         /* if the flow type has not been specified then set the default
            for this direction */
         zl5011xParams->wanIf.wanTxFlow[par->context] = ZL5011X_FLOW_PKT_PE_WAN;
      }
      else
      {
         zl5011xParams->wanIf.wanTxFlow[par->context] = par->flow;
      }

      zl5011xParams->wanIf.tfmCurrent.context[par->context].state = ZL5011X_STATE_INIT;

      /* reset the PW status byte counts etc. Set the current value to an invalid value to
         indicate that it has not yet been initialised. */
      zl5011xParams->packetIf.packetRx.contextRxPacketMatch[par->context].statusByte.value = (Uint32T)ZL5011X_INVALID;

      {
         Uint32T loop;

         for (loop = 0; loop < ZL5011X_PKC_NUM_CLASSIFY_ENTRIES; loop++)
         {
            if (zl5011xParams->packetIf.packetRx.pkcClassify[loop].context == par->context)
            {
               zl5011xParams->packetIf.packetRx.pkcClassify[loop].context = (Uint32T)ZL5011X_INVALID_CONTEXT;
            }
         }
      }
   }

   if (status == ZL5011X_OK)
   {
      /* reset the RTP statistics - packet Rx */
      status = zl5011xRtpInitStatisticsRxEntry(zl5011xParams, par->context);
   }

   if (status == ZL5011X_OK)
   {
      /* reset the TDM queue statistics */
      status = zl5011xTfqResetStats(zl5011xParams, par->context);
   }

   /* if in unframed mode, then need to add the stream to the context now */
   if ((status == ZL5011X_OK) && (zl5011xParams->wanIf.wanConnectionMode == ZL5011X_WAN_CONNECTION_UNFRAMED))
   {
      tdm.stream = (Uint8T)par->context;
      tdm.channel = 0;

      status = zl5011xTfmAddChan(zl5011xParams, par->context, tdm);

      if (status == ZL5011X_OK)
      {
         /* the channel defaults to the last byte when added by the TFM.
            If the underrun byte is specified, then set it */
         if (par->unframedStream.underrunMode == ZL5011X_WAN_USE_FIXED_BYTE)
         {
            status = zl5011xTfmSetChanUnderrun(zl5011xParams, tdm,
                  par->unframedStream.underrunByte, par->unframedStream.underrunMode);
         }
      }
   }

   if (gotDevice == ZL5011X_TRUE)
   {
      if (status == ZL5011X_OK)
      {
         status = zl5011xReleaseDevice(zl5011xParams);
      }
      else
      {
         /* already have an error code, so don't overwrite it */
         (void)zl5011xReleaseDevice(zl5011xParams);
      }
   }

   return status;
}

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

 Function:
   zl5011xContextAddChannelRxStructInit

 Description:
   Initialises structure used by zl5011xContextAddChannelRx function.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   par            Pointer to the structure for configuration items.
                  See main function

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xContextAddChannelRxStructInit(zl5011xParamsS *zl5011xParams, zl5011xContextAddChannelRxS *par)
{
   zlStatusE status = ZL5011X_OK;

   /* do some parameter checking */
   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_TDM_FN_ID,
            "zl5011xContextAddChannelRxStructInit:",
            0, 0, 0, 0, 0, 0);

      par->context = (Uint32T)ZL5011X_INVALID_CONTEXT;
      par->tdm.stream = (Uint8T)ZL5011X_INVALID_STREAM;
      par->tdm.channel = (Uint8T)ZL5011X_INVALID_CHANNEL;
      par->checkChannelCombination = ZL5011X_TRUE;

      par->osExclusionEnable = ZL5011X_TRUE;
   }

   return status;
}

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

 Function:
   zl5011xContextAddChannelRx

 Description:
   Adds a channel to a context.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   par            Pointer to the structure for configuration items. See below:

 Structure inputs:
   context     context to be used
   tdm.stream  the stream that the channel to be added is from
   tdm.channel which channel to add
   checkChannelCombination ZL5011X_FALSE to disable checking of the channel
               combination
   osExclusionEnable ZL5011X_TRUE to enable OS exclusion

 Structure outputs:
   None

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xContextAddChannelRx(zl5011xParamsS *zl5011xParams, zl5011xContextAddChannelRxS *par)
{
   zlStatusE status = ZL5011X_OK;
   Uint32T loop, chanIndex;
   zl5011xWanChannelS tdm;
   zl5011xBooleanE gotDevice = ZL5011X_FALSE;

   /* do some parameter checking */
   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      status = ZL5011X_CHECK_RUNNING(zl5011xParams);
   }

   if ((status == ZL5011X_OK) && (par->osExclusionEnable == ZL5011X_TRUE))
   {
      /* get access to the device */
      status = zl5011xGetDevice(zl5011xParams, ZL5011X_GET_DEVICE_TIMEOUT_MODE);

      if (status == ZL5011X_OK)
      {
         gotDevice = ZL5011X_TRUE;
      }
   }

   /* check that the Wan Rx context is valid */
   if (status == ZL5011X_OK)
   {
      status = zl5011xContextCheckRx(zl5011xParams, par->context, ZL5011X_CHECK_CONTEXT_MODIFY);
   }

   /* main function code starts */

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE_CONTEXT(ZL5011X_TDM_FN_ID, par->context,
            "zl5011xContextAddChannelRx: ctxt %3d",
            par->context, 0, 0, 0, 0, 0);
   }

   if (par->checkChannelCombination == ZL5011X_TRUE)
   {
      if (status == ZL5011X_OK)
      {
         /* check that a valid stream / channel combination has been provided before
            making any further checks */
         status = zl5011xCheckTdm(zl5011xParams, par->tdm, &chanIndex);
      }

      tdm.channel = par->tdm.channel;

      /* check that no other channels of this number have been configured so far */
      for (loop = 0; loop < zl5011xParams->wanIf.wanNumStreams; loop++)
      {
         if (status != ZL5011X_OK)
         {
            break;
         }

         tdm.stream = (Uint8T)loop;
         status = zl5011xCalcChanIndex(zl5011xParams, tdm, &chanIndex);

         if (status == ZL5011X_OK)
         {
            if (zl5011xParams->wanIf.plaCurrent.channel[chanIndex].context == par->context)
            {
               if (par->tdm.stream != tdm.stream)
               {
                  status = ZL5011X_CHANNEL_INVALID;
               }
            }
         }
      }
   }

   if (status == ZL5011X_OK)
   {
      status = zl5011xPlaAddChan(zl5011xParams, par->context, par->tdm);
   }

   if (gotDevice == ZL5011X_TRUE)
   {
      if (status == ZL5011X_OK)
      {
         status = zl5011xReleaseDevice(zl5011xParams);
      }
      else
      {
         /* already have an error code, so don't overwrite it */
         (void)zl5011xReleaseDevice(zl5011xParams);
      }
   }

   return status;
}

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

 Function:
   zl5011xContextAddChannelTxStructInit

 Description:
   Initialises structure used by zl5011xContextAddChannelTx function.

 Inputs:
   zl5011xParams   Pointer to the structure for this device instance
   par            Pointer to the structure for configuration items.
                  See main function

 Returns:
   zlStatusE

 Remarks:
   None

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

zlStatusE zl5011xContextAddChannelTxStructInit(zl5011xParamsS *zl5011xParams,
      zl5011xContextAddChannelTxS *par)
{
   zlStatusE status = ZL5011X_OK;

   /* do some parameter checking */
   status = ZL5011X_CHECK_POINTERS(zl5011xParams, par);

   if (status == ZL5011X_OK)
   {
      ZL5011X_TRACE(ZL5011X_TDM_FN_ID,
            "zl5011xContextAddChannelTxStructInit:",
            0, 0, 0, 0, 0, 0);

      par->context = (Uint32T)ZL5011X_INVALID_CONTEXT;
      par->tdm.stream = (Uint8T)ZL5011X_INVALID_STREAM;
      par->tdm.channel = (Uint8T)ZL5011X_INVALID_CHANNEL;
      par->checkChannelCombination = ZL5011X_TRUE;

      par->underrunMode = ZL5011X_WAN_USE_FIXED_BYTE;
      par->underrunByte = 0xff;

      par->osExclusionEnable = ZL5011X_TRUE;
   }

   return status;
}

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

⌨️ 快捷键说明

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