Forum Discussion
Altera_Forum
Honored Contributor
14 years ago --- Quote Start --- There are multiple ways to do this depending upon your HDL module. You can include your own module as a custom instruction in the SOPC Builder, as you've suggested. A simpler method would be to interface with the PIO ports. This would require instantiating your module in the high-level HDL file in Quartus, then connect your Nios2 PIO ports to your module. For example, if you have a Verilog module that outputs a single number as a result of two inputs, simply generate 3 PIOs in your SOPC builder and connect. Your Nios program would write a number to each output PIO, then read from the input PIO after a minimum timing requirement. -J --- Quote End --- Hi gaudetteje, I am trying your method of using 3 PIOs in SOPC Builder to do a simple calculation in hardware from numbers coming from NIOS. I initially tried to do a sum of products on two arrays of integer but I could not get anywere and so I decided to start with a basic addition of two numbers. See my original forum post: http://www.alteraforum.com/forum/showthread.php?t=29030 So now my verilog module is:
module add_two (
// Inputs
line_1_in,
line_2_in,
// Output
result_out
);
//Port Declarations
// Inputs
input line_1_in; // 8 bit value
input line_2_in;
// Output
output result_out; // assume 8 bit
assign result_out = line_1_in + line_2_in ;
endmodule
I've declared the input/output ports as in my other post, and added these lines in the C code:
int line1 = 3;
int line2 = 4;
int store_val;
volatile int * line_1_ptr = (int *) 0x08200000; // Port_in_1 address
volatile int * line_2_ptr = (int *) 0x08200010;// Port_in_2 address
volatile int * result_back_ptr = (int *) 0x08200020;// Port_out_result
*line_1_ptr = line1;
*line_2_ptr = line2;
store_val = * result_back_ptr;
Questions: - How do I instantiate that add_two.v module in the top level .v file? - How I do make the add_two.v module accept the data from the NIOS processor through the PIOs and return a value again? - Is the use of pointers correct? I saw in another posts people suggesting to use IORD/IORW but I am not too sure how to do that. Any help is appreciated.