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

📄 le1veapp.c

📁 Zalink50114----TDMoIP芯片驱动源码
💻 C
📖 第 1 页 / 共 2 页
字号:
        result = zl5011xPacketTxSetHeaderStructInit(pZl5011xParams, &packetTxHeader);

        if (result == ZL5011X_OK)
        {
            /* get the payload length, for use in setting up the packet header */
            if (result == ZL5011X_OK)
            {
                result = zl5011xWanRxGetPayloadLengthStructInit(pZl5011xParams, &payloadLength);

                payloadLength.context = contextLoop;

                if (result == ZL5011X_OK)
                {
                    result = zl5011xWanRxGetPayloadLength(pZl5011xParams, &payloadLength);
                }
            }
        }

        if (result == ZL5011X_OK)
        {
            packetTxHeader.context = contextLoop;
            packetTxHeader.payloadLength = payloadLength.lengthBytes;
            packetTxHeader.rtpTimestampInc = 1;

            /* send all the high contexts to port 1 and the low ones to port 0 */
            if (contextLoop > 0)  /*(contextLoop > 63)*/
            {
                packetTxHeader.portNum = 1;
            }
            else
            {
                packetTxHeader.portNum = 0;
            }

            /* set the queue, based on the low 2 bits of the context number */
            packetTxHeader.queueNum = contextLoop & 3;

            /* use the header array defined locally */
            packetTxHeader.header = pZl5011xParams->pPktTxHeader[contextLoop];

            /* fill in this header array with header data */
            (void)populateHeader(contextLoop, pZl5011xParams->macAddress[0], packetTxHeader.header,
            &(packetTxHeader.headerLength), &(packetTxHeader.protocolType));

            result = zl5011xPacketTxSetHeader(pZl5011xParams, &packetTxHeader);
        }
    }

    /* Update the TDM input contexts */
    for (contextLoop = FIRST_CONTEXT;
        (contextLoop < (FIRST_CONTEXT + NUM_CONTEXTS)) && (result == ZL5011X_OK);
        contextLoop++)
    {
        context = contextLoop;

        printf("context %3d: TDM input update \n", context);

        result = zl5011xContextUpdateRxStructInit(pZl5011xParams, &contextInfo);

        if (result == ZL5011X_OK)
        {
            contextInfo.context = context;
            result = zl5011xContextUpdateRx(pZl5011xParams, &contextInfo);
        }
    }

	return (result);
}

