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.

AM572x RTOS Ethernet communication example

Other Parts Discussed in Thread: SYSBIOS

I am using GP evmAM572x. I want to send some data on ethernet to host PC at 1Gbps. Please tell me the flow of sending data and which file i need to change or modify. Can I use EMAC_BasicExample_evmAM572x_armBiosExampleProject at C:\ti\pdk_am57xx_1_0_3\packages\MyExampleProjects.
How do I change or set the ip Address of source and destination? I am new to this kind of SW architecture. Please help me out to establish the communication between target ethernet port to PC.


Thanks,
Anjana Pathak

  • The RTOS team have been notified. They will respond here.
  • I am waiting for answer.....
    I am using processor_sdk_rtos_am57xx_3_00_00_04, CCS6.1.3.00034_win32. and loading program using SD card.
    My system configuration is windows 7 64 bit.

    Anjana Pathak
  • Hi Anjana,

    Yes, you can develop your network application based on EMAC_BasicExample_evmAM572x_armBiosExampleProject. Developing a network application with the NDK software is similar to program with a standard sockets API, please refer to the chapter 3 "Network Application Development" in the TI Network Developer's Kit (NDK) v2.24 User's Guide spru523i.pdf (ndk_2_24_03_35\docs). This chapter describes how to begin developing network applications. It discusses the issues and guidelines involved in the development of network applications using the NDK libraries. Section 3.4 provides an Example Code. For the EMAC_BasicExample_evmAM572x_armBiosExampleProject, the source IP address is defined in nimu_evm.cfg,

    if (enableStaticIP)
    {
        /* Settings for static IP configuration */
        Ip.ResolveIP = false;
        Ip.CallByIP = false;
        Ip.autoIp = false;
        Ip.address = "192.168.1.4";
        Ip.mask = "255.255.255.0";
        Ip.gatewayIpAddr = "192.168.1.1";
    }

    The destination IP address you specify will need fill in structure sockaddr, and then used by
         ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *to,
         socklen_t tolen);
    in the case you send data from EVM to PC, or vice versa,
         ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *from,
         socklen_t *fromlen);

    Regards,
    Garrett

  • Thanks Garett,

    but the config file used in EMAC_BasicExample_evmAM572x_armBiosExampleProject is evm_AM572x.cfg and for example project NIMU_BasicExample_evmAM572x_armExampleproject config file used is nimu_evm.cfg In evm_AM572x.cfg no IP address is defined and not able to trace where the IP address is set. In which file the below functions and structure sockaddr is defined?

     ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *to,
         socklen_t tolen); 

    ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *from,
         socklen_t *fromlen);

    Regards,

    Anjana Pathak

  • Anjana,

    uh, I meant the NIMU_BasicExample_evmAM572x_armExampleproject as your project base. The sendto and recvfrom are standard BSD socket layer API from NDK, see chapter 3.4.3 of TI Network Developer's Kit (NDK) v2.24 API Reference Guide, SPRU524I.

    Regards,
    Garrett
  • Hi Garrett,
    I added the following lines in TaskFxn() in NIMU_BasicExample_evmAM572x_armExampleproject to send a string on UDP port, but it didnt work. i got the result as -1

    int yes1=1;
    int i,bind_tmp;

    struct sockaddr_in sin1;
    SOCKET s1;
    char *pBuf={"Test application\r\n"};

    s1=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

    sin1.sin_addr.s_addr = inet_addr(LocalIPAddr1);
    sin1.sin_port = htons(0);
    sin1.sin_family = AF_INET;
    bind_tmp=bind(s1, (PSA)&sin1, sizeof(sin1));
    NIMU_log("Bind result= %d\n",bind_tmp);
    bind_tmp=setsockopt(s1, SOL_SOCKET, SO_BROADCAST, &yes1, sizeof(int) );
    NIMU_log("Set socket opt result= %d\n",bind_tmp);
    sin1.sin_addr.s_addr = htonl(-1);
    sin1.sin_port = htons(11000);
    sin1.sin_family = AF_INET;

    // si_other1.sin_addr.s_addr = htonl(-1); /*send message to 255.255.255.255 */
    // si_other1.sin_family = PF_INET;
    // si_other1.sin_port = htons(baud); /*port number */

    for(i=0;i<10;i++)
    {
    bind_tmp=send( s1, pBuf, sizeof(pBuf), 0 );
    NIMU_log("send result= %d\n",bind_tmp);
    app_delay(10000);
    /*tmp = sizeof( sin1 );
    i = (int)recvncfrom( s1, (void **)&pBuf, 0, (PSA)&sin1, &tmp, &hBuffer );

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

    Result
    Bind result= -1
    Set socket opt result= -1
    send result= -1
    Please suggest where i am wrong.

    Thanks,
    Anjana Pathak
  • Anjana,

    Please refer to section 3.5.1 Troubleshooting Common Problems, in "TI Network Developer's Kit (NDK) v2.24 User's Guide", spru523i.

    All socket calls return “error” (-1)
    • Make sure there is a call to fdOpenSession() in the Task before it uses sockets, and a call to
    fdCloseSession() when the Task terminates

    Regards, Garrett

  • Thanks Garrett,

    I did the changes in NIMU example to send data after refering NDK user guide spru523i. But not able to send data. Attaching the code of modified NIMU_BasicExample_evmAM572x_armExampleproject. Configuring NDK with XGCONF. Please suggest where i am going wrong.

    Task_Handle main_task;

    static int nimu_device_index = 0U;


    NIMU_DEVICE_TABLE_ENTRY NIMUDeviceTable[MAX_TABLE_ENTRIES];

    void TaskFxn(UArg a0, UArg a1);

    extern int CpswEmacInit (STKEVENT_Handle hEvent);
    //tagged by anjana
    void app_delay(uint32_t delayValue);
    void SendDataToPC();

    struct sockaddr_in sin1;
    //---------------------------------------------------------------------------
    // Configuration
    //
    //char *HostName1 = "tidsp";
    char *LocalIPAddr1 = "192.168.1.2";
    char *IPAddr = "192.168.1.100";
    //char *LocalIPMask1 = "255.255.255.0"; // Not used when using DHCP
    //char *GatewayIP1 = "192.168.1.1"; // Not used when using DHCP
    //char *DomainName1 = "demo.net"; // Not used when using DHCP
    //char *DNSServer1 = "0.0.0.0"; // Used when set to anything but zero


    /* ========================================================================== */
    /* Function Definitions */
    /* ========================================================================== */

    /**
    * \brief This function returns the MAC address for the EVM
    *
    * \param addrIdx the MAC address index.
    * \param macAddr the Pointer where the MAC address shall be stored
    * 'addrIdx' can be either 0 or 1
    *
    * \return None.
    */
    /*void EVMMACAddrGet(uint32_t addrIdx, uint8_t *macAddr)
    {
    macAddr[0U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_0
    >> 16U) & 0xFFU;
    macAddr[1U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_0
    >> 8U) & 0xFFU;
    macAddr[2U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_0)
    & 0xFF;
    macAddr[3U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_1
    >> 16U) & 0xFFU;
    macAddr[4U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_1
    >> 8U) & 0xFFU;
    macAddr[5U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_1)
    & 0xFFU;
    }commented by anjana*/

    int32_t EVMMACAddrGet(uint32_t addrIdx, uint8_t *macAddr)
    {
    int32_t retVal = 0;
    switch(addrIdx)
    {
    case 1U:
    macAddr[0U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_1
    >> 16U) & 0xFFU;
    macAddr[1U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_1
    >> 8U) & 0xFFU;
    macAddr[2U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_1)
    & 0xFFU;
    macAddr[3U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_0
    >> 16U) & 0xFFU;
    macAddr[4U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_0
    >> 8U) & 0xFFU;
    macAddr[5U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_0)
    & 0xFF;
    break;

    case 2U:
    macAddr[0U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_3
    >> 16U) & 0xFFU;
    macAddr[1U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_3
    >> 8U) & 0xFFU;
    macAddr[2U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_3)
    & 0xFFU;
    macAddr[3U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_2
    >> 16U) & 0xFFU;
    macAddr[4U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_2
    >> 8U) & 0xFFU;
    macAddr[5U] = (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_2)
    & 0xFF;
    break;

    default:
    retVal = -1;
    break;
    }
    return retVal;
    }

    /**
    * \name main
    * \brief Main Function
    * \param none
    * \return none
    *
    */
    int main()
    {
    /* Call board init functions */
    Board_initCfg boardCfg;
    Task_Params taskParams;
    EMAC_HwAttrs_V4 cfg;

    boardCfg = BOARD_INIT_PINMUX_CONFIG |
    BOARD_INIT_MODULE_CLOCK | BOARD_INIT_UART_STDIO;
    Board_init(boardCfg);

    CSL_xbarMpuIrqConfigure(CSL_XBAR_INST_MPU_IRQ_92, CSL_XBAR_GMAC_SW_IRQ_RX_PULSE);
    CSL_xbarMpuIrqConfigure(CSL_XBAR_INST_MPU_IRQ_93, CSL_XBAR_GMAC_SW_IRQ_TX_PULSE);

    /* Select RGMII 2 ports GMIIx_SEL = 2 for RGMII*/
    CSL_FINS (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->CONTROL_IO_1,
    CONTROL_CORE_CONTROL_IO_1_GMII1_SEL, 2U);
    CSL_FINS (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->CONTROL_IO_1,
    CONTROL_CORE_CONTROL_IO_1_GMII2_SEL, 2U);

    /*GMAC RESET ISOLATION Enable*/
    CSL_FINS (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->CONTROL_IO_2,
    CONTROL_CORE_CONTROL_IO_2_GMAC_RESET_ISOLATION_ENABLE, 0U);
    CSL_FINS (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->CONTROL_IO_2,
    CONTROL_CORE_CONTROL_IO_2_GMAC_RESET_ISOLATION_ENABLE, 1U);


    EMAC_socGetInitCfg(0, &cfg);
    cfg.port[0].phy_addr = EMAC_CPSW_PORT0_PHY_ADDR_EVM;
    cfg.port[1].phy_addr = EMAC_CPSW_PORT1_PHY_ADDR_EVM;
    EMAC_socSetInitCfg(0, &cfg);

    Task_Params_init(&taskParams);
    taskParams.priority = 1;
    taskParams.stackSize = 0x1400;
    main_task = Task_create (TaskFxn, &taskParams, NULL);
    //Tagged by anjana
    Task_Params_init(&taskParams);
    taskParams.priority = 2;
    taskParams.stackSize = 0x1400;
    main_task = Task_create (SendDataToPC, &taskParams, NULL);

    NIMUDeviceTable[nimu_device_index++].init = &CpswEmacInit ;
    NIMUDeviceTable[nimu_device_index].init = NULL ;

    /* Task_Params_init(&taskParams);
    taskParams.priority = 1;
    taskParams.stackSize = 0x1400;
    main_task = Task_create (TaskFxn, &taskParams, NULL);*/

    BIOS_start();

    return -1;
    }

    /**
    * \name TaskFxn
    * \brief Task which do EIP initialization
    * \param a0
    * \param a1
    * \return none
    *
    */
    void TaskFxn(UArg a0, UArg a1)
    {
    NIMU_log("\n\rSYS/BIOS Ethernet/IP (CPSW) Sample application\n\r");
    //SendDataToPC();
    }
    //tagged by anjana
    void SendDataToPC()
    {
    SOCKET s = INVALID_SOCKET;
    struct sockaddr_in sin1;
    // struct sockaddr_in sin_bind1;
    int I,test=125;
    char *pBuf = 0;
    struct timeval timeout;
    // Allocate the file descriptor environment for this Task
    fdOpenSession( (HANDLE)Task_self() );
    NIMU_log("\n== Start TCP Echo Client Test ==\n");
    //NIMU_log("\n== Start UDP Echo Client Test ==\n");
    // Create test socket
    //s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if( s == INVALID_SOCKET )
    {
    NIMU_log("failed socket create (%d)\n",fdError());
    goto leave;
    }
    // Prepare address for connect
    bzero( &sin1, sizeof(struct sockaddr_in) );
    sin1.sin_family = AF_INET;
    sin1.sin_addr.s_addr = inet_addr(IPAddr);//inet_addr(SERVER_IP);//htonl(-1);
    sin1.sin_port = htons(7);

    /*bzero( &sin_bind1, sizeof(struct sockaddr_in) );
    sin_bind1.sin_family = AF_INET;
    sin_bind1.sin_addr.s_addr = inet_addr(LocalIPAddr1);//IPAddr;
    sin_bind1.sin_port = htons(1025);//htons(7);

    if( bind( s, (PSA) &sin_bind1, sizeof(sin_bind1) ) < 0 )
    {
    NIMU_log("failed bind (%d)\n",fdError());
    goto leave;
    }
    else
    {NIMU_log("bind succesful\n");}*/

    // Configure our Tx and Rx timeout to be 5 seconds
    timeout.tv_sec = 5;
    timeout.tv_usec = 0;

    if(setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof( timeout ) ) < 0 )
    {
    NIMU_log("failed Socket opt(%d)\n",fdError());
    goto leave;
    }
    else
    {NIMU_log("Socket opt succesful\n");}

    setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof( timeout ) );
    // Connect socket
    if( connect( s, (PSA) &sin1, sizeof(sin1) ) < 0 )
    {
    NIMU_log("failed connect (%d)\n",fdError());
    goto leave;
    }
    // Allocate a working buffer
    if( !(pBuf = malloc( 125 )) )
    {
    NIMU_log("failed temp buffer allocation\n");
    goto leave;
    }
    // Fill buffer with a test pattern
    for(I=0; I<125; I++)
    *(pBuf+I) = (char)I;
    // Send the buffer
    /* sin1.sin_family = AF_INET;
    sin1.sin_addr.s_addr = inet_addr(SERVER_IP);//htonl(-1);
    sin1.sin_port = htons(7);
    app_delay(10000000);*/


    /*ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *to,
    socklen_t tolen);*/
    //if(sendto(s, pBuf, 125, 0, (PSA)&sin1,sizeof(sin1)) < 0);
    if( send( s, pBuf, 125, 0 ) < 0 )
    {
    NIMU_log("send failed (%d)\n",fdError());
    goto leave;
    }
    /* for(I=0;I<10;I++)
    {
    //test=send( s, pBuf, sizeof(pBuf), 0 );
    test=sendto(s, pBuf, 125, 0, (PSA)&sin1,sizeof(sin1));
    NIMU_log("send result= %d\n",test);
    NIMU_log("send failed (%d)\n",fdError());
    app_delay(10000000);
    }*/
    // Try and receive the test pattern back
    /*I = recv( s, pBuf, 125, MSG_WAITALL );
    if( I < 0 )
    {
    NIMU_log("recv failed (%d)\n",fdError());
    goto leave;
    }
    // Verify reception size and pattern
    if( I != test )
    {
    NIMU_log("received %d (not %d) bytes\n",I, test);
    goto leave;
    }
    for(I=0; I<test; I++)
    if( *(pBuf+I) != (char)I )
    {
    NIMU_log("verify failed at byte %d\n",I);
    break;
    }
    // If here, the test passed
    if( I==test )
    NIMU_log("passed\n");*/
    leave:
    if( pBuf )
    free( pBuf );
    if( s != INVALID_SOCKET )
    fdClose( s );
    //NIMU_log("== End UDP Echo Client Test ==\n\n");
    NIMU_log("== End TCP Echo Client Test ==\n\n");
    // Free the file descriptor environment for this Task
    fdCloseSession( (HANDLE)Task_self() );
    Task_exit();
    }

  • any updates...............I am stuck..........

  • In above attach code i am not able to send data using TCPIP protocol to PC
    The snapshot of my config nimu_evm.cfg file, do i need to do some changes in this file for TCPIP communication.
    /* ================ General configuration ================ */
    var enableStaticIP = 1;

    /* use modules */
    var Defaults = xdc.useModule('xdc.runtime.Defaults');
    var Diags = xdc.useModule('xdc.runtime.Diags');
    var Error = xdc.useModule('xdc.runtime.Error');
    var Log = xdc.useModule('xdc.runtime.Log');
    var LoggerBuf = xdc.useModule('xdc.runtime.LoggerBuf');
    var Main = xdc.useModule('xdc.runtime.Main');
    var System = xdc.useModule('xdc.runtime.System');
    var Text = xdc.useModule('xdc.runtime.Text');
    var IntXbar = xdc.useModule('ti.sysbios.family.shared.vayu.IntXbar');
    var Clock = xdc.useModule('ti.sysbios.knl.Clock');
    var Timer = xdc.useModule('ti.sysbios.timers.dmtimer.Timer');
    var Swi = xdc.useModule('ti.sysbios.knl.Swi');
    var Task = xdc.useModule('ti.sysbios.knl.Task');
    var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
    var ti_sysbios_hal_Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
    var SysMin = xdc.useModule('xdc.runtime.SysMin');
    var SemiHostSupport = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');

    /* NDK modules */
    var Global = xdc.useModule('ti.ndk.config.Global');
    var Ip = xdc.useModule('ti.ndk.config.Ip');
    var Udp = xdc.useModule('ti.ndk.config.Udp');
    var Telnet = xdc.useModule('ti.ndk.config.Telnet');
    var Tcp = xdc.useModule('ti.ndk.config.Tcp');

    /*
    * Program.argSize sets the size of the .args section.
    * The examples don't use command line args so argSize is set to 0.
    */
    /* Program.argSize = 0x0; */
    /* System stack size (used by ISRs and Swis) */
    Program.stack = 0x10000;

    /*
    * Uncomment this line to globally disable Asserts.
    * All modules inherit the default from the 'Defaults' module. You
    * can override these defaults on a per-module basis using Module.common$.
    * Disabling Asserts will save code space and improve runtime performance.
    Defaults.common$.diags_ASSERT = Diags.ALWAYS_OFF;
    */

    /*
    * Uncomment this line to keep module names from being loaded on the target.
    * The module name strings are placed in the .const section. Setting this
    * parameter to false will save space in the .const section. Error and
    * Assert messages will contain an "unknown module" prefix instead
    * of the actual module name.
    Defaults.common$.namedModule = false;
    */

    /*
    * Minimize exit handler array in System. The System module includes
    * an array of functions that are registered with System_atexit() to be
    * called by System_exit().
    */
    System.maxAtexitHandlers = 4;

    /*
    * Uncomment this line to disable the Error print function.
    * We lose error information when this is disabled since the errors are
    * not printed. Disabling the raiseHook will save some code space if
    * your app is not using System_printf() since the Error_print() function
    * calls System_printf().
    Error.raiseHook = null;
    */

    /*
    * Uncomment this line to keep Error, Assert, and Log strings from being
    * loaded on the target. These strings are placed in the .const section.
    * Setting this parameter to false will save space in the .const section.
    * Error, Assert and Log message will print raw ids and args instead of
    * a formatted message.
    Text.isLoaded = false;
    */

    /*
    * Uncomment this line to disable the output of characters by SysMin
    * when the program exits. SysMin writes characters to a circular buffer.
    * This buffer can be viewed using the SysMin Output view in ROV.
    SysMin.flushAtExit = false;
    */

    System.SupportProxy = SysMin;
    /* Circular buffer size for System_printf() */
    SysMin.bufSize = 0x200;


    /* ================ BIOS configuration ================ */

    var BIOS = xdc.useModule('ti.sysbios.BIOS');
    /*
    * Build a custom SYS/BIOS library from sources.
    */
    BIOS.libType = BIOS.LibType_Custom;


    /*
    * The BIOS module will create the default heap for the system.
    * Specify the size of this default heap.
    */
    BIOS.heapSize = 0xA0000;

    /*
    * Create and install logger for the whole system
    */
    var loggerBufParams = new LoggerBuf.Params();
    loggerBufParams.numEntries = 16;
    var logger0 = LoggerBuf.create(loggerBufParams);
    Defaults.common$.logger = logger0;
    Main.common$.diags_INFO = Diags.ALWAYS_ON;


    if (enableStaticIP)
    {
    /* Settings for static IP configuration */
    Ip.ResolveIP = false;
    Ip.CallByIP = false;
    Ip.autoIp = false;
    Ip.address = "192.168.1.2";
    Ip.mask = "255.255.255.0";
    Ip.gatewayIpAddr = "192.168.1.1";
    }
    else
    {
    Ip.dhcpClientMode = Ip.CIS_FLG_IFIDXVALID;
    }

    Global.ndkTickPeriod = 100;
    Global.kernTaskPriLevel = 11;
    Global.serviceReportHook = null;
    Global.IPv6 = false;

    Task.defaultStackSize = 4096;
    Task.idleTaskStackSize = 4096;

    /* ================ Driver configuration ================ */

    var deviceType = "am572x";
    var socType = "am572x";

    var Csl = xdc.loadPackage('ti.csl');
    Csl.Settings.deviceType = deviceType;
    /* Load the OSAL package */
    var osType = "tirtos"
    var Osal = xdc.useModule('ti.osal.Settings');
    Osal.osType = osType;

    /* Load the Board package and set the board name */
    var Board = xdc.loadPackage('ti.board');
    Board.Settings.boardName = "evmAM572x";

    /* Load the EMAC packages */
    var Emac = xdc.loadPackage('ti.drv.emac');
    Emac.Settings.socType = socType;
    /* Load the UART package */
    var UART = xdc.loadPackage('ti.drv.uart');

    /* Load the I2C package */
    var I2C = xdc.loadPackage('ti.drv.i2c');


    var Nimu = xdc.loadPackage('ti.transport.ndk.nimu');
    Nimu.Settings.socType = socType;


    /* ================ Cache and MMU configuration ================ */

    var Cache1 = xdc.useModule('ti.sysbios.family.arm.a15.Cache');
    Cache1.enableCache = true;

    /***********************************************
    * MMU Configuration *
    ***********************************************/
    var Mmu = xdc.useModule('ti.sysbios.family.arm.a15.Mmu');
    Mmu.enableMMU = true;

    /******************************************************************************
    *
    * SYS/BIOS assigns the following defaults to MAIR0 ATTR0, ATTR1 and ATTR2:
    *
    * ATTR0 -> 0x44 (mark memory region as non-cacheable normal memory)
    * ATTR1 -> 0x04 (mark memory region as device memory, i.e. strongly
    * ordered and non-cacheable)
    * ATTR2 -> 0xFF (mark memory region as normal memory, RW cacheable and
    * RW allocate)
    ******************************************************************************
    */


    // descriptor attribute structure
    var attrs0 = new Mmu.DescriptorAttrs();

    Mmu.initDescAttrsMeta(attrs0);
    attrs0.type = Mmu.DescriptorType_BLOCK; // BLOCK descriptor
    attrs0.shareable = 2; // sharerable
    attrs0.attrIndx = 1; // Non-cache, device memory

    // Set the descriptor for each entry in the address range
    for (var i=0x40000000; i < 0x60000000; i = i + 0x00200000) {
    // Each 'BLOCK' descriptor entry spans a 2MB address range
    Mmu.setSecondLevelDescMeta(i, i, attrs0);
    }

    // descriptor attribute structure
    var attrs1 = new Mmu.DescriptorAttrs();

    Mmu.initDescAttrsMeta(attrs1);
    attrs1.type = Mmu.DescriptorType_BLOCK; // BLOCK descriptor
    attrs1.shareable = 2; // sharerable
    attrs1.attrIndx = 2; // Cached, normal memory

    // Set the descriptor for each entry in the address range
    for (var i=0x80000000; i < 0xA0000000; i = i + 0x00200000) {
    // Each 'BLOCK' descriptor entry spans a 2MB address range
    Mmu.setSecondLevelDescMeta(i, i, attrs1);
    }

    /* ================ Memory sections configuration ================ */
    Program.sectMap["BOARD_IO_DELAY_DATA"] = "OCMC_RAM1";
    Program.sectMap["BOARD_IO_DELAY_CODE"] = "OCMC_RAM1";
    Ip.enableFiltering = false;
    Ip.enableForwarding = false;
    Ip.enableDirectedBroadcast = true;
  • Anjana,

    You can try to add the following in .cfg to get optimal throughput, but you may need to look into wireshark capture to see what is happening on the port first.

    Global.pktNumFrameBufs = 384;
    Tcp.transmitBufSize = 8192;
    Tcp.receiveBufSize = 65536;
    Tcp.receiveBufLimit = 65536;

    Regards, Garrett
  • Please reply.........................waiting for suggestion.

    or shall i open a new post for this

  • ok i will try..
  • Did the changes as suggested. also attached the wireshark capture return value of send is 4: EINTR           4       // Interrupted system call

     I get the following console output:

    [CortexA15_0] Using MAC Address: 5c-f8-21-0f-9c-a8
    Using MAC Address: 5c-f8-21-0f-9c-a8
    Network Added: If-1:192.168.1.2

  • I am not able to receive data from evmAm572x on TCPIP to PC(application used is telnet to receive data). I did the changes as you mentioned.

    I am getting response as of  send(.............) as 4  // Interrupted system call.

    1. Please suggest if i need to do any other changes in file(nimu_cfg/other network open or configuration file)

    2.Which tool shall i use to test the TCPIP communication?

    Attaching my code also

    
    /* ========================================================================== */
    /*                             Include Files                                  */
    /* ========================================================================== */
    
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <xdc/std.h>
    #include <xdc/runtime/Error.h>
    #include <xdc/runtime/System.h>
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    
    #include <ti/ndk/inc/stkmain.h>
    //tagged by anjana
    #include <ti/ndk/inc/netmain.h>
    
    #include <ti/drv/emac/emac_drv.h>
    #include <ti/drv/emac/src/v4/emac_drv_v4.h>
    
    #include <ti/csl/soc.h>
    #include <ti/csl/cslr_device.h>
    
    #include <ti/board/board.h>
    
    /* TI-RTOS Header files */
    #include <ti/drv/i2c/I2C.h>
    #include <ti/drv/i2c/soc/I2C_v1.h>
    /* UART Header files */
    #include <ti/drv/uart/UART.h>
    #include <ti/drv/uart/UART_stdio.h>
    #include <ti/csl/soc/am572x/src/csl_device_xbar.h>
    
    /* Enable the below macro to have prints on the IO Console */
    //#define IO_CONSOLE
    
    #ifndef IO_CONSOLE
    #define NIMU_log                UART_printf
    #else
    #define NIMU_log                printf
    #endif
    
    /* ========================================================================== */
    /*                             Macros                                  */
    /* ========================================================================== */
    
    /**Phy address of  port 0 */
    #define EMAC_CPSW_PORT0_PHY_ADDR_EVM     1
    /**Phy address of port 1 */
    #define EMAC_CPSW_PORT1_PHY_ADDR_EVM     2
    
    
    #define MAX_TABLE_ENTRIES   3
    
    /* ========================================================================== */
    /*                            Global Variables                                */
    /* ========================================================================== */
    
    /**Task handle for EIP*/
    Task_Handle main_task;
    
    static int nimu_device_index = 0U;
    
    
    NIMU_DEVICE_TABLE_ENTRY NIMUDeviceTable[MAX_TABLE_ENTRIES];
    
    void TaskFxn(UArg a0, UArg a1);
    
    extern int CpswEmacInit (STKEVENT_Handle hEvent);
    //tagged by anjana
    void app_delay(uint32_t delayValue);
    void SendDataToPC();
    
    struct sockaddr_in sin1;
    //---------------------------------------------------------------------------
    // Configuration
    //
    //char *HostName1    = "tidsp";
    char *IPAddr = "192.168.0.144";
    //char *IPAddr = "255.255.255.255";
    
    //char *LocalIPMask1 = "255.255.255.0";    // Not used when using DHCP
    //char *GatewayIP1  = "192.168.1.1";    // Not used when using DHCP
    //char *DomainName1  = "demo.net";         // Not used when using DHCP
    //char *DNSServer1   = "0.0.0.0";          // Used when set to anything but zero
    
    
    /* ========================================================================== */
    /*                          Function Definitions                              */
    /* ========================================================================== */
    
    /**
     * \brief   This function returns the MAC address for the EVM
     *
     * \param   addrIdx    the MAC address index.
     * \param   macAddr    the Pointer where the MAC address shall be stored
     *     'addrIdx' can be either 0 or 1
     *
     * \return  None.
     */
    
    
    int32_t EVMMACAddrGet(uint32_t addrIdx, uint8_t *macAddr)
    {
        int32_t retVal = 0;
        switch(addrIdx)
        {
            case 1U:
                macAddr[0U] =  (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_1
                          >> 16U) & 0xFFU;
                macAddr[1U] =  (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_1
                          >> 8U) & 0xFFU;
                macAddr[2U] =  (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_1)
                          & 0xFFU;
                macAddr[3U] =  (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_0
                          >> 16U) & 0xFFU;
                macAddr[4U] =  (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_0
                          >> 8U) & 0xFFU;
                macAddr[5U] =  (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_0)
                          & 0xFF;
            break;
    
            case 2U:
                macAddr[0U] =  (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_3
                          >> 16U) & 0xFFU;
                macAddr[1U] =  (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_3
                          >> 8U) & 0xFFU;
                macAddr[2U] =  (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_3)
                          & 0xFFU;
                macAddr[3U] =  (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_2
                          >> 16U) & 0xFFU;
                macAddr[4U] =  (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_2
                          >> 8U) & 0xFFU;
                macAddr[5U] =  (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->MAC_ID_SW_2)
                          & 0xFF;
                break;
    
            default:
                retVal = -1;
                break;
        }
        return retVal;
    }
    
    
    
    /**
     *  \name main
     *  \brief Main Function
     *  \param none
     *  \return none
     *
     */
    int main()
    {
        /* Call board init functions */
        Board_initCfg boardCfg;
        Task_Params taskParams;
        EMAC_HwAttrs_V4 cfg;
    
        boardCfg =  BOARD_INIT_PINMUX_CONFIG |
            BOARD_INIT_MODULE_CLOCK | BOARD_INIT_UART_STDIO;
        Board_init(boardCfg);
    
        CSL_xbarMpuIrqConfigure(CSL_XBAR_INST_MPU_IRQ_92, CSL_XBAR_GMAC_SW_IRQ_RX_PULSE);
        CSL_xbarMpuIrqConfigure(CSL_XBAR_INST_MPU_IRQ_93, CSL_XBAR_GMAC_SW_IRQ_TX_PULSE);
    
        /* Select RGMII 2 ports GMIIx_SEL = 2 for RGMII*/
       CSL_FINS (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->CONTROL_IO_1,
              CONTROL_CORE_CONTROL_IO_1_GMII1_SEL, 2U);
        CSL_FINS (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->CONTROL_IO_1,
              CONTROL_CORE_CONTROL_IO_1_GMII2_SEL, 2U);
    
        /*GMAC RESET ISOLATION Enable*/
        CSL_FINS (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->CONTROL_IO_2,
              CONTROL_CORE_CONTROL_IO_2_GMAC_RESET_ISOLATION_ENABLE, 0U);
        CSL_FINS (((CSL_control_coreRegs *) CSL_MPU_CTRL_MODULE_CORE_CORE_REGISTERS_REGS)->CONTROL_IO_2,
              CONTROL_CORE_CONTROL_IO_2_GMAC_RESET_ISOLATION_ENABLE, 1U);
    
    
        EMAC_socGetInitCfg(0, &cfg);
        cfg.port[0].phy_addr = EMAC_CPSW_PORT0_PHY_ADDR_EVM;
        cfg.port[1].phy_addr = EMAC_CPSW_PORT1_PHY_ADDR_EVM;
        EMAC_socSetInitCfg(0, &cfg);
    
       Task_Params_init(&taskParams);
        taskParams.priority = 1;
        taskParams.stackSize = 0x1400;
        main_task = Task_create (TaskFxn, &taskParams, NULL);
    
    
        NIMUDeviceTable[nimu_device_index++].init =  &CpswEmacInit ;
        NIMUDeviceTable[nimu_device_index].init =  NULL ;
    
        BIOS_start();
    
        return -1;
    }
    
    /**
     *  \name TaskFxn
     *  \brief Task which do EIP initialization
     *  \param a0
     *  \param a1
     *  \return none
     *
     */
    void TaskFxn(UArg a0, UArg a1)
    {
        NIMU_log("\n\rSYS/BIOS Ethernet/IP (CPSW) Sample application\n\r");
        SendDataToPC();
    }
    //tagged by anjana
    void SendDataToPC()
    {
    	SOCKET s = INVALID_SOCKET;
    	struct sockaddr_in sin1;
    	int j,I,test=256;
    	int yes1=1;
    	char *pBuf = 0;
    	struct timeval timeout;
    	app_delay(1000000);
    	fdOpenSession( (HANDLE)Task_self() );
    	NIMU_log("\n== Start TCP Client Test ==\n");
    	// Create test socket
    	s = socket(AF_INET, SOCK_STREAM, 0);
    	if( s == INVALID_SOCKET )
    	{
    		NIMU_log("failed socket create (%d)\n",fdError());
    	goto leave;
    	}
    	// Prepare address for connect
    	bzero( &sin1, sizeof(struct sockaddr_in) );
    	sin1.sin_family = AF_INET;
    	sin1.sin_addr.s_addr =  inet_addr(IPAddr);//inet_addr(SERVER_IP);//htonl(-1);
    	sin1.sin_port = htons(23);//htons(9000);
    	
    	// Configure our Tx and Rx timeout to be 5 seconds For TCPIP
    	timeout.tv_sec = 5;
    	timeout.tv_usec = 0;
    
    	if(setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof( timeout ) ) < 0 )
    			{
    				NIMU_log("failed Socket opt(%d)\n",fdError());
    			goto leave;
    			}
    	else
    	{NIMU_log("Socket opt succesful\n");}
    
    	setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof( timeout ) );
    	// Connect socket
    	if( connect( s, (PSA) &sin1, sizeof(sin1) ) < 0 )
    	{
    		NIMU_log("failed connect (%d)\n",fdError());
    	goto leave;
    	}
    	// Allocate a working buffer
    	if( !(pBuf = malloc( test )) )
    	{
    		NIMU_log("failed temp buffer allocation\n");
    	goto leave;
    	}
    	// Fill buffer with a test pattern
    	for(I=0,j=0; I<85; I++)
    	{
    	*(pBuf+I) = (char)I;
    	
    	}
    	// Send the buffer
    
    	for(I=0;I<100;I++)
    	{
    	test=send( s, pBuf, sizeof(pBuf), 0 );
    	//test=sendto(s, pBuf, 256, 0, (PSA)&sin1,sizeof(sin1));//for UDP
    	NIMU_log("send result= %d\n",test);
    	NIMU_log("send failed (%d)\n",fdError());
    	app_delay(1000000);
    	}
    
    	leave:
    	if( pBuf )
    	free( pBuf );
    	if( s != INVALID_SOCKET )
    	fdClose( s );
    	NIMU_log("== End TCP Client Test ==\n\n");
    	// Free the file descriptor environment for this Task
    	fdCloseSession( (HANDLE)Task_self() );
    	Task_exit();
    	}
    
    void app_delay(uint32_t delayValue)
    {
        volatile uint32_t delay = delayValue*10;
        while (delay--);
    }
    

  • Anjana,

    From the wireshark trace, it appears the packets have been transmitted to wire/PC. To receive the packet data, you need a similar socket receive application other than Telnet in PC. There are a few window socket apps in ndk_2_24_x_y\packages\ti\ndk\winapps, for example, recv.c/recv.exe. To establish Telnet communication, you need to develop a Telnet server/client on the EVM.

    Regards, Garrett
  • Hi Garrett,

    I developed TCPiP client on the EvM defined port 23 the source code I attaced in my last communication.

    When i run this code using target debugger. i got send(..) response as number of bytes send, means it trys to send data for approx 20 iterration but after that the response of send(..) changes to error code 35 /* Operation would block */ and then 57 /*Socket is not connected */ . 

    The window socket apps in C:\ti\ndk_2_24_03_35\packages\ti\ndk\winapps recv.c and send.c both are prograamed as TcPIP client. when i am trying to run recv.exe (cmd: recv.exe 192.168.0.254 23 ) it is giving failed connect error 10060.

    I am attaching the NIMU system overview

     Is the configuration is correct. Hre telnet is selcted what dose this means?

      

  • Anjana,

    You don't have to enable Telnet server for just verifying TCP/IP socket connection. For Telnet configuration, please check these threads:
    e2e.ti.com/.../327369
    e2e.ti.com/.../343931

    Regards,
    Garrett
  • Hi Garrett,

    Why Tcp.transmitBufSize is set to 8192? Is there any specific reason.

    Thanks,

    Anjana Pathak

  • Anjana,


    It doesn't have to be 8192 for Tcp.transmitBufSize, but we observed better throughput with it in ftp application, see e2e.ti.com/.../2002191

    Regards,

    Garrett

  • 1. What should be TCP transmit buffer size for TCPIP communication protocol?

    2. I am sending the data of length 1400 bytes on tcpip through a client application running on evmam572x target to a server application running on PC. I am getting different result(bytes Received) of recv() function in server app.i.e.

    byte received:1400bytes  

    byte received:1300bytes  

    byte received:100bytes

    byte received:1400bytes  

    byte received:1200bytes  

    byte received:100bytes

    It should be of length 1400 bytes always.

     3.Also Why i am getting TCPIP retransmission issue as shown in 

  • please reply.......................

  • Anjana,

    1. There is no fixed TCP transmit buffer size for TCPIP communication protocol, you may experiment 8192, 16384...
    2. Did you look into the wireshark trace to confirm the non 1400 byte packets from EVM?
    3. This is not re-transmission issue, instead, it seem you are sending small segmented packets continuously. Wireshark will show 'TCP Retransmission' if it's.

    Regards,
    Garrett
  • sorry i attached wrong slide.......

    but if i want to transfer 2700 bytes in one packet in send command, the tcpip transmit buffer size will not effect the speed of transmission if the packets are repeatedly transmitted.

    8192 is the minimum of TCP transmit buffer size?

    Thanks,

    Anjana Pathak

  • Anjana,

    8192 is not the minimum of TCP transmit buffer size, instead, it's a value that we observed better throughput. The minimum of TCP transmit buffer size should be 20 byte TCP header plus payload size.

    Regards,
    Garrett
  • ok thanks alot...

    Anjana Pathak