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.

MEM_alloc using DSP/BIOS

Other Parts Discussed in Thread: CCSTUDIO

Dear Sir:

I want to use MEM_alloc or malloc in my program like this

char *a = (char*)malloc(10);

First, when I didn't choose "No Dynamic Memory Heaps", of course I got return a=0x0.

Next, I disable "No Dynamic Memory Heaps" and make DDR2 "create a heap in this memory" as "True" and set the heap size as 0x400, enable "usr defined heap identifier label".

But I got serious result because after entering the function malloc, the program never return and hang in this function.

I try MEM_alloc(DDR2, 10, 0) too but still has this problem.

 

How can I suppose to resolve this?

Thank you very much.

 

 

  • Penny,

    Calls to malloc() or MEM_alloc() are usually safe as long as you have enough memory and no other higher priority threads are locking the same memory.

    Assuming that your external memory is working (i.e., the EMIF is properly configured by your custom code or via a GEL file), the most common root for this problem is calling MEM_alloc() or malloc() either from a SWI or from a HWI - this can cause lockup problems given these APIs have a memory lock mechanism to protect against data overwrite.

    To explore this further I would suggest to verify the following references:

    This question at the DSP/BIOS FAQ that talks about the RTS functions that use the LCK mechanism;

    MEM_alloc() and LCK_pend() descriptions at the DSP/BIOS API Guide (SPRU403 for C6000);

    Section A.1 - Function Callability Table of the DSP/BIOS API Guide (SPRU403 for C6000)

    Section 5.1 of the DSP/BIOS User's Guide that talks about general memory configuration (SPRU423);

    For an usage example check the supplied DSP/BIOS example project mem_management typically located at

    C:\CCStudio_v3.3\bios_5_33_05\packages\ti\bios\examples\basic\mem_management

    Hope this information helps,

    Rafael

     

  • I have tried mem_management sample before.

    It can really work when allocating memory in IRAM

    However, when I change to DDR2 it will fail.

    I add extern Int SEG1 as DDR2 heap identifier label, change the malloc()/free() memory to DDR2.

    I check the trace memory and got some message:

    2 seg0: segment size 0x2000
    3       number of MADUs used in seg0: 0x2000
    4       size of the largest free contiguous block of memory in seg0:    A 0x0
    5   allocating memory blocks in seg0 ...
    6   memory block 0 allocated at address = 00000000
    7   memory block 1 allocated at address = 00000000
    8   after allocating ...
    9   seg0: segment size 0x2000
    10       number of MADUs used in seg0: 0x2000
    11       size of the largest free contiguous block of memory in seg0:    A 0x0

    I wonder why there's no contiguous memory.

    Thank you very much.

     

    Penny

  • I check out the Kernel Object View window and found that

    the MEM object describes two memory segment status.

    The IRAM is normal but the another one is "PRD_STARTPRD Memory Heap Full".

    Once the program beginning, the memory heap is full no matter how I set the DDR2 size and heap size.

    How to resolve this problem?