Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12748 Discussions

Variables in different physical memory

Altera_Forum
Honored Contributor II
1,271 Views

Im looking to define some variables (large arrays)such that one resides in sdram and the other in separate sram so that my custom peripheral can do work on one while i do work on the other array with Nios. 

 

How can i direct the compiler to do this, i cant find anything in the manual
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
542 Views

Instead of declaring arrays, declare pointers, and initialize them with an address (which might be defined in system.h, or you might add offsets to the values from system.h). 

 

If one memory is already where your .rodata and .rwdata are being placed, then you only need a pointer for the other one. 

 

Example - if you are running code from sdram, your compiler setting are probably also placing .rwdata in the sdram as well, so just set a pointer to the SRAM like so: 

 

alt_u32 * my_sram = ONCHIP_MEMORY_0_BASE ; 

 

Now you can use my_sram[i] as an array of 32 bit values. (Assuming ONCHIP_MEMORY_0_BASE is defined in your system.h). 

 

 

Or if your code and .rwdata are in the onchip SRAM, then instead setup a pointer to the base address of the SDRAM. 

 

\chuck
0 Kudos
Altera_Forum
Honored Contributor II
542 Views

Ok, thanks I will do that. I guess what i was after was a way of getting the compiler to do it so I didnt have to take care of allocating the memory and all the problems that will happen if I end up overwriting something i shouldnt.

0 Kudos
Altera_Forum
Honored Contributor II
542 Views

I imagine that getting the compiler to do it would involve something like: 

1. declare/setup an extra data segment, in addition to rwdata or bss 

2. specify that certain variables should use that segment instead. 

 

I can't even begin to guess at how to do either, if it's even possible. 

 

\c
0 Kudos
Reply