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.

How to allocate memory on DSP based on codec engine in DM3730

Hi,

I am trying to allocate memory on dsp through Memory_alloc() function. This work is based on codec engine in DM3730, which is modified from the videnc_copy example. I made some changes in the (.tcf) file  as follows:

bios.setMemDataHeapSections (prog, bios.DDRALGHEAP);

bios.MEM.MALLOCSEG  = bios.DDRALGHEAP;

(the default setup is

bios.setMemDataHeapSections (prog, bios.DDR2);

bios.MEM.MALLOCSEG  = bios.DDR2;

)

and also in the .cfg file, change is made  as follows:

DSKT2.ALLOW_EXTERNAL_SCRATCH = true;

(the default setup is false)

And then in the videnc_copy.c file, i coded :

Memory_AllocParams allocParams;
allocParams.type = Memory_CONTIGPOOL;
allocParams.flags = Memory_NONCACHED;
allocParams.align = 128;
allocParams.seg = 0;

tempBuf2 = (XDAS_UInt8 *)Memory_alloc( minSamples, &allocParams);

I can build the files well. But the run result is wrong. FT_trace print the result

shows that the memory request failed.

How can i copy with this problem?

In addition,

I tried to use malloc function after i changed the setup as described above. i found the

function malloc can work well, though the malloc function is  not allowed in XDAS.

thks in advance!

F.H. Sun

  • I suspect that you are running out of Memory for the segment 0 from which you are trying to allocate memory.  Does it work if you leave memory configuration in tcf to DDR2?

    Here is some related info about configuring memory heaps for BIOS 5:

    http://e2e.ti.com/support/embedded/tirtos/f/355/p/63829/231552.aspx#231552

    You might also find the following information useful:

    http://e2e.ti.com/support/dsp/davinci_digital_media_processors/f/537/t/346316.aspx

  • Hi Armie Reynoso,

    Thks for your reply.

    When I left memory configuration in tcf to DDR2, the memory request also failed. GT_trace prints the address of 

    the allcoated memory is 0x0.  

    I agree with your deduction about running out of memory. So, I tried to leave memory configuration to DDRALGHEAP which is large enough. And the memory map is set as follows:

    comment: "DDRALGHEAP: off-chip memory for dynamic algmem allocation",
    name: "DDRALGHEAP",
    base: 0x88000000, //128MB
    len: 0x07600000, // 118 MB
    space: "code/data"
    },
    {
    comment: "DDR2: off-chip memory for application code and data",
    name: "DDR2",
    base: 0x8F600000,
    len: 0x00400000, // 4 MB
    space: "code/data"
    }

    However, I still can not use Memory_alloc() function on DSP. I think some setup details remain

    to be done for solving the problem. But I still donot know how to set these configuration.

    Looking forward to further suggestions and thks again!

    F.H. Sun

     

  • You previously mentioned that malloc() works. When using DSP/BIOS, all malloc calls are in routed to MEM_alloc using the location configured by "MEM.MALLOCSEG". 

    Calling Memory_alloc with params.seg = 0 may be allocating from a different memory segment.  As all the Memory_* function calls are abstracted to call MEM_alloc, MEM_*, etc. on the devices running BIOS.

    The following configuration line:

    bios.MEM.MALLOCSEG  = bios.DDR2

    set which Segment location malloc/free calls will allocated from.  In order for Memory_alloc -> MEM_alloc to allocate from the same memory heap as what was configured in bios."MEM.MALLOCSEG", you can do something as follows in your config(*.tcf):

    bios.DDR2.enableHeapLabel = true;
    bios.DDR2["heapLabel"]    = prog.extern("SEG0");

    Then in your C code, you can add the following:

    extern Int SEG0;

    Memory_AllocParams allocParams;
    allocParams.type = Memory_CONTIGPOOL;
    allocParams.flags = Memory_NONCACHED;
    allocParams.align = 128;
    allocParams.seg = SEG0;

    tempBuf2 = (XDAS_UInt8 *)Memory_alloc( minSamples, &allocParams);

    For sake of completeness, you would typically also enable a heap creation for that particular memory segment with a size as follows:

    bios.DDR2.createHeap      = true;
    bios.IDDR2.enableHeapLabel = true;
    bios.DDR2["heapLabel"]    = prog.extern("SEG0");
    bios.DDR2.heapSize        = 0x2000;

    In your case, this may not be necessary since you indicated that calling malloc works which means that a heap somewhere in your configuration was already being created for that memory segment used by malloc.

  • hi Arnie Reynoso,

    thks for your further suggestions. I just followed what you advised. But it still can not work. 

    After thinking and trying more, I think the problem lies in the fact that the DDR2 segment is not big enough. So, I must turn to the  DDRALGHEAP segment.

    I  have done something in the configuration (*.tcf and  *.tci):

    bios.setMemDataHeapSections (prog, bios.DDRALGHEAP);

    bios.MEM.MALLOCSEG  = bios.DDRALGHEAP;

    bios.DDRALGHEAP.enableHeapLabel = true;
    bios.DDRALGHEAP["heapLabel"] = prog.extern("SEG0");

    and also in the c codes, i followed your advice :

    extern Int SEG0;

    Memory_AllocParams allocParams;
    allocParams.type = Memory_CONTIGPOOL;
    allocParams.flags = Memory_NONCACHED;
    allocParams.align = 128;
    allocParams.seg = SEG0;

    Finally, it can work well! 

     F. H. Sun