Altera_Forum
Honored Contributor
19 years agoManually Assigning C Code to a Specific Memory Section
Hi, everybody.
I want to place some code, that is critical in fast onchip memory. I've read in "Nios II Software Developer's Book" from Altera's site this: "Within your program source code, you can specify a target memory section for a specific piece of code. To do this action in C or C++, you can use the section attribute. The following code shows placing a variable foo within the memory named on_chip_memory, and the function bar()in the memory named sdram. Use the extension .txt for code, and the extension .rodata for read-only data or .rwdata for read-write data. Example: Manually Assigning C Code to a Specific Memory Section /* data should be initialized when using the section attribute */ int foo __attribute__ ((section (".on_chip_memory.rwdata"))) = 0; void bar __attribute__ ((section (".sdram.txt"))) (void) { foo++; }" I'm using Nios II IDE, have onchip memory generated in SOPC Builder named onchip_memory_0, and I want to place my interrupt service routine in this memory. For program, read only, heap, stack, and read/write memory in system description in Nios II IDE I choose sram. I can define variable in this memory like this: int foo __attribute__ ((section (".onchip_memory_0.rwdata"))) = 0; ,but if I try to place there function like this: void function __attribute__ ((section (".onchip_memory_0.text"))) (void) { foo++; } compiler returns errors: 1) parse error before "(" ,and 2) size of function isn't known What's happening? What must I do? Have I write my own linker script instead of automatically written by Nios II IDE, or something?