zlStatusE le1veCreatTxContext(int slot)
{
	zl5011xParamsS       			*pZl5011xParams;
	zl5011xPacketRxSetHeaderS 		packetRxHeader;
	Uint8T 							*packetHeader;
	zl5011xContextCreateS 			contextCreate;
	zl5011xContextAddChannelTxS 	addChannelTx;
	zl5011xContextS 				contextInfo;
	zl5011xWanTxQueueConfigS 		wanTxQueue;
	zl5011xWanRxGetPayloadLengthS 	payloadLength;
	Uint32T contextLoop;
	Uint32T channelLoop;
	Uint32T context, stream, channel;
	zlStatusE status = ZL5011X_OK;

   pZl5011xParams = le1ve_Zl5011xParams[slot - 1];

   /*  Create the TDM output contexts (also referred to as WAN Tx contexts) */
   for ( contextLoop = FIRST_CONTEXT;
      (contextLoop < (FIRST_CONTEXT + NUM_CONTEXTS)) && (status == ZL5011X_OK);
      contextLoop++)
   {
      context = contextLoop;

      printf("context %3d: TDM output create\n", context);

      status = zl5011xContextCreateStructInit(pZl5011xParams, &contextCreate);
      /* For default values for structure contextCreate, see the  function
         zl5011xContextCreateStructInit() in file zl5011xTdm.c */
	if (NULL == (packetHeader = (Uint8T*)malloc(100)))
		status = ZL5011X_ERROR;
	else
	{
		pZl5011xParams->pPktRxHeader[contextLoop] = packetHeader;
	}

      if (status == ZL5011X_OK)
      {
         contextCreate.context = context;
         contextCreate.flow = ZL5011X_FLOW_PKT_WAN;  /*ZL5011X_FLOW_PKT_PE_WAN;*/

         status = zl5011xContextCreateTx(pZl5011xParams, &contextCreate);
      }
   }
#if 1
   /* Add channels to the TDM output contexts (structured mode only) */
   for (contextLoop = FIRST_CONTEXT;
      (contextLoop < (FIRST_CONTEXT + NUM_CONTEXTS)) && (status == ZL5011X_OK);
      contextLoop++)
   {
      context = contextLoop;

      for (channelLoop = 1; (channelLoop < 32) && (status == ZL5011X_OK); channelLoop++)
      {
         /* simply assign 32 channels to each context.  */
         stream = context;
         status = zl5011xContextAddChannelTxStructInit(pZl5011xParams, &addChannelTx);

         /* the structure addChannelTx is used to associate the context,
            stream & channel numbers.  For default
            values for structure addChannelTx, see the  function
            zl5011xContextAddChannelTxStructInit() in file zl5011xTdm.c */

         if (status == ZL5011X_OK)
         {
            addChannelTx.context = context;
            addChannelTx.tdm.stream = 0;
            addChannelTx.tdm.channel = channelLoop * 4 + stream;
            addChannelTx.underrunMode = ZL5011X_WAN_USE_FIXED_BYTE;
            addChannelTx.underrunByte = 0xFF;

            status = zl5011xContextAddChannelTx(pZl5011xParams, &addChannelTx);
         }
      }
   }
#endif
   /* Configure the TDM output queues (referred to as WAN Tx Queues)*/
   for (contextLoop = FIRST_CONTEXT;
      (contextLoop < (FIRST_CONTEXT + NUM_CONTEXTS)) && (status == ZL5011X_OK);
      contextLoop++)
   {
      context = contextLoop;

      printf("context %3d: TDM output queue configure\n", context);

      status = zl5011xWanTxQueueConfigStructInit(pZl5011xParams, &wanTxQueue);

      if (status == ZL5011X_OK)
      {
         wanTxQueue.context = context;
         wanTxQueue.queueMode = ZL5011X_WAN_TX_QUEUE_FIFO; /*ZL5011X_WAN_TX_QUEUE_RESEQUENCE_8;*/
         wanTxQueue.queueSize = ZL5011X_WAN_TX_QUEUE_SIZE_8;
         /* set the jitter buffer in TDM frames (1 frame = 125us) */
         wanTxQueue.jitterBufferSizeUs = 125 * 8;

         status = zl5011xWanTxQueueConfig(pZl5011xParams, &wanTxQueue);
      }
   }

   /* program the packet Rx header matching */
   for (contextLoop = FIRST_CONTEXT;
      (contextLoop < (FIRST_CONTEXT + NUM_CONTEXTS)) && (status == ZL5011X_OK);
      contextLoop++)
   {
      context = contextLoop;

      printf("context %3d: TDM output setup header\n", context);

      status = zl5011xPacketRxSetHeaderStructInit(pZl5011xParams, &packetRxHeader);

      if (status == ZL5011X_OK)
      {
         packetRxHeader.context = context;
         packetRxHeader.header = pZl5011xParams->pPktRxHeader[contextLoop];

          /* fill in the header array with header data */
         (void)populateHeader(context, pZl5011xParams->macAddress[0], packetRxHeader.header,
               &(packetRxHeader.headerLength), &(packetRxHeader.protocolType));

         status = zl5011xPacketRxSetProtocol(pZl5011xParams, &packetRxHeader);
      }

      if (status == ZL5011X_OK)
      {
         /* get the payload length, so that the packet matching can be set up */
         if (status == ZL5011X_OK)
         {
            status = zl5011xWanRxGetPayloadLengthStructInit(pZl5011xParams, &payloadLength);

            payloadLength.context = context;

            if (status == ZL5011X_OK)
            {
               status = zl5011xWanRxGetPayloadLength(pZl5011xParams, &payloadLength);
            }
         }
      }

      if (status == ZL5011X_OK)
      {
         packetRxHeader.payloadLength = payloadLength.lengthBytes;

         status = zl5011xPacketRxSetHeader(pZl5011xParams, &packetRxHeader);
      }
   }

   /* Update the TDM output contexts */
   for (contextLoop = FIRST_CONTEXT;
      (contextLoop < (FIRST_CONTEXT + NUM_CONTEXTS)) && (status == ZL5011X_OK);
      contextLoop++)
   {
      context = contextLoop;

      printf("context %3d: TDM output update\n", context);

      if (status == ZL5011X_OK)
      {
         status = zl5011xContextUpdateTxStructInit(pZl5011xParams, &contextInfo);

         if (status == ZL5011X_OK)
         {
            contextInfo.context = context;
            status = zl5011xContextUpdateTx(pZl5011xParams, &contextInfo);
         }
      }
   }
   return status;
}

