This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

HALCoGen Ethernet Driver and lwIP Integration Demonstration Library for UDP

Other Parts Discussed in Thread: TMS570LC4357, HALCOGEN

Hi TI,

I am using TMS570LC4357. I wants to integrate HALCoGen Ethernet Driver and lwIP Integration Demonstration Library to establish a UDP communication. I have downloaded the Demo Code from  .

I had also read the lwip.pdf for using lwIP API for UDP communication. In that PDF, they given the example code only for the TCP/IP server configuration. So I copied that code and paste it in the ethernet demo project given in the CCS environment.

Unfortunately when I try to build it, shows lot of errors.

Please anybody guide me to use this library for establishing UDP communication or else TCP/IP communication atleast with the available example code in lwip.pdf which is located in C:\ti\Hercules\HALCoGen EMAC Driver with lwIP Demonstration\v00.03.00\lwip-1.4.1\doc\lwip.pdf.


Expecting your guidance.

Thanks in advance.

Regards,

Karthikeyan.K

  • Hi TI,

    Please anybody do reply.

    Thanks,

    Regards,
    Karthikeyan.K
  • Hello:

    Your question has been directed to our experts. We will get back to you soon.

    Regards,

    Enrique
  • Hi Karthikeyan,

    http://processors.wiki.ti.com/index.php/HALCoGen_Ethernet_Driver_and_lwIP_Integration_Demonstration

    Have you make this HTTP web server demo work using TCP/IP?

    The demo project has functions called LocatorConfig(...) , Locatorreceive(..) in Locator.c. Those functions are called by the LWIP TCP/IP stack when it receives a UDP packet from the discovery port. It produces the response packet, which is sent back to the querying client. You can use those functions as reference to write your own functions for UDP communication.

    pcb = udp_new();
    udp_recv(pcb, ...);
    udp_bind(pcb, ...);
    udp_connect(pcb, ...);

    BTW, HTTP uses TCP since the files, images, web pages which we get from the remote host should not be dropped on the way and it should be re-transimitted if it is lost. HTTP could also use UDP but usually not, if a UDP packet containing the first part of a web page is lost, then its not re-transmitted. You need to write some code in your application layer to handle these re-transmissions of lost packets when you use UDP.

    Regards,

    QJ

  • Hi QJ,

    Thanks for your reply.

    Really I am confused with how to use this library. Pls help me.

    Actually the demo code works perfectly. But what I want is that I have to use this library exactly for UDP communication alone, Not the server Configuration (like the demo code does.). So What are the parts I've to disable so that some of the files which are not needed will not get compiled. (ex: the html file, fsdata.c). When doing this I should not disable the necessary parts of the library. (ex: udp_output()).

    In order to achieve this I have to start from the beginning or I have to reuse some of the codes alone of this library.

    I followed the steps you suggest and the same is avialable in "...\lwip-1.4.1\doc\rawapi.txt". But my code didn't worked. Here I have posted the code. please help me in fixing this issue.

    /* USER CODE BEGIN (0) */
    #include "udp.h"
    #include "pbuf.h"
    #include "lwip/ip_addr.h"
    /* USER CODE END */
    
    /* Include Files */
    
    #include "HL_sys_common.h"
    #include "HL_system.h"
    
    /* USER CODE BEGIN (1) */
    extern void EMAC_LwIP_Main (uint8_t * emacAddress);
    /* USER CODE END */
    
    
    /* USER CODE BEGIN (2) */
    static unsigned char locatorData1[84];
    static void LocatorReceive1(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port);
    
    static void LocatorReceive1(void *arg, struct udp_pcb *pcb, struct pbuf *p,
                               struct ip_addr *addr, u16_t port)
    {
        unsigned char *pucData;
        unsigned long ulIdx;
    
        /* Validate the contents of the datagram.*/
        /* Clear out the response data.*/
        pucData = p->payload;
    
        if((p->len != 4) || (pucData[0] != 0xFF/*TAG_CMD*/) || (pucData[1] != 4) ||
           (pucData[2] != 0x02 /*CMD_DISCOVER_TARGET*/) ||
           (pucData[3] != ((0 - 0xFF/*TAG_CMD*/ - 4 - 0x02/*CMD_DISCOVER_TARGET*/) & 0xff))) {
               pbuf_free(p);
            return;
        }
    
        pbuf_free(p);
    
        p = pbuf_alloc(PBUF_TRANSPORT, sizeof(locatorData1), PBUF_RAM);
        if(p == NULL)
        {
            return;
        }
    
        /* Calcuate and fill in the checksum on the response packet.*/
        for(ulIdx = 0, locatorData1[sizeof(locatorData1) - 1] = 0;
            ulIdx < (sizeof(locatorData1) - 1); ulIdx++)
        {
            locatorData1[sizeof(locatorData1) - 1] -=
                locatorData1[ulIdx];
        }
    
        /* Copy the response packet data into the pbuf. */
        pucData = p->payload;
        for(ulIdx = 0; ulIdx < sizeof(locatorData1); ulIdx++)
        {
            pucData[ulIdx] = locatorData1[ulIdx];
        }
    
        /* Send the response.*/
        udp_sendto(pcb, p, addr, port);
    
        pbuf_free(p);
    }
    /* USER CODE END */
    
    uint8	emacAddress[6U] = 	{0x00U, 0x08U, 0xEEU, 0x03U, 0xA6U, 0x6CU};
    uint32 	emacPhyAddress	=	1U;
    
    void main(void)
    {
    /* USER CODE BEGIN (3) */
    	char Titl[] = "HDK enet_lwip";
    	char *Title = Titl;
    	char idx=0;
    	struct ip_addr *ipaddr;
    		struct ip_addr *dst_ip;
    	    struct pbuf *p;
    	    struct udp_pcb *pcb;
    
    		ipaddr->addr = (u32_t) 0xA00A0302;
    	    dst_ip->addr = (u32_t) 0x0AA91E1A;
    
    	EMAC_LwIP_Main(emacAddress);
    
    
    
    
    
    	pcb = udp_new();
    
        for(idx = 0; idx < 84; idx++)
        {
            locatorData1[idx] = 0;
        }
    
        /* Fill in the header for the response data.*/
        locatorData1[0] = 0xFE/*TAG_STATUS*/;
        locatorData1[1] = sizeof(locatorData1);
        locatorData1[2] = 0x02/*CMD_DISCOVER_TARGET*/;
    
        /* Fill in the MAC address for the response data. */
        locatorData1[9] =  emacAddress[0];
        locatorData1[10] = emacAddress[1];
        locatorData1[11] = emacAddress[2];
        locatorData1[12] = emacAddress[3];
        locatorData1[13] = emacAddress[4];
        locatorData1[14] = emacAddress[5];
    
    
    	udp_recv(pcb, LocatorReceive1, NULL);
    
    	for(idx = 0; (idx < 64) && *Title; idx++)
    	    {
    	        locatorData1[idx + 19] = *Title++;
    	    }
    
    	for(; idx < 64; idx++)
    	    {
    	        locatorData1[idx + 19] = 0;
    	    }
    
    	(void)udp_bind(pcb,ipaddr,6897);
    
    	(void)udp_connect(pcb,ipaddr,6897);
    
    	udp_sendto(pcb,p,dst_ip,8080);
    
    /* USER CODE END */
    }
    
    /* USER CODE BEGIN (4) */
    /* USER CODE END */
    

    So clearly, I dont want the TCP interface and only needs the UDP interface. how to achieve this using this lwIP Driver code?

    Thanks in advance.


    Please help me.

    Regards,

    Karthikeyan.K