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.

Properly connection parameters (TMDSEVM6670L ethernet). Custom socket project

Other Parts Discussed in Thread: SYSBIOS

Hello again.

Still the same board (TMDSEVM6670L), still the same problems. 

I want to send from the PC (client) the string array to the board (server) and send back the string array, which is declared on board. I use this code on PC (client):

SOCKET mysocket;
  if (INVALID_SOCKET == (mysocket = socket (AF_INET, SOCK_STREAM, 0) ) )
   {
      // Error...
      error = WSAGetLastError();
      // ... 
   }
  sockaddr_in mysocket_addr;
  ZeroMemory (&mysocket_addr, sizeof (mysocket_addr));
  mysocket_addr.sin_family = AF_INET;
   
   mysocket_addr.sin_addr.S_un.S_addr = inet_addr ("192.168.1.200"); 
   mysocket_addr.sin_port = htons (1234);

   if (SOCKET_ERROR == ( connect (mysocket, (sockaddr *) &mysocket_addr, sizeof (mysocket_addr) ) ) )
   {
      // Error...
      error = WSAGetLastError();
      // ... 
   }
   
   if (SOCKET_ERROR == ( send (mysocket, sHELLO, sizeof(sHELLO), 0 ) ) )
   {
      // Error...
      error = WSAGetLastError();
      // ... 
   }
   
     if (SOCKET_ERROR == ( recv (mysocket, (char* ) & buff, sizeof(*buff), 0 ) ) )
   {
      // Error...
      error = WSAGetLastError();
      // ... 
   }
   closesocket(mysocket);

And this code on server (board):

 SOCKET s; 
        SOCKET client_socket;    
        struct sockaddr_in server_addr;
        server_addr.sin_family = AF_INET;
        server_addr.sin_port = htons(1234);
        server_addr.sin_addr.s_addr = inet_addr("192.168.1.200");
        s = socket (AF_INET, SOCK_STREAM, 0);

        bind(s, (struct sockaddr*)& server_addr, sizeof(server_addr));

        struct sockaddr_in client_addr;


        client_addr.sin_addr.s_addr = inet_addr("192.168.1.1");
        int client_addr_size=sizeof(client_addr);
        client_socket=accept(s, (struct sockaddr *)&client_addr, &client_addr_size);

        //connect - bind - accept - send - recieve

       
        listen(s, 0x100);
       for (;;)
        {
         recv(client_socket,&buff[0],sizeof(buff),0);
         send(client_socket,message,sizeof(message),0);
        }


Still i'm thinking that i've done everything completely wrong, so i;m really asking for help. And also, can i use not the "7" port for the connection, because it's using only for testing?