/*-----------------------------------------

 Function:
   populateHeader

 Description:
   Dummy function used to prepare a protocol header for use in the packet header
   functions for the device.

*/
LOCAL void populateHeader(Uint32T context, UINT8 *macAddress, Uint8T *header, Uint8T *headerLength, zl5011xProtocolTypeE *protocol)
{
   Uint32T loop, index;

   /* put in the ethernet header */
   {
      /* Source & Destination MAC address */
      for (loop = 0; loop < ZL5011X_MAC_SIZE; loop++)
      {
         header[loop] = macAddress[loop];
         header[loop + ZL5011X_MAC_SIZE] = macAddress[loop];
      }

      /* setup the MAC addresses, such that traffic out of port 0 (contexts 0 to 63)
         goes to port 1 and vice-versa */
#if 0
      if (context > 63)
      {
         header[ZL5011X_MAC_SIZE + ZL5011X_MAC_SIZE - 1] = 1;
      }
      else
      {
         header[ZL5011X_MAC_SIZE - 1] = 1;
      }
#else
      if (header[ZL5011X_MAC_SIZE - 1] - 1 == 0)
          header[ZL5011X_MAC_SIZE - 1] = 3;
      else
          header[ZL5011X_MAC_SIZE - 1] = 1;
#endif
      /* put in the ethertype for IPv4 */
      index = 2 * ZL5011X_MAC_SIZE;
      header[index++] = (Uint8T)(ZL5011X_PKT_ETHERTYPE_IPV4 >> BITS_PER_BYTE);
      header[index++] = (Uint8T)ZL5011X_PKT_ETHERTYPE_IPV4;
   }

   /* put in an IPv4 header */
   {
      header[index++] = 0x45;
      /* type of service */
      header[index++] = 0x00;
      /* length */
      header[index++] = 0x00;
      header[index++] = 0x00;
      /* ident */
      header[index++] = 0x00;
      header[index++] = 0x00;
      /* fragment */
      header[index++] = 0x40;
      header[index++] = 0x00;
      /* TTL */
      header[index++] = 0x40;
      /* protocol */
      header[index++] = ZL5011X_PKT_IP_PROTOCOL_UDP;
      /* checksum */
      header[index++] = 0x00;
      header[index++] = 0x00;
      /* source addr */
      header[index++] = 192;
      header[index++] = 168;
      header[index++] = 161 + context;

      /* use the low byte of the IP src address to represent the context.
         This is useful when examining packets use a sniffer program */
          if (context == 0)
          {
             header[index++] = 128;
          }
          else
          {
             header[index++] = (Uint8T)context;
          }

      /* dest addr */
      header[index++] = 192;
      header[index++] = 168;
      header[index++] = 161 + context;
      header[index++] = 2;
   }

   /* put in a UDP header */
   {
          /* src port */
          header[index++]  = 0xc0;
          header[index++]  = 0x00;
          /* dest port */
          header[index++]  = 0xd0;
          header[index++]  = (Uint8T)context;
      /* length */
      header[index++]  = 0x00;
      header[index++]  = 0x00;
      /* checksum */
      header[index++]  = 0x00;
      header[index++]  = 0x00;
   }

   /* put in a RTP header */
   {
      header[index++]  = 0x80;
      header[index++]  = 0x00;
      header[index++]  = 0x00;
      header[index++]  = 0x00;
      header[index++]  = 0x00;
      header[index++]  = 0x00;
      header[index++]  = 0x00;
      header[index++]  = 0x00;
      header[index++]  = 0x02;
      header[index++]  = 0x03;
      header[index++]  = 0x04;
      header[index++]  = (Uint8T)context;
   }

   /* put in a PW header */
   {
      header[index++]  = 0x00;
      header[index++]  = 0x00;
      header[index++]  = 0x00;
      header[index++]  = 0x00;
   }

   /* fill in the header length and the protocol type */
   *headerLength = index;
   *protocol = ZL5011X_IP_UDP_RTP_PW;
}
#endif

⌨️ 快捷键说明

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