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.

RTOS/OMAPL138B-EP: How to use memory_alloc function

Part Number: OMAPL138B-EP
Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

Hi there, I have specified heap memory in the Memory Management section of the SYSBIOS Configuration file to be 1MB.

In my main function I am using some port of the heap by calling the following function:

c_state = (system_vector*)  Memory_alloc(NULL,sizeof(c_state),0,&eb);

When I read the c_state after executing the about memory_alloc function I get an pointer to the buffer as 0xC3000100 which is pointing to the external memory (DDR2)

I have restarted the main() many times and it for some reason always uses 0xC3000100 address to point the buffer, Which I guess is okay. But when I look at the Memory Browser in CCS at this address 0XC3000100

__ASM__, ti_sysbios_heaps_HeapMem_Instance_State_0_buf__A

What is this? the reason I ask is, I am noticing the data in the buffer changing randomly. 

Please let me know if there is any other mention to allocate buffer in the SYSBIOS dynamically. 

Regards,

Mitesh

  • Hi Mitesh,

    'ti_sysbios_heaps_HeapMem_Instance_State_0_buf__A' is simply a symbol that indicates the start of the memory managed by the HeapMem instance. An array of this name is allocated automatically for the heap. As for the data in the buffer changing randomly, that may or may not be an issue. For example, it is possible for code executed before main() to allocate from the heap, start filling it, and subsequently free it. It really depends on your specific application. Your Memory_alloc() call looks fine to me - assuming eb is a valid Error_Block. Please refer to rtsc.eclipse.org/.../Memory.html for documentation on Memory_alloc.

    Best regards,
    Vincent
  • Thanks for your reply. Is there any way to be sure that buffer allocated doesn't randomly overly by other part of the code?

    How to be sure if the error block is defined properly and hoe will that help in this case? Thanks.

  • Hi Mitesh,

    You can maybe try setting up a data breakpoint to halt the processor on the code that writes to the beginning of the heap, if this feature is supported on your platform.:

    Otherwise, I'd suggest to start stepping thru the code starting from the entry point of your program til you see a change in the memory contents in the Memory Browser. That should help you pinpoint where the write occurs. Turning off optimization in your compiler options and setting

    var BIOS = xdc.useModule('ti.sysbios.BIOS');

    BIOS.libType = BIOS.LibType_Debug;

    in your .cfg file to use the debug libraries should make it easier to step thru any code from the BIOS libraries.

    One more tip: When you run the app using CCS, after loading the app, verify in the Disassembly window (Window->Show View -> Disassembly) that you are indeed at the first instruction of your bootloader's entry point. Make sure you do not have CCS configured to automatically run to main() after load completion (you can disable this by right clicking on the first entry in the Debug window of your target configuration, select Open GEL Files View, Auto Run and Launch Options, and deselect the box next to 'On a program load or restart':

    As for error blocks, I don't think it is affecting you in this case, but you should still be using them properly in order to obtain error information whe3n failure occurs. Here's an example of how it is normally setup:

     #include <xdc/runtime/Error.h>

     #include <xdc/runtime/Memory.h>

     Error_Block eb;

     char * ptr;

     Error_init(&eb);

     ptr = (char *)Memory_alloc(..., &eb);

    please refer to the XDC runtime documentation for how they work:

    Best regards,

    Vincent

  • Hi Vincent, thanks for your reply. It was typo in the memory alloc function. It's working fine now. Thanks.

  • Hi there is there a way to initialse buffer to zero, using memory alloc function?
  • Hi Mitesh,

    You can use Memory_calloc() - rtsc.eclipse.org/.../Memory.html

    Best regards,
    Vincent