Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
19 years ago

Manually 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?

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    No, I've tried both. I think that in pdf it is a bug, and it should be text. I've tried .txt, .text, without .something, and have same errors.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I haven't looked at this, but I think that "Nios2 Forum" should have something more suitable to address your issue.