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.

UDP packet sending

Other Parts Discussed in Thread: TMS320C6748

Hello,

I am newbie to the Ethernet programming.

Could anyone assist me with the udp packet sending from the dsp TMS320c6748.

I have custom board which is inspired by the LCDKC6748.

I am trying to used the example projects given in the starterware and i have manipulated the enet_echo in a way that i can sense the packet sent from the pc to the dsp in the debugger however i have no idea how to send the packet from dsp to the pc.

Could anyone guide me over it please?

  • Dear Axay,
    Let me check the code and give you.
    Thanks for your patience.

    I can remember that you have to use "sendto" API to send the UDP packet from DSP to PC.

    Something like this.

    Sample code snippet.
    /*
    * udpHello.c
    *
    * This program implements a UDP echo server, which echos back any
    * input it receives.
    *
    * Copyright (C) 2007 Texas Instruments Incorporated - http://www.ti.com/
    *
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the
    * distribution.
    *
    * Neither the name of Texas Instruments Incorporated nor the names of
    * its contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    */

    #include <ti/ndk/inc/netmain.h>

    SOCKET socksend = INVALID_SOCKET;
    static int PktNum = 0;
    char buff1[1024] = {0};
    //
    // dtask_udp_hello() - UDP Echo Server Daemon Function
    // (SOCK_DGRAM, port 7)
    //
    // Returns "1" if socket 's' is still open, and "0" if its been closed
    //
    int dtask_udp_hello( SOCKET s, UINT32 unused )
    {
    struct sockaddr_in sin1;
    struct timeval to;
    int i,tmp;
    char *pBuf;
    HANDLE hBuffer;

    (void)unused;

    // Configure our socket timeout to be 3 seconds
    to.tv_sec = 3;
    to.tv_usec = 0;
    setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
    setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );

    for(;;)
    {
    tmp = sizeof( sin1 );
    i = (int)recvncfrom( s, (void **)&pBuf, 0, (PSA)&sin1, &tmp, &hBuffer );

    // Spit any data back out
    if( i >= 0 )
    {
    sendto( s, pBuf, i, 0, (PSA)&sin1, sizeof(sin1) );
    recvncfree( hBuffer );
    }
    else
    break;
    }

    // Since the socket is still open, return "1"
    // (we need to leave UDP sockets open)
    return(1);
    }

    int sendUDPTsk()
    {
    struct sockaddr_in sinData, cliAddr;
    int sa_size1 = 0, err = 0;
    int retSize1 = 0, buff_size1 = 0, i = 0, chain = 0;

    //Allocate the file environment for this task
    fdOpenSession( TaskSelf() );

    //Initialize the socket
    socksend = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (socksend == INVALID_SOCKET)
    {
    printf(" socket(socksend) failed \n");
    return -1;
    }

    err = setsockopt( socksend, SOL_SOCKET, SO_REUSEADDR, buff1, 1472 );
    err = setsockopt( socksend, SOL_SOCKET, SO_REUSEPORT, buff1, 1472 );

    //Initialize socket address in structure
    bzero( &sinData, sizeof(struct sockaddr_in) );
    sinData.sin_family = AF_INET;
    sinData.sin_len = sizeof( sinData );
    sinData.sin_addr.s_addr = INADDR_ANY;
    sinData.sin_port = htons(2500);

    //Bind the socket
    err = bind (socksend, (struct sockaddr *)&sinData, sizeof(sinData));
    if(err == 0)
    printf("Send-Bind operation successfully done\n");
    else
    {
    printf("Send-Bind operation failed errno= %d\n", fdError());
    return -1;
    }

    bzero( &cliAddr, sizeof(struct sockaddr_in) );
    cliAddr.sin_family = AF_INET;
    cliAddr.sin_len = sizeof( cliAddr );
    cliAddr.sin_addr.s_addr = inet_addr("10.100.1.209"); //Target IP(PC IP address)
    cliAddr.sin_port = htons(2501);
    sa_size1 = sizeof(struct sockaddr_in);
    buff_size1 = 1024; //1472;

    TaskSleep(10000);
    buff1[0] = 48;

    while(1)
    {

    TaskSleep(500);
    buff1[1] = i + 48;
    i++;
    chain ^= 1;
    if(chain == 0)
    memset(buff1, '1', 1024);
    else
    memset(buff1, 'A', 1024);

    retSize1 = sendto(socksend, buff1, buff_size1, 0, (struct sockaddr *)&cliAddr, sa_size1);
    if(retSize1 < 0)
    printf(" Error Sending sendto() %d \n", fdError());
    else
    printf(" %d.Send_Size = %d \n ", PktNum,retSize1);
    PktNum++;

    if(i==10)
    i = 0;


    }


    }