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.

TMDSIDK437X: SNTP socket creation error

Part Number: TMDSIDK437X
Other Parts Discussed in Thread: SYSBIOS

HI,

Below are the components i am using.

I have sntp applicaiton as well library to project "NIMU_ICSS_BasicExample_idkAM437x_wSoCLib_armExampleproject".

Appliation code i am using for sntp is below.

 int32_t  retVal;
    uint32_t seconds;
    uint32_t secondsFraction;
    SlNetSock_Timeval_t timeval;
    uint64_t ntpTimeStamp = 0;
    SlNetSock_AddrIn_t ipv4addr;

    uint32_t addr = 0xc800a8c0;
    //uint32_t addr = 0xc0a880c8;

    ipv4addr.sin_family = SLNETSOCK_AF_INET;
    ipv4addr.sin_port = SlNetUtil_htons(123/*SNTP_PORT*/);
    ipv4addr.sin_addr.s_addr = inet_addr("192.168.0.200");
    timeval.tv_sec  = 5;
    timeval.tv_usec = 0;



    while(1) {

            retVal = SNTP_getTimeByAddr((SlNetSock_Addr_t *)&ipv4addr, &timeval,
                  &ntpTimeStamp);

            if (retVal == 0) {
                // The seconds value is stored in the upper 32 bits
                seconds = (0xFFFFFFFF00000000 & ntpTimeStamp) >> 32;
                // The seconds fraction is stored in the lower 32 bits
                secondsFraction = ntpTimeStamp;
            }



        /* Sleep to yield */
        Task_sleep(16000);
    }
    Task_exit();

But it is not able to create socket under function "getTime".

failed at 

/* Create a UDP socket to communicate with NTP server */
    sd = SlNetSock_create(server->sa_family, SLNETSOCK_SOCK_DGRAM, SLNETSOCK_PROTO_UDP, ifID, 0);
    if (sd < 0)
    {
        return (SNTP_ESOCKCREATEFAIL);
    }

Kindly help.

Regards,

