Hi,
I am creating the mallocseg in the .tcf file, but how do I reference that name in my .c file when I want to use the MEM_alloc?
Thanks,
Will
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.
Hi,
I am creating the mallocseg in the .tcf file, but how do I reference that name in my .c file when I want to use the MEM_alloc?
Thanks,
Will
Hi Will,
You can use the heap label that's defined in the *.tcf file.
For example, the BIOS example "mem_management" (bios_5_41_11_38\packages\ti\bios\examples\evm6474\mem_management.tcf) has the following:
bios.IRAM.createHeap = true;
bios.IRAM.enableHeapLabel = true;
bios.IRAM["heapLabel"] = prog.extern("SEG0");
bios.IRAM.heapSize = 0x2000;
bios.MEM.BIOSOBJSEG = prog.get("IRAM");
bios.MEM.MALLOCSEG = prog.get("IRAM");
Then memory is allocated in the code like this (C:\ti\bios_5_41_11_38\packages\ti\bios\examples\mem_management.c):
ram[i] = MEM_alloc(SEG0, BUFSIZE, 0);
Steve
Steve,
So this is what I have so far, taken from my .tcf file which was an example for the NDK stack:
/* Create a heap in external memory */
bios.MEM.instance("DDR").createHeap = 1;
bios.MEM.instance("DDR").heapSize = 0x00200000;
bios.MEM.BIOSOBJSEG = prog.get("DDR");
bios.MEM.MALLOCSEG = prog.get("DDR");
/* Move all sections to external memory */
bios.setMemCodeSections(prog, prog.get("DDR"));
bios.setMemDataHeapSections(prog, prog.get("DDR"));
bios.setMemDataNoHeapSections(prog, prog.get("DDR"));
How would I add the heaplabel into the bios.MEM.instance("DDR")?
Would I put:
bios.MEM.enableHeapLabel = true.
bios.MEM.instance("DDR")["heapLabel"] = prog.extern("SEG0")
Steve,
So I used the DSP/BIOS config tool; went into system, MEM, and the DDR. I checked the "enter a user defined heap identifier label" and then typed in the ID label "DDR_HEAP". Attached is the .tcf portion that defines the DDR heap functionality:
/* Create a heap in external memory */
bios.MEM.instance("DDR").createHeap = 1;
bios.MEM.instance("DDR").enableHeapLabel = 1;
bios.MEM.instance("DDR").heapLabel = prog.extern("DDR_HEAP", "asm");
bios.MEM.instance("DDR").heapSize = 0x00200000;
bios.MEM.BIOSOBJSEG = prog.get("DDR");
bios.MEM.MALLOCSEG = prog.get("DDR");
Below is the code that I tries to MEM_alloc:
node.fk = (double **) MEM_alloc(_DDR_HEAP, sizeof(double *) * node.slownessArraySize, 8);
In the file, I have #include "sadarcfg.h"
I get an error " #20 identifier "DDR_HEAP" is undefined" What am I missing?
Thanks,
WIll
Sorry, I had a typo...
node.fk = (double **) MEM_alloc(DDR_HEAP, sizeof(double *) * node.slownessArraySize, 8);
It still doesn't work though.
WIll
Will,
You need to add the following line of code into your C file:
extern Int DDR_HEAP;
Steve
Steve,
Along the same lines, is it possible to create a buffer in the .tcf, which uses a variable for the buffer size (also defined in the .tcf) and then reference that variable in my .c files?
I can't get that to work. I don't see an extern call in the .tcf
Will Resnick
will Resnick said:I can't get that to work. I don't see an extern call in the .tcf
Are you referring to the extern declaration from the previous post I sent? If so, that code should be added into your *.c file, not the *.tcf file.
will Resnick said:Along the same lines, is it possible to create a buffer in the .tcf, which uses a variable for the buffer size (also defined in the .tcf) and then reference that variable in my .c files?
One way I can think of is to create/define the buffer just as you want inside your *.tcf file. Then, based on those values, you can generate a new *.c file by printing the C code you want to the file based on the values in your array in the *.tcf file. (The *.tcf file is just JavaScript ...)
Steve
Steve,
What I want to do is only have to define the size of the buffer once in my .tcf using a variable created in the .tcf and then use that variable to initialize some arrays in my .h files. I also need to reference the variable in my .c files. Is that possible? I am not sure how the print statement in the .tcf can do that?
Will
Will,
I apologize ... I jumped the gun on this one. I thought there was an easy way to print to a file from within JavaScript but it looks like there is not.
I don't see an easy way for you to do this from within the Tconf file. I'd recommend just making a common header file that defines constants for all the variables you need and then just include it in your C file. Then, you would only need to edit the header file when you want to change it.
Steve
Will,
I jumped the gun again haha ...
I found how to do it. The trick is to use Java. Since Tconf runs on top of the Rhino JS interpreter, Java APIs are supported.
I was able to put the following in my *.tcf file and it created the file 'C:/temp/foo.txt':
var file = new java.io.FileWriter("C:/temp/foo.txt");
file.write("this is a test");
file.flush();
file.close();
You can do something similar to generate the C code constants you want.
See this website for more info:
http://rtsc.eclipse.org/docs-tip/The_XDCscript_Language
Steve
Steve,
Sorry that I seem so scattered. In returning to the MEM_alloc question, even when I add the extern to my .c file, the compiler still can't find the variable DDR_HEAP.
Thanks,
Will
Steve,
Solved the issue. In the .tcf file, I needed to add an "_" before DDR_HEAP. So the line of code in the .tcf is
bios.MEM.instance("DDR").heapLabel = prog.extern("_DDR_HEAP", "asm");
Thanks,
Will