(Original plugin) How to Use the niosii c2h compiler? (IC design) (de2) (nio ii) (Quartus II) (FPGA builder) (C/C ++) (c2h)

Source: Internet
Author: User

Abstract
Due to the low computing speed of embedded CPUAlgorithmIn this case, hardware acceleration may fail to meet real-time requirements. In this case, hardware acceleration can be implemented by using OpenGL or VHDL. In order to reduce the time to market, Altera provides c2h compiler, allowing you to directly convert program libraries that use the simplified C language into hardware.

Introduction
Environment: US us II 7.2 SP1 + kernel Core IP 7.2 SP1 + de2 (Cyclone II ep2c35f627c6)

What is c2h? It is a programming component of (C to hardware) that can change your original programming language into a hardware. For more information, please refer to the technical examination to quickly develop a hardware design for the single chip system and the ansi c program function) (C/C ++) (News). If you are interested in the principles behind it, I suggest you take a look at the paper of the original output table of Altera: automatic Generation of hardware accelerators with Direct Memory Access from ANSI/ISO Standard C functions. This article mainly discusses the problems that c2h may encounter.

Build a hardware system
Step 1:
Create the us II Community case

Please refer to \ de2_demonstrations \ sopc_builder \ reference_design \ de2_nios in de2 CD to hard drive (or pull from http://www.terasic.com/downloads/cd-rom/de2/), do not forget to cancelUniquenessIf you want to build your own system from the beginning to the end by using the systems builder, please refer to the previous article) how can I build a system for running μC/OS-II on de2 with the help of the system? (IC design) (de2) (Quartus II ).

Note that the current sample of Youjing is developed by Quartus II 6.0 and 7.1. If you use a later version such as Quartus II 7.2, after the de2_nios case is opened,Enable the blockchain with a new version of the 7.2 format and save the code as a later version, because c2h will change the C program to the sopc m component of the systems builder, the format difference may cause c2h compiler to fail to renew successfully..

Build the niosii Compiler
Step 1:
Establishing the niosii proposal case

Use the hello World template to create an example and use the following program in hello_world.c.

1 /*  
2 (C) oomusou 2008 Http://oomusou.cnblogs.com
3
4 Filename: hello_world.c
5 Compiler: niosii gcc
6 Description: Demo how to use c2h Compiler
7 Release: 04/22/2008 1.0
8 */
9 # Include < Stdio. h >
10
11 Int Sum_elements ( Int   * List, Int Len ){
12 Int I;
13 Int Sum =   0 ;
14
15 For (I =   0 ; I < Len; I ++ )
16 Sum + =   * List ++ ;
17
18 Return SUM;
19 }
20
21 Int Main (){
22 Int IA [] = { 1 , 2 , 3 , 4 , 5 };
23 Int Sum = Sum_elements (IA, 5 );
24
25 Printf ( " % D " , Sum );
26 }

This program is very simple. I just want to add each element in the array, so I will not do more solutions for the content, wait a moment and we will try to use c2h to accelerate the sum_elemenet function with hardware.

At present, you can check whether the debugging result of the program niosii is successful, it indicates that the configuration of the worker in the FPGA builder is problematic, and the hardware won't be successful.

Step 2:
Change the specified function to hardware

Now we want to use the hardware interface line of the sum_elements () function. The following example selects accelerate with the nio ii c2h compiler for sum_elements.

After the selection, there will be more c2h settings below. Select "build software and generate system" and "use hardware accelerator in place of software implementation. flush data cach before each call 』.

The last step is to re-build the entire project. It will take a long time for you to fully check the configuration of your PC hardware. So far, the new system has been created.

Step 3:
Return to Quartus II

Return to Quartus II license. If you have a complete license, it will be fine. For example, if I do not have a complete license, it will be cracked, only de2_nios_time_limited.sof will be generated, and then programmer will be used to import this sof into de2. The following reminder will appear, which can be ignored as determined.

After the programmer program enters, the following program appears.

Step 4:
Back to niosii EDS

As with the niosii runtime, sum_elements () will be written in the hardware.

Remark
There are several special points for discussion:
1. in the above step, in the c2h selection scheme, I used "build software and generate system builder" instead of "Build Software, generate system builder, and run Quartus II Compilation ", the reason is that if you have a complete license, you can build de2_nios.sof, then no problem, back to Quartus II, You can naturally Use programmer to import de2_nios.sof into de2, but because we are a cracked version, de2_nios_time_limited.sof is built, in this case, the original programmer program into de2 is still de2_nios.sof. Many people think that c2h cannot be used because there is no license.

2. if you want to switch back to your physical servers in the future, you only need to select "use software implementation" as follows. Why is this amazing, as long as this is done, the hardware can be switched into the automatically generated generation of hardware accelerators with Direct Memory Access from ANSI/ISO Standard C functions.

3. In order to prove that this is a hardware, after the system is opened with the help of the system, it is discovered that the custom component named accelerator_hello_world_0_sum_elements_managed_instance generated by c2h is missing.

4. Maybe you may be wondering if other functions are called in the function, can hard-body acceleration be implemented? I changed the program to the following:

1 /*  
2 (C) oomusou 2008 Http://oomusou.cnblogs.com
3
4 Filename: hello_world.c
5 Compiler: niosii gcc
6 Description: Demo how to use c2h Compiler
7 Release: 04/22/2008 1.0
8 */
9 # Include < Stdio. h >
10
11 Int Func ( Int I ){
12 Return I +   2 ;
13 }
14
15 Int Sum_elements ( Int   * List, Int Len ){
16 Int I;
17 Int Sum =   0 ;
18
19 For (I =   0 ; I < Len; I ++ )
20 Sum + = Func ( * List ++ );
21
22 Return SUM;
23 }
24
25
26 Int Main (){
27 Int IA [] = { 1 , 2 , 3 , 4 , 5 };
28 Int Sum = Sum_elements (IA, 5 );
29
30 Printf ( " % D " , Sum );
31 }

Call func () in sum_elements (), and both functions can perform hardware acceleration.


Download the complete program
De2_nios_c2h.7z
De2_nios_c2h_function_call.7z

Conclusion
Through c2h, you can quickly use hardware acceleration without changing the development process of your development environment, which is very helpful for short time to market. This allows you to develop a hardware environment without having to understand the hardware description. So the C language can only develop the release and release of the software? Through c2h compiler, the C statement can also be used to develop hardware !!

See also
Chip Design (C/C ++) (News)
(Original) how to build a system on de2 run μC/OS-II with the system? (IC design) (de2) (Quartus II)
(Original) how to crack Quartus II 7.2 SP1? (IC design) (Quartus II) (nioii)

Reference
Automatic Generation of hardware accelerators with Direct Memory Access from ANSI/ISO Standard C functions
Niosii software developer's Handbook

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.