Vrund

  • Gentle reminder..

    I reliazed the problem occurs when 

    SLNETSOCK_LOCK is getting called.

    Kindly suggest.

    Regards,

    Vrund

  • Hi Vrund,

    What was the behavior of the program (or symptom of the problem) when SLNETSOCK_LOCK was called? Was the program just hanging?

    Please note that SLNETSOCK_LOCK() is defined as sem_wait() which waits for semaphore VirtualSocketSem to be available. The semaphore needs to be first initialized. Did your program call SlNetSock_init() which initializes that semaphore?

    Thanks,

    Jianzhong

  • Hello,

    1) Behavior of the program: hang

    2) First of all below are the definition i found in package.(SLNETSOCK_LOCK())

    #define SLNETSOCK_LOCK() pthread_mutex_lock(&VirtualSocketMutex) // forever
    #define SLNETSOCK_UNLOCK() pthread_mutex_unlock(&VirtualSocketMutex)

    3) I have tried with  SlNetSock_init()  also behavior is same.

    If i use sem_wait() which header file i need to include? I am working on windows platform and using TI RTOS.

    config script snapshot.

    var Clock = xdc.useModule('ti.sysbios.knl.Clock');
    var Swi = xdc.useModule('ti.sysbios.knl.Swi');
    var Task = xdc.useModule('ti.sysbios.knl.Task');
    var Mailbox = xdc.useModule('ti.sysbios.knl.Mailbox');
    var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
    var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
    var Timer = xdc.useModule('ti.sysbios.hal.Timer');
    var SemihostSupport = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');

    Regards,

    Vrund

  • Hi Vrund,

    My apology. I was looking at a different version of Network Services. In ns_2_60_01_06, SLNETSOCK_LOCK() is defined as pthread_mutex_lock(), not sem_wait(). 

    You probably have read the NS User's Guide at: ns_2_60_01_06/docs/ns/NS_Users_Guide.html, but I just wanted to point out that following text from section 2.2 Usage is important to follow:

    To use the SlNetSock APIs, the application should include its header file as follows:

    #include <ti/net/slnetsock.h>
    #include <ti/net/slnetif.h>
    #include <ti/net/slnetutils.h>

    At runtime, users must initialize any modules they use:

        SlNetSock_init(0);
        SlNetIf_init(0);
        SlNetUtil_init(0);

    Users must also register at least one SlNetIf “interface” that will provide SlNetSock services:

    /* To add the NDK network stack */
    #include <ti/ndk/slnetif/slnetifndk.h>
    
        status = SlNetIf_add(SLNETIF_ID_2, ifName,
                (const SlNetIf_Config_t *)&SlNetIfConfigNDK, ndkPri);

    For more details, including example code, see the SlNetSock API Reference Guide.

    Regards,

    Jianzhong

  • Hello,

    As suggested, i have added code as below.

    header file included: #include <ti/ndk/slnetif/slnetifndk.h>

    void SNTP_Update(void)
    {
    
    
    #if 0
        HANDLE      hCfgIpAddr;
        while(1){
    
            /*get the current static IP entry */
            CfgGetEntry(0, CFGTAG_IPNET, 1, 0, &hCfgIpAddr);
            /* Sleep to yield */
            Task_sleep(16000);
        }
    Task_exit();
    
    #else
        int32_t  retVal;
        uint32_t seconds;
        uint32_t secondsFraction;
        SlNetSock_Timeval_t timeval;
        uint64_t ntpTimeStamp = 0;
        SlNetSock_AddrIn_t ipv4addr;
    
        uint32_t addr = 0xc800a8c0;
        //uint32_t addr = 0xc0a880c8;
    
        ipv4addr.sin_family = SLNETSOCK_AF_INET;
        ipv4addr.sin_port = SlNetUtil_htons(123/*SNTP_PORT*/);
        ipv4addr.sin_addr.s_addr = inet_addr("192.168.0.200");
        timeval.tv_sec  = 5;
        timeval.tv_usec = 0;
    
        uint8_t ndkPri = 1;
        int32_t status = 0;
    
        SlNetSock_init(0);
        SlNetIf_init(0);
        SlNetUtil_init(0);
    
        status = SlNetIf_add(SLNETIF_ID_2, "eth0",
                    (const SlNetIf_Config_t *)&SlNetIfConfigNDK, ndkPri);
        while(1) {
    
                retVal = SNTP_getTimeByAddr((SlNetSock_Addr_t *)&ipv4addr, &timeval,
                      &ntpTimeStamp);
    
                if (retVal == 0) {
                    // The seconds value is stored in the upper 32 bits
                    seconds = (0xFFFFFFFF00000000 & ntpTimeStamp) >> 32;
                    // The seconds fraction is stored in the lower 32 bits
                    secondsFraction = ntpTimeStamp;
                }
    
    
    
            /* Sleep to yield */
            Task_sleep(16000);
        }
        Task_exit();
    #endif
    }

     slnet files as well as library are also added from ns package to the project and to linker directory.

    C:\ti\ns_2_60_01_06\source\ti\net

    C:\ti\ns_2_60_01_06\source\ti\net\lib\gcc\a9fg : release.a

    as well sntp related files and library are also to the project and to linker directory.

    Apart from this Below are the files added from NDK package.(C:\ti\ndk_3_61_01_01\packages\ti\ndk\slnetif)

    slnetifndk.c, slnetifndk.h, slnetifndk_internal.h

    Compiler not able to locate header file (#include <semaphore.h>)from file slnetifndk.c

    As i informed i am using sys bios rtos

    var Defaults = xdc.useModule('xdc.runtime.Defaults');
    var Diags = xdc.useModule('xdc.runtime.Diags');
    var Error = xdc.useModule('xdc.runtime.Error');
    var Main = xdc.useModule('xdc.runtime.Main');
    var System = xdc.useModule('xdc.runtime.System');
    var Text = xdc.useModule('xdc.runtime.Text');
    var Clock = xdc.useModule('ti.sysbios.knl.Clock');
    var Swi = xdc.useModule('ti.sysbios.knl.Swi');
    var Task = xdc.useModule('ti.sysbios.knl.Task');
    var Mailbox = xdc.useModule('ti.sysbios.knl.Mailbox');
    var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
    var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
    var Timer = xdc.useModule('ti.sysbios.hal.Timer');
    var SemihostSupport = xdc.useModule('ti.sysbios.rts.gnu.SemiHostSupport');

    My understanding is that for semaphore.h needs to be located under posix (C:\ti\bios_6_76_03_01\packages\ti\posix\gcc)

    But I am not using posix RTOS. How to proceed further.

    Kindly guide.

    Regards,

    Vrund

  • Hi Vrund,

    Please try to use the pre-built NDK library from ndk_3_61_01_01\packages\ti\ndk\slnetif\lib instead of adding slnetifndk.c to your project.

    Thanks,

    Jianzhong

  • Hello,

    Added and project is getting build.

    But i am not able to add interface as it is getting failed at 

     /* Check if all required configuration exists                            */
        retVal = SlNetIf_configCheck(ifConf);
    
        /* Check retVal in order to continue with adding the interface           */
        if (SLNETERR_RET_CODE_OK == retVal)
        {

    It is not going in if case.

    can you provide any example code how to add interface.

    below is my code.

    void SNTP_Update(void)
    {
    #if 1
    
        int32_t  retVal;
        uint32_t seconds;
        uint32_t secondsFraction;
        SlNetSock_Timeval_t timeval;
        uint64_t ntpTimeStamp = 0;
        SlNetSock_AddrIn_t ipv4addr;
    
        uint32_t addr = 0xc800a8c0;
        //uint32_t addr = 0xc0a880c8;
    
        ipv4addr.sin_family = SLNETSOCK_AF_INET;
        ipv4addr.sin_port = SlNetUtil_htons(123/*SNTP_PORT*/);
        ipv4addr.sin_addr.s_addr = inet_addr("192.168.0.200");
        timeval.tv_sec  = 5;
        timeval.tv_usec = 0;
    
        uint8_t ndkPri = 1;
        int32_t status = 0;
        SlNetIf_Config_t SlNetIfConfigNDK;
    
        SlNetSock_init(0);
        SlNetIf_init(0);
        SlNetUtil_init(0);
    
        status = SlNetIf_add(SLNETIF_ID_2, "eth0",
                    (const SlNetIf_Config_t *)&SlNetIfConfigNDK, ndkPri);
        while(1) {
    
                retVal = SNTP_getTimeByAddr((SlNetSock_Addr_t *)&ipv4addr, &timeval,
                      &ntpTimeStamp);
    
                if (retVal == 0) {
                    // The seconds value is stored in the upper 32 bits
                    seconds = (0xFFFFFFFF00000000 & ntpTimeStamp) >> 32;
                    // The seconds fraction is stored in the lower 32 bits
                    secondsFraction = ntpTimeStamp;
                }
    
    
    
            /* Sleep to yield */
            Task_sleep(16000);
        }
        Task_exit();
    #endif
    }

    Regards,

    Vrund

  • Hi Vrund,

    Your data structure "SlNetIfConfigNDK" is not populated and that's why SlNetIf_configCheck() returns error. Please refer to ns_2_60_01_06\source\ti\net\slnetif.h for the mandatory configurations.

    Thanks,

    Jianzhong

  • Hi Vrund,

    I looked at SNTP_getTimeByAddr() a little more. This function depends on SlNetSock module and SlNetUtils module. So you don't have to call SlNetIf_init() or SlNetIf_add(). Can you try just adding the following into your application:

        SlNetSock_init(0);
        SlNetUtil_init(0);
    

    Thanks,

    Jianzhong

  • Hi,

     I have tried that option but not working.

    There are couple of points i would like to draw your attention.

    1) Below is the function SlNetUtil_init is it ok? i havent seen any initialization into this.

    int32_t SlNetUtil_init(int32_t flags)
    {
        return 0;
    }

    2) During debugging till  SLNETSOCK_LOCK(); code works fine under function SlNetSock_AllocVirtualSocket().

    after  SLNETSOCK_LOCK(); it comes to function

    acquireMutexNone() 
    static int acquireMutexNone(pthread_mutex_obj *mutex, UInt32 timeout)
    {
        UInt               key;
        pthread_Obj       *thisThread;
    
        thisThread = (pthread_Obj *)pthread_self();
    
        /* Return if the thread already owns the mutex */
        if (mutex->owner == thisThread) {
            if (mutex->type == PTHREAD_MUTEX_ERRORCHECK) {
                return (EDEADLK);
            }
            if (mutex->type == PTHREAD_MUTEX_RECURSIVE) {
                mutex->lockCnt++;
                return (0);
            }
    
            /*
             *  If we get here, the mutex type is PTHREAD_MUTEX_NORMAL, so
             *  deadlock will occur (with an infinite timeout).
             */
            Assert_isTrue(mutex->type != PTHREAD_MUTEX_NORMAL, 0);
        }

    after Assert_isTrue(mutex->type != PTHREAD_MUTEX_NORMAL, 0);

    it raies the error. IN console window "CortexA9: Unhandled ADP_Stopped exception 0x803C7078"

    and "

    Can't find a source file at "/db/ztree/library/trees/newlib/newlib-a00/src/linaro/gcc-arm-none-eabi-7-2017-q4-major/src/newlib/libgloss/arm/swi.h"
    Locate the file or edit the source lookup path to include its location. " under source file window.

    Void Assert_raise(Types_ModuleId mod, CString file, Int line, Assert_Id id)
    {
        String sep = (id != 0U) ? ": " : "";
        CString msg = (id != 0U && Text_isLoaded == TRUE) ?
            Text_ropeText((Text_RopeId)(id >> 16)) : "";
    
        Error_raiseX(NULL, mod, file, line,
            Assert_E_assertFailed, (IArg)sep, (IArg)msg);
    }

    After that it goes to exit function.

    void _exit(int code) 
    {
        asm(" .global C$$EXIT");
        asm("C$$EXIT:");
        while(1){};
    }
    /*
     *  @(#) gnu.targets.arm.rtsv7A; 1, 0, 0,; 9-13-2019 11:37:42; /db/ztree/library/trees/xdctargets/xdctargets-t09/src/ xlibrary
    
     */

    Regards,

    Vrund

  • Hi Vrund,

    Regarding your questions:

    1) Below is the function SlNetUtil_init is it ok? i havent seen any initialization into this.

    That's fine. This just means SlNetUtil module don't need initialization in this release.

    2) During debugging till  SLNETSOCK_LOCK(); code works fine under function SlNetSock_AllocVirtualSocket().

    Let me clarify. Before you added SlNetSock_init(), your program was hanging in SLNETSOCK_LOCK(), and now it didn't hang but failed on that assertion. Is this right? 

    The code you were looking at, acquireMutexNone(), is from TI SYS/BIOS. I wouldn't recommend you to debug that code. 

    I'm reaching out to development teams to see if we can provide some example code of using SlNetSock API. Before then, I would recommend to read the NS User's Guide and API Reference Guide to understand the proper usage of the API.

    Thank you for your patience.

    Regards,

    Jianzhong

  • Hello Jianzhong,

    The code you were looking at, acquireMutexNone(), is from TI SYS/BIOS. I wouldn't recommend you to debug that code. 

    --- I am not debugging the TI SYS/BIOS code. I am just trying to understand where exactly the

    problem is so that i can convey to you to help solve the problem fast. 

    Let me clarify. Before you added SlNetSock_init(), your program was hanging in SLNETSOCK_LOCK(), and now it didn't hang but failed on that assertion. Is this right? 

    ---Initially also (before addition of SlNetSock_init()) program goes to acquireMutexNone(),  stage.

    I'm reaching out to development teams to see if we can provide some example code of using SlNetSock API. Before then, I would recommend to read the NS User's Guide and API Reference Guide to understand the proper usage of the API.

    -- is there any other way for implementing SNTP without usage of SlNetSock API??

    kindly guide.

    Regards,

    Vrund

  • Vrund,

    The SNTP module in Network Services is implemented on top of SlNetSock module. We don't have any other way of implementing SNTP. 

    Thanks,

    Jianzhong

  • Gentle reminder..

    Kindly address the issue.

     have tried that option but not working.

    There are couple of points i would like to draw your attention.

    1) Below is the function SlNetUtil_init is it ok? i havent seen any initialization into this.

    1
    2
    3
    4
    int32_t SlNetUtil_init(int32_t flags)
    {
        return 0;
    }

    2) During debugging till  SLNETSOCK_LOCK(); code works fine under function SlNetSock_AllocVirtualSocket().

    after  SLNETSOCK_LOCK(); it comes to function

    1
    acquireMutexNone()
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    static int acquireMutexNone(pthread_mutex_obj *mutex, UInt32 timeout)
    {
        UInt               key;
        pthread_Obj       *thisThread;
        thisThread = (pthread_Obj *)pthread_self();
        /* Return if the thread already owns the mutex */
        if (mutex->owner == thisThread) {
            if (mutex->type == PTHREAD_MUTEX_ERRORCHECK) {
                return (EDEADLK);
            }
            if (mutex->type == PTHREAD_MUTEX_RECURSIVE) {
                mutex->lockCnt++;
                return (0);
            }
            /*
             *  If we get here, the mutex type is PTHREAD_MUTEX_NORMAL, so
             *  deadlock will occur (with an infinite timeout).
             */
            Assert_isTrue(mutex->type != PTHREAD_MUTEX_NORMAL, 0);
        }

    after Assert_isTrue(mutex->type != PTHREAD_MUTEX_NORMAL, 0);

    it raies the error. IN console window "CortexA9: Unhandled ADP_Stopped exception 0x803C7078"

    and "

    Can't find a source file at "/db/ztree/library/trees/newlib/newlib-a00/src/linaro/gcc-arm-none-eabi-7-2017-q4-major/src/newlib/libgloss/arm/swi.h"
    Locate the file or edit the source lookup path to include its location. " under source file window.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    Void Assert_raise(Types_ModuleId mod, CString file, Int line, Assert_Id id)
    {
        String sep = (id != 0U) ? ": " : "";
        CString msg = (id != 0U && Text_isLoaded == TRUE) ?
            Text_ropeText((Text_RopeId)(id >> 16)) : "";
        Error_raiseX(NULL, mod, file, line,
            Assert_E_assertFailed, (IArg)sep, (IArg)msg);
    }

    After that it goes to exit function.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    void _exit(int code)
    {
        asm(" .global C$$EXIT");
        asm("C$$EXIT:");
        while(1){};
    }
    /*
     *  @(#) gnu.targets.arm.rtsv7A; 1, 0, 0,; 9-13-2019 11:37:42; /db/ztree/library/trees/xdctargets/xdctargets-t09/src/ xlibrary
     */

    Regards,

  • Hi Vrund,

    1)  SlNetUtil_init() is fine. It has nothing to initialize in this release. We may add new features in future and this function may become non-empty, but API will remain the same.

    2) I'm aware of the problem within SLNETSOCK_LOCK() and am reaching out to internal developers for help. I'll try to get back to you as soon as possible.

    Thanks for your patience.

    Regards,

    Jianzhong

    P.S. I will be out from December 24 to January 3 and won't be able to respond to your posts during this period of time.