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.

fdOpenSession() fails

Other Parts Discussed in Thread: SYSBIOSEquipment:
Board: ICE v2, CCSv6 vs. 6.0.1.00040,
TI XDS100v2 USB Emulator,
Windows7,
am335x_sysbios_ind_sdk_1.1.0.5
NDK 2.24.1.18
NDK's NSP 1.10.2.09
SYSBIOS 6.40.3.39
Compiler TI v5.1.9


Hello,

I am trying to run fdOpenSession() in a statically created task to be able to create a socket and send
TCP/IP data to another pc.
But fdOpenSession() returns 0 (error) when it is called the very first time.
That means
"An error return indicates that a session is already open for
the specified task, or that a memory allocation error has occurred."

If lack of memory is the reason, how could I find out?

The code I am using is the EchoTcp() function from the NDK User's Guide, chapter "3.4 Example Code".
The function is called at the beginning of the task.

Thank you.

Regards,
Martin H.
  • Hi Martin,

    In order to determine whether the NDK memory manager has run out of memory, you can get a memory allocation report using _mmCheck() function. Please see Section 3.5.6 of the user guide for more info on how to interpret the memory report and _mmCheck() function syntax.

    In case you find that the memory manager has run out of memory, you can increase the memory manager's raw page count or raw page size. The memory manager configuration parameters are described here.

    Best,

    Ashish

  • Hi Ashish,

    thanks for your response.

    I tried to run _mmCheck(), but in my switch project (stripped ethernetip_adapter example ) the function is not declared.
    I found it's definition in the file mem.c, but compiling the file led to some errors.
    Probably the better way would be to add the right library file to the search path. But which one is the right library?
    C:\ti\ndk_2_24_01_18\packages\ti\ndk\os\lib contains several files but none of them seems to have the .lib extension.

    Or should the .cfg file be modified?

    Thank you.

    Regards,
    Martin H.
  • P.S.
    The problem is the same with a new TI_RTOS project: _mmCheck() is declared implicitly.

    Regards,
    Martin H.
  • Hi Martin,

    All the necessary libraries should already be pulled in. Can you try adding the below line to the C file where you are making the _mmCheck() call and rebuild ?

    extern void _mmCheck( unsigned int CallMode, int (*pPrn)(const char *,...) );

    Best,
    Ashish
  • Hi Ashish,

    I did as you suggested and also added the definitions
    #define MMCHECK_MAP 0 // Map out allocated memory
    #define MMCHECK_DUMP 1 // Dump allocated block ID's
    #define MMCHECK_SHUTDOWN 2 // Dump allocated block's & free

    The project now compiles.
    To come closer to a solution for that fdOpenSession() issue, I added _mmCheck() before and after the call:

    _mmCheck(MMCHECK_DUMP, &System_printf);
    System_flush();

    // Allocate the file descriptor environment for this Task
    i = fdOpenSession( (HANDLE)Task_self() ); // returns 0 (error)

    _mmCheck(MMCHECK_DUMP, &System_printf);
    System_flush();



    The result in the console view is this:

    [CortxA8]
    0:48 0:96 0:128 0:256
    0:512 0:1536 0:3072
    (0/0 mmAlloc: 0/0/0, mmBulk: 0/0/0)

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

    0:48 0:96 0:128 0:256
    0:512 0:1536 0:3072
    (0/0 mmAlloc: 1/1/0, mmBulk: 0/0/0)

    I am not sure what that memory report means, but it is always the same.
    I does not matter if I use MMCHECK_MAP, MMCHECK_DUMP or MMCHECK_SHUTDOWN as a parameter.

    The problem seems to come with fdOpenSession().
    Perhaps I should mention that I added
    #include "ti/sysbios/knl/Task.h"
    to get rid of that Task_self() error the compiler came up with.

    Does that make any sense to you?

    Regards,
    Martin H.
  • Hi Martin,

    Section 3.5.6 of the user guide explains how to interpret the report. As per the report, no memory is available for allocation. It looks like the memory manager init routine has not run yet.

    I am guessing what might be happening is that your statically created task that call fdOpenSession() is being called before the NDK task runs and is able to initialize the NDK stack. Can you try the following ?

     - Create a sempahore and update your network task to pend on it before calling fdOpenSession().

     - Add a networkIPAddrHook function that posts this semaphore. This hook function is called once the stack is initialized so it should be safe to unblock your network task so it can call fdOpenSession() at this time.

    *.cfg:
    var Global = xdc.useModule('ti.ndk.config.Global');
    Global.networkIPAddrHook = '&myIPAddrHook';
    
    *.c:
    Void myIPAddrHook(IPN IPAddr, uint IfIdx, uint fAdd)
    {
        Semaphore_post(...);
    }
    

    Best,

    Ashish

  • Hi Ashish,

    excellent! That solved the problem (and improved my understand of TI-RTOS).
    fdOpenSession() returns 1 and prints "[CortxA8] Network Added: If-1:192.168.1.64"
    and socket() returns a handle.


    To do the modifications I had to add "${PROJECT_BUILD_DIR}/configPkg/package/cfg" to the Include Search PATH of the project and add #include "app_pea8fnv.h" to the source file.
    Otherwise the static tasks and semaphores would not have been available.
    This .h file also includes semaphore.h (prototypes for semaphore functions) and task.h.

    I still wonder if that this is the recommended procedure (adding .h files manually). Or are there some settings in the .cfg file that make TI-RTOS components available automatically?

    I then connected to a TCP server and sent data (function EchoTcp() from the User Guide is called once in my network task).
    Data is received by the server.
    I could not yet check if all the data has been received and if all data is correct.
    However, in the console view the error message
    "recv failed (35)"
    shows up.
    Do you have an idea what might have caused this message?

    Thank you.


    Regards,
    Martin H.
  • Hi Ashiv,

    sorry for my last question. Asking that was somewhat overhasty.
    That message seems to be the result of the recv() function.
    The error code is defined like this:
    #define EWOULDBLOCK 35 /* Operation would block */
    "The socket is specified as non-blocking, or the timeout has expired."

    I did not use that windows application that sends data back. So the recv() function timed out.
    My fault.

    Regards,
    Martin H.
  • Hi Martin,

    Glad to know that your application is working.

    Martin H. said:

    To do the modifications I had to add "${PROJECT_BUILD_DIR}/configPkg/package/cfg" to the Include Search PATH of the project and add #include "app_pea8fnv.h" to the source file.
    Otherwise the static tasks and semaphores would not have been available.
    This .h file also includes semaphore.h (prototypes for semaphore functions) and task.h.

    I still wonder if that this is the recommended procedure (adding .h files manually). Or are there some settings in the .cfg file that make TI-RTOS components available automatically?

    If you statically create task or semaphore instances, you can store their handles in a global variable that can be referenced from your C file. Please see this link for more info on this: http://rtsc.eclipse.org/cdoc-tip/index.html#xdc/cfg/Program.html#global. The link also has an example.

    Best,

    Ashish

  • Hi Ashish,

    that sounds interesting but it is still cousing some headache.

    What is xdc_cfg__header__, the executable-specific C/C++ header generated by the program configuration?

    Is it app_pea8fnv.h, which I already used ?

    And if so, would I just have to do a
    #define xdc_cfg__header__ local\Debug\configPkg\package\cfg\app_pea8fnv.h
    in the appropriate .c file?

    Where would I expect to find Mod.h?

    Regards,
    Martin H.
  • Hi Martin,

    Basically, you dont have to include "app_pea8fnv.h" header file or define xdc_cfg__header__local. If you need to create an object in the cfg file and reference it in the C file, you would create it like this:

    *.cfg example:
    Program.global.myTask = Task.create(...);

    And then in your C file, you would include the global header file and reference myTask (or what the variable name is) like a global variable.

    *.c example:
    #include <xdc/cfg/global.h>

    func() {
    Task_setPri(myTask, ...);
    }

    Best,
    Ashish