Question:
I'm new to VDK .I have a question about VDK heap.
How to define a heap in SDRAM and how to link heap id to address?
How to make a thread use heap by defined in kernal tab heaps,or I have to use heap_malloc to instead of new?
Is there a example about VDK heap use?
==============================
Answer:
As a start up please refer the manual given in the VDSP help path >Manuals>Software and tools manual>VDK manual which might help you work with VDK.
The heap can be placed into external memory like SDRAM from the "LDF Settings: System Heap" menu in the Project options. Select "Customize the system heap?" and then select "L3 external memory (SDRAM)" and increase the minimum size if required.
As you are using VDK, we recommend to read the "Memory Pools" section in the VDK manual. You can find this in VisualDSP++ Help menu: 'Help' - 'Contents' - 'Graphical Environment' - 'VDK' - 'How To' - 'Configuring VDK' - 'Memory Pools'
Also adding a heap in the VDK kernel tab makes VDK aware of existing heaps but it does not create a new heap on its own. In order to create a new heap the easiest is to use a generated CRT and LDF and add the heap there. This means that the process of using a user heap in VDK consists of two steps: adding the heap to the project and declaring it to VDK.
1. Add a user heap to the project
- With Generated Startup Code/LDF.
To add the generated LDF you need to go to the Project Options-> Add Startup Code/LDF. Once you have the startup code/LDF then you will see in the Project Options User Heap under LDF Settings.
- Without Generated Startup Code/LDF
You need to add a heap table file to your project. The heap table would look something like this (if you write it in C)
extern "asm" int ldf_heap_space;
extern "asm" int ldf_heap_length;
extern "asm" int MySDRAMHeap_space;
extern "asm" int MySDRAMHeap_length;
struct heap_table_t
{
void *base;
unsigned long length;
long int userid;
};
struct heap_table_t heap_table[3] = /* 3 would be higher if you had more than 1 user heap */
{
{ &ldf_heap_space, (unsigned long) &ldf_heap_length, 0 },
{ &MySDRAMHeap_space, (unsigned long) &MySDRAMHeap_length, 1 }, /* the user ID must increase in each iteration by 1 */
{ 0, 0, 0 }
};
And in the LDF you would have to allocate the space for your heap. For example for a fixed size 8k in L3 you would add in your L3 memory space:
RESERVE(heaps_and_stack_in_L3_bank3, heaps_and_stack_in_L3_bank3_length = 8192,4)
MySDRAMHeap_space = heaps_and_stack_in_L3_bank3;
MySDRAMHeap_end = (MySDRAMHeap_space + (heaps_and_stack_in_L3_bank3_length - 4)) & 0xfffffffc;
MySDRAMHeap_length = MySDRAMHeap_end - MySDRAMHeap_space;
2. Declare to VDK that you want to use a user heap
In the VDK kernel tab in the Heaps node right click onto New Heap. The name of the heap is specific to VDK so you can choose what you want and does not have to match the heap table. The heap ID is the user ID specified as the third member of the heap_table_t structure for the heap that you are interested in.
Doing this will show your user heap in the list of heaps that you can allocate from in the kernel tab. You can also use this heap in VDK APIs that take a heap with the k prefix.