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++
12595 Discussions

Tutorial for C/C++ programming

Honored Contributor II



I wanted to know how to use C or C++ with my FPGA.  

I already know those languages but i have no idea how to use them to control my hardware. I know that there is a file called "system.h" in which there is plenty of information about the components, but i really don't know how to use them. 


I'm looking for something quite simple, indeed this is for my student project which is not suppose to be very complicated. I only need to know the basics (but not too basic :D). 


Does anyone have any tutorial or information to help me ? 


Thank you !
0 Kudos
5 Replies
Honored Contributor II

how about my tutrial 


concept of this document is to understand NiosII as quick as possible. 

try it. 

and if you like it, tell me on this page.
0 Kudos
Honored Contributor II

Thank you for your answer. 

However, i already know how to use Nios II, i have succeeded to upload code (that i found online) to my board and it worked. 


What i don't understand is how the C code for FPGAs works, i really don't know how to make it control my hardware.
0 Kudos
Honored Contributor II

all right then, next step. 


how about this document? 


this document tells you how to assign your VerilogHDL to your Qsys(SOPC). 

then you can send value from C-code into your Verilog code. 

after your Verilog gets value, you can do anything with the value in Verilog HDL. 


is that what you want?
0 Kudos
Honored Contributor II

Well, this is not really what i want. I will try to be more specific : 


I launched some examples that i found in the following directory : DE2_demonstrations\DE2_NET\hello_led_0 (from a resource pack by Altera) 


I tried to figure out what does this program do and how it does it. 

Well, this program prints text on the LCD screen and lights some green leds thanks to buttons. 


After a few tests i isolated the function which is responsible to light the green leds when i press the key buttons. Here is its code : 


void init_button_irq() { /* Enable all 4 button interrupts. */ set_pio_irq_mask(BUTTON_PIO_BASE, BUTTON_INT_MASK); /* Reset the edge capture register. */ set_pio_edge_cap(BUTTON_PIO_BASE, 0x0); /* Register the interrupt handler. */ alt_irq_register( BUTTON_PIO_IRQ, NULL, (void*)handle_button_interrupts ); }  


The questions that i am asking to myself are : 


what are those functions :  

- set_pio_irq_mask() 

- set_pio_edge_cap() 

- alt_irq_register() 


I know that BUTTON_PIO_BASE, BUTTON_INT_MASK, BUTTON_PIO_IRQ can be found in the file "system.". However i really don't know what are they used for in this example (and even anywhere else). 



This is the kind of things that i want to learn and understand for my project. Do you have any idea where i could find that kind of knowledge ?
0 Kudos
Honored Contributor II

all right I answer as far as I can. 


- set_pio_irq_mask 

I don't know what is this function. 

but I know what does it do. 

this function sets value on the address of PIO. 

(page 10-7) 

it masks which IO should / should not be enable for interrupt. 

for example 0x01 is set, which means bit0 of PIO is enable as interrupt pin. 


- set_pio_edge_cap 

this function set if the interrupt should be LEVEL interrupt or edge captured interrupt. 

if it set 0 which means this interrupt is LEVLE interrupt ( I'm not sure if it is opposed).  


- alt_irq_register 

I'm sure you can find document. 

(on page 14-40) 

register the interrupt on your system. and specify function which is called when the interrupt is occurred. 


is that answer what you want?
0 Kudos