(Original topology) How to declare an array on ssram? (SOC) (nio ii)

Source: Internet
Author: User

Abstract
De2/DE2-70 has a lot of memory, there are onchip memory, ssram, SDRAM, Flash, each has a lack of memory, how can we place the change data or array on a specific memory?

Introduction
Use environment: Quartus II 8.0 + NiO II eds 8.0 + DE2-70 (Cyclone II ep2c70f896c6n)

In the de2 Dev online forum, the netizen Mithril asked the following questions:

When you set up the system, the program and data are stored in ssram, SDRAM, and Flash, and the program and data in the system are all stored in the SDRAM, in this case, how do I place a notice column on ssram?

At the niosii eds, we can only make the following settings to see which memory to use:

There is no way to specify the memory in which the array or variable data table is established by using a set method, but we know that onchip memory and ssram are the fastest, if you create common change data or sequence columns on the onchip memory or ssram, the speed of the entire system of the niosii will be helpful, but how do I create an array on ssram?The answer is to use the attribute provided by GCC..

Solution

Hello_world.c/C

1 /*  
2 (C) oomusou 2008 Http://oomusou.cnblogs.com
3
4 Filename: hello_world.c
5 Compiler: niosii eds 8.0/ANSI C
6 Description: Demo how to declare array in ssram
7 Release: 11/11/2008 1.0
8 */
9
10 # Include < Stdio. h >
11
12 // Declare array in ssram
13 Int IA [ 3 ] _ Attribute _ (Section ( " . Ssram " )));
14
15 Int Main (){
16 Int I;
17
18 // Write to array
19 For (I =   0 ; I <   3 ; ++ I)
20 IA [I] = I;
21
22 // Read from Array
23 For (I =   0 ; I <   3 ; ++ I)
24 Printf ( " % D \ n " , Ia [I]);
25
26 Return   0 ;
27 }
28

13 rows

Int IA [ 3 ] _ Attribute _ (Section ( " . Ssram " )));

Use _ attribue _ to declare array Ia [] on ssram.

When you see this, you will certainly ask,Must I declare it outside main?On the source card of Altera, the system uses the niosii software developers's Handbook p.6-42.Assigning code and data to memory partitionsThe following statements are described in this example:

Within your program source code , You can specify a target memory section for each piece of code. In C or C ++ , You can use the section attribute. This attribute must be place in a function prototype , You cannot place it in the function declaration itself.

That is, it must be placed in the function prototype area before Main (). It cannot be placed in the function area.

Of course, it cannot only be used as an array. Changes and functions can all be placed in the specified memory using attribute.

Another question is, how do I know which memory sections can be stored?There are two methods:

Method 1:
View niosii EDS

The preceding column indicates the section name available for the reporter.

Method 2:
View linker script

\ De2_70_nios_10_attribute \ Software \ hello_world_0_syslib \ debug \ system_description \ generated. x

Generated. X is very long. I only accept the section-related part.

. Onchip_mem:
{
Provide (_ alt_partition_onchip_mem_start = Absolute (.)) ;
* (. Onchip_mem. onchip_mem .*)
. = Align ( 32 / 8 ) ;
Provide (_ alt_partition_onchip_mem_end = Absolute (.)) ;
}> Onchip_mem

Provide (_ alt_partition_onchip_mem_load_addr = Loadaddr (. onchip_mem )) ;

. Sdram_u1:
{
Provide (_ alt_partition_sdram_u1_start = Absolute (.)) ;
* (. Sdram_u1. sdram_u1 .*)
. = Align ( 32 / 8 ) ;
Provide (_ alt_partition_sdram_u1_end = Absolute (.)) ;
_ End = Absolute (.) ;
End = Absolute (.) ;
_ Alt_stack_base = Absolute (.) ;
}> Sdram_u1

Provide (_ alt_partition_sdram_u1_load_addr = Loadaddr (. sdram_u1 )) ;

. Sdram_u2:
{
Provide (_ alt_partition_sdram_u2_start = Absolute (.)) ;
* (. Sdram_u2. sdram_u2 .*)
. = Align ( 32 / 8 ) ;
Provide (_ alt_partition_sdram_u2_end = Absolute (.)) ;
}> Sdram_u2

Provide (_ alt_partition_sdram_u2_load_addr = Loadaddr (. sdram_u2 )) ;

. Ssram:
{
Provide (_ alt_partition_ssram_start = Absolute (.)) ;
* (. Ssram. ssram .*)
. = Align ( 32 / 8 ) ;
Provide (_ alt_partition_ssram_end = Absolute (.)) ;
}> Ssram

Provide (_ alt_partition_ssram_load_addr = Loadaddr (. ssram )) ;

. Cfi_flash:
{
Provide (_ alt_partition_cfi_flash_start = Absolute (.)) ;
* (. Cfi_flash. cfi_flash .*)
. = Align ( 32 / 8 ) ;
Provide (_ alt_partition_cfi_flash_end = Absolute (.)) ;
}> Cfi_flash

The preceding section name indicates that you can use the reporter's section name. In fact, the section name shown by niosii EDS is also the root linker script.

Download the full program
De2_70_nios_10_attribute.7z

Conclusion
In previous PC programming, we couldn't specify the memory where an array, variable, or function is stored, but in de2/DE2-70, we recommend that you use the notebook to improve the efficiency of programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.