And also... I must use "sendto" and "recvfrom", or simple "send" and "recieve" would be enough?

  • Hi,
    Which example are you using ?
    hello world or client ?
    Can you please refer to the following post.

    e2e.ti.com/.../1397057
  • Hello Titus. I'm using client example.
  • Hello again.

    I've followed the thread and got some problems. Debug stops at the 

    rSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP );
                if( rSocket == INVALID_SOCKET )
                	printf("FATAL ERROR! SOCKET IS NOT CREATED \n");


    And returns this in the console:

    00000.000 llEnter: Illegal priority call to llEnter()
    00000.000 llExit: Illegal call to llExit()

    What's wrong with this thing? If i'm using only recieve section, it's working, but when i add send section, this error appears. Is that a memory configuration issue or i've just mistaked in the socket creation code?

  • BTW: you've refered me once to the MCSDK "Helloworld" example. But neither there nor there i've not found the socket creation mechanism. Certain projects Daemon-functions are using sockets, but there are no functions of initiating socket. I'm really confused about how i can combine simple project and the 

     thread project.

    And the last question. Which port is good for the transmission? I've tryed many and the board says me, that all of them are unreachable.

  • Hi Taras,

    I have used "hello world" NDK example code which receive the UDP packets and send back to the same IP address.

    So, you can use the function "dtask_udp_hello" from "udpHello.c" then create socket to do that....

    You can also change the port no as your wish.

    Here, 7 is the port no...

    Ex:

    static void NetworkOpen()

    {

       // Create our local server

       hHello = DaemonNew( SOCK_DGRAM, 0, 7, dtask_udp_hello,

                          OS_TASKPRINORM, OS_TASKSTKNORM, 0, 1 );

    }

     

    I have used packet sender to send UDP packets from PC (10.100.1.94) to C6678 EVM board (10.100.1.17) and able to get the same packet to my PC (echoed back).

    I hope, that's what you need right ?

    I have used the following code from C6678 hello world example.

    int dtask_udp_hello( SOCKET s, UINT32 unused )
    {
        struct sockaddr_in sin1;
        struct timeval     to;
        int                i,tmp;
        char               *pBuf;
        HANDLE             hBuffer;
    
        printf("########### UDP HELLO EXE ########### \n");
    
        (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 );
    
            printf("UDP PACKET RECEIVED from port 5555 : %p\n",*pBuf);
    
            // 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);    
    }

    It is the same for C6670 hello world application too.

    Please let me know if any issues.

    I have send UDP packet from PC to board through "packetsender" and captured the packet in PC which I received from board.

  • Hi Taras,
    Also, if you would like me to do the same on C6670 EVM board with client example, surely I can do that for you and update.
  • Well i thank you very much, that really helps a lot. But that's not all what i need to do. I've created C++ application, which must send a string like "Hello Board" to the board. Board must recieve this, and spit the "Hello PC" String. In my case it look like even the infinte cycle of recv with "break" is not helping, i can't recieve this data. If i will fix and understand that, hope i'll can do sending to PC by myself.

    UPD: Program runs out of memory when i'm launching the C++ application. Problems with heap or something like that:

    [C66xx_0] ti.sysbios.heaps.HeapMem: line 294: out of memory: handle=0xc1f00b0, size=4096

  • Hi,

    I have added one more screen shot for your reference in previous post..

    I would like you to suggest to use the "packetsender" to send the packet and use the "wireshark" to capture and analyse (whats going on network) the packets over network.


    UPD: Program runs out of memory when i'm launching the C++ application. Problems with heap or something like that:
    [C66xx_0] ti.sysbios.heaps.HeapMem: line 294: out of memory: handle=0xc1f00b0, size=4096


    Try to increase the heap memory in *.cfg file.

    /*
    ** Create a Heap.
    */
    var HeapMem = xdc.useModule('ti.sysbios.heaps.HeapMem');
    var heapMemParams = new HeapMem.Params();
    heapMemParams.size = 0x300000;
    heapMemParams.sectionName = "systemHeap";
    Program.global.heap0 = HeapMem.create(heapMemParams);


    Try to use the packet sender and set the break point in function to ensure.
    Else, if you don't have emulator, put some console print.

    Note:
    Try to use "TCP" option too if its not working UDP option in "packet sender" app.

    Please let me know if any issues.
  • It's sad, but i can't increase the Heap size, because my programm is barely allocated with that configuration:

    Memory.defaultHeapInstance  =   Program.global.heap0;
    Program.sectMap["sharedL2"] = "MSMCSRAM"; 
    Program.sectMap["systemHeap"] = "MSMCSRAM";
    Program.sectMap[".sysmem"]  = "MSMCSRAM";
    Program.sectMap[".args"]    = "MSMCSRAM";
    Program.sectMap[".cio"]     = "MSMCSRAM";
    Program.sectMap[".far"] 	= 	"MSMCSRAM";
    Program.sectMap[".rodata"] 	= 	"MSMCSRAM";
    Program.sectMap[".neardata"]= 	"MSMCSRAM";
    Program.sectMap[".cppi"] 	= 	"L2SRAM";
    Program.sectMap[".init_array"] 	= 	"MSMCSRAM";
    Program.sectMap[".qmss"] 	= 	"L2SRAM";
    Program.sectMap[".cinit"] 	= 	"L2SRAM";
    Program.sectMap[".bss"]		=	"MSMCSRAM";
    Program.sectMap[".const"]	=	"MSMCSRAM";
    Program.sectMap[".text"]	=	"MSMCSRAM";
    Program.sectMap[".code"]	=	"MSMCSRAM";
    Program.sectMap[".switch"]	=	"MSMCSRAM";
    Program.sectMap[".data"]	=	"MSMCSRAM";
    Program.sectMap[".fardata"] = 	"MSMCSRAM";
    Program.sectMap[".args"] 	= 	"MSMCSRAM";
    Program.sectMap[".cio"] 	= 	"MSMCSRAM";
    Program.sectMap[".vecs"] 	= 	"MSMCSRAM";
    Program.sectMap["platform_lib"] 	= 	"L2SRAM";
    Program.sectMap[".DbgSection"]  = "L2SRAM";
    Program.sectMap[".far:NDK_PACKETMEM"] = {loadSegment: "MSMCSRAM", loadAlign: 128};
    Program.sectMap[".far:taskStackSection"] = "L2SRAM";
    Program.sectMap[".stack"]	=	"L2SRAM";
    Program.sectMap[".nimu_eth_ll2"] = "L2SRAM";
    Program.sectMap[".resmgr_memregion"] = {loadSegment: "L2SRAM", loadAlign:128};	/* QMSS descriptors region 	*/
    Program.sectMap[".resmgr_handles"] = {loadSegment: "L2SRAM", loadAlign:16};	/* CPPI/QMSS/PA Handles			*/
    Program.sectMap[".resmgr_pa"]	= {loadSegment: "L2SRAM", loadAlign:8};		/* PA Memory					*/
    Program.sectMap[".far:IMAGEDATA"] = {loadSegment: "L2SRAM", loadAlign: 8};
    Program.sectMap[".far:NDK_OBJMEM"] = {loadSegment: "L2SRAM", loadAlign: 8};
    

    If you still remember my DDR3 problems, you would understand this "crutch" :) Still, i will try to add another internal memory region, such as L1DSRAM or something. Please, can you provide links to examples of ad sizes of memory regions and the regions themselves.

  • UPD:

    [C66xx_0] ti.sysbios.heaps.HeapMem: line 294: out of memory: handle=0xc1f0080, size=4096
    [C66xx_0] xdc.runtime.Error.raise: terminating execution


    begins to appear, when i'm trying send packet with PacketSender, as you said. I've added the transmission task function

    /*
     * retrans.c
     *
     *  Created on: 11.08.2015
     *      Author: KolesTaras
     */
    
    #include <ti/ndk/inc/netmain.h>
    
    //
    // 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_transmit( SOCKET s, UINT32 unused )
    {
    	SOCKET sUDP;
        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( sUDP, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
        setsockopt( sUDP, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );
    
        for(;;)
        {
            tmp = sizeof( sin1 );
            i = (int)recvncfrom( sUDP, (void **)&pBuf, 0, (PSA)&sin1, &tmp, &hBuffer );
    
            // Spit any data back out
           /* if( i >= 0 )
            {
                sendto( sUDP, "Hello PC!", 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);
    }
    

    and declared it as follows:

    static void NetworkOpen()
    {
        // Create our local servers
        hEcho = DaemonNew( SOCK_STREAMNC, 0, 7, dtask_tcp_echo,
                           OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
        hEchoUdp = DaemonNew( SOCK_DGRAM, 0, 7, dtask_udp_echo,
                              OS_TASKPRINORM, OS_TASKSTKNORM, 0, 1 );
        hData = DaemonNew( SOCK_STREAM, 0, 1000, dtask_tcp_datasrv,
                           OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
        hNull = DaemonNew( SOCK_STREAMNC, 0, 1001, dtask_tcp_nullsrv,
                           OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
        hOob  = DaemonNew( SOCK_STREAMNC, 0, 999, dtask_tcp_oobsrv,
                           OS_TASKPRINORM, OS_TASKSTKNORM, 0, 3 );
        hRetr = DaemonNew(SOCK_DGRAM, 0, 5555, dtask_udp_transmit,
                OS_TASKPRINORM, OS_TASKSTKNORM, 0, 1 );
    
    /* ....*/
    }


    the Full picture of an issue:

    Also, can you please link me your *.cfg file memory map allocation?

  • Hi,
    I'm not sure why you are getting running out of memory ?
    Just you have only client NDK example alone right ?
    Or is there any extra stuff you added into that example ?
    Send me your complete project if you have difference.

    I will also try to reproduce the problem on C6670 EVM board.
  • https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/791/client.7zOk, i will gladly send you my project.

  • Hi Taras,
    Thank you!
    I will test it and update you on tomorrow.
    Thanks for your patience.
  • Good day to you. Do you have any news or just any thoughts about my project?
  • Hi Taras,
    Sorry for the delayed response on this.
    I'm not able to find source files (*.c,*.cfg etc.,) in the attached project.
    Can you please attach it with complete project.

  • This should be my project tree, which is contained in the archive, after import. I'm re-sending archive now.client.zip

    Can i hope to receive news on Monday?

  • Hi Taras,
    Thanks.
    Now I'm able to see your memory insufficient issue.
    You have added lot of stuff (platform LED code, testing etc.,) in that code which consume much memory, I will look into it and get back to you.

  • Hello again.

    Well, i've really added a lot of stuff, but in the final stage, i will need to add the whole calculation program in the project, so it's critical to me to know if I can work within the framework of internal memory or will have to finish boot DDR memory. And i'm afraid that this will be a nessesary step, but now i would be satisfied with properly internal configuration.

    UPD: Still working to make the DDR loader to initialize. Waiting for your news.

  • Hi,
    Yes I'm able to reproduce your memory issue, its due to stack overflow.
    This "dtask_udp_transmit" function executing continuously if received single UDP packet, due to that it lead to stack overflow.
    You can put breakpoint in that function or put some printf to check.
    I'm checking why the UDP function get called even didn't send any UDP packet (just for single UDP packet event) from PC.
  • Hi Taras,

    Now, I'm able to send and receive the UDP packets with your client NDK project example code without any issues.

    The problem is due to your "dtask_udp_transmit" in "retrans.c" file.

    I think, your requirement is need to send UDP packet from PC (Message: Hello DSP) and DSP should respond to DSP with UDP packet (Message : Hello PC)

    I have modified the code like that and able to send/receive the UD packet without any stack overflow or memory issue.

    Try the code in "retrans.c" file and let me know if any issues.

    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>
    
    //
    // 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_transmit( SOCKET s, UINT32 unused )
    {
        struct sockaddr_in sin1;
        struct timeval     to;
        int                i,tmp;
        char               *pBuf;
        char               *dspBuf = "Hello PC"; //Titus
        HANDLE             hBuffer;
    
        printf("UDP packet received\n");
    
        (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 );
    //Receive the message from PC "Hello DSP"
            i = (int)recvncfrom( s, (void **)&pBuf, 0, (PSA)&sin1, &tmp, &hBuffer );
    
            // Spit any data back out
            if( i >= 0 )
            {
    //Titus
    //Respond to PC with message "Hello PC"
            	sendto(s, dspBuf, strlen(dspBuf)+1, 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);
    }
    
    
    

  • Hello Titus.

    Your code helped! Thank you very much, i've defeated this simple project. I will still ask further  questions about DDR init in other themes, but this thing is finished

  • Hi,
    Are you switch OFF the board for every load ?
    Can you attach the complete log.
    I will attach the complete working project.
  • Yes, i was switching it off, doing the full reset, etc. Everything is worked, but one tiny thing appeared - when i'm receiving the data, it appears like

    What should i do, if i want to print the whole data message, instead of only first letter? 

    And one more thing? Are there the specific memory locations for ethernet buffer, or they are created dynamically? Can i allocate the specific one  to watch it?

    UPD:
    the whole log 

    [C66xx_0] QMSS successfully initialized
    [C66xx_0] CPPI successfully initialized
    [C66xx_0] PA successfully initialized
    [C66xx_0]
    [C66xx_0] TCP/IP Stack Example Client
    [C66xx_0] demo.net
    [C66xx_0] tidspdemo.net
    [C66xx_0] Configuring DHCP client
    [C66xx_0] PASS successfully initialized
    [C66xx_0] Ethernet subsystem successfully initialized
    [C66xx_0] Ethernet eventId : 48 and vectId (Interrupt) : 7
    [C66xx_0] Verify_Init: Expected 0 entry count for Queue number = 901, found 12 entries
    [C66xx_0] Verify_Init: Expected 0 entry count for Queue number = 902, found 8 entries
    [C66xx_0] Registration of the EMAC Successful, waiting for link up ..
    [C66xx_0] Service Status: DHCPC : Enabled : : 000
    [C66xx_0] Service Status: Telnet : Enabled : : 000
    [C66xx_0] Service Status: HTTP : Enabled : : 000
    [C66xx_0] Service Status: DHCPC : Enabled : Running : 000
    [C66xx_0] Network Added: If-1:192.168.1.200
    [C66xx_0] Service Status: DHCPC : Enabled : Running : 017
    [C66xx_0] UDP packet received
    [C66xx_0] Hello DSP
    [C66xx_0] Hello DSP
    [C66xx_0] UDP packet received

  • Hi,

    Now also I tested your modified code and didn't see any issues.

    Could you please test this and let me know.

    Delete your imported project from CCS workspace and import the attached project.

    I attached here your modified project.

    8551.client.zip

  • Hello Titus.

    This project is working correctly too. I've tested this, didn't find issues.

  • Hi Taras,
    Now, your problem got solved ?
  • Hello Titus.

    Yes, for this time, problem is solved completely. There are still more, but this one is finished.
  • :-) okay, thanks for your update.
    Please create a new post for the problem if any.