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.

[ NDK ] mmAlloc issue

I'm using NDK bundled with tirtos_sitara_2_00_01_23.

I'm testing http server, so I'm adding some web content as described in sprh524h.pdf:

void AddWebFiles(void)
{

efs_createfile("index.html", DEFAULT_SIZE, DEFAULT);
}

I cannot add any file, because efs_createfilecb always returns with no action performed, since mmAlloc always returns NULL:

void efs_createfilecb( char *name, INT32 length, UINT8 *pData,
                       EFSFUN pllDestroyFun, UINT32 MemMgrArg )
{
    FILEHEADER *pfh;

    /* Allocate the file header structure */
    pfh = mmAlloc( sizeof(FILEHEADER) );
    if( !pfh )
        return;

 mmAlloc (in /os/mem.c), performs this check at line 264 :

    /* Here we didn't find a free or usable PIT, so we have an OOM */
    /* error or a fatal error */
    if( PITUsed != PITCount )
        DbgPrintf(DBG_ERROR,"mmAlloc: PIT Used Sync");
    goto MMA_ERROR;

looking at variables with debugger, PITUsed =0 and PITCount=0, so no error should come up.

There are no parentheses after if() statement, so if everything is ok BdgPrintf is not invoked, but gotoMMA_ERROR is always executed. Is this the expected behaviour?

  • Eugenio,

    This is the first I’ve looked at this function… but the way I read it is that the CPU gets to that point if (as it says in the comment) if there is either an out of memory condition, or some fatal error.  In either case an error is detected, but it is only for the PITUsed != PITCount case that the “PIT Used Sync” error is printed.  Earlier in the function there are a couple “goto MMA_PITVALID;” statements that hop over this check.

    When this happens, is it possible you've simply run out of free memory?

    Thanks,
    Scott

  • Here is a write-up about the memory allocation in the Networking Stack:

    Additionally, here is a write-up about how to create an HTTP Server. http://processors.wiki.ti.com/index.php/TI-RTOS_HTTP_Example

    It's for a different device, but the steps are the same.

    Todd

  • Hi Todd, great example!

    Problem was that efs_createfile() should be called *after* NDK has started. 

    In my first attempt I've called before BIOS_start(), when NDK global variables were uninitialized.

    I suggest to improve the spru524h.pdf: there is no mention of this requirement in section E) "Web programming with the HTTP server":

  • Thank you for your reply!

    Problem was more subtle (to me): mmAlloc was called before NDK initialization. Now everything works great.

  • Todd, maybe there is a small bug in file/TIRTOS_httpServer/SDCardFiles/efs_stdio.c

    If you point to efs_filesend function, fread always read 4 bytes of data ( sizeof(buf) )

        if ((buf = malloc(512)) != NULL) {
            for (total = size; total > 0; total -= cnt) {
                cnt = fread(buf, 1, sizeof(buf), stream);
    

    Should be:

        if ((buf = malloc(512)) != NULL) {
            for (total = size; total > 0; total -= cnt) {
                cnt = fread(buf, 1, 512, stream);
    

  • Thanks. I'll open a bug report and take a closer look.