Back | Next | Contents
My First SoC - Simple Hardware Adder
Here we walk through the steps to create simple Avalon MM Components that will help us interface with our simple adder.
We want a way to write and read data to our simple adder. If you recall, the adder has only 3 ports - 2 inputs (a
and b
) and 1 output (sum
). For this, we will create custom Input/Output (IO) components that will enable us to read them.
Hang on, this is so basic, surely there should be something readily available to help us do this? There is and that is where the IP Catalog comes in. This is what you see on the left hand side of Platform Designer. There are so many ready to use components that you can just drag and drop into your design.
Normally that's what you would use because they are tried and tested. In fact, there is one module that is designed for exactly this purpose and you may have seen other examples online using it. It's called the Parallel I/O peripheral and can be found as shown:
But there are few reasons I'm not using this one:
- Many examples online already demonstrate how to use this component. In fact, it's demonstrated in the GHRD also when you open it. You can use it to write to the onboard LEDs.
- The parallel IO only goes up to 32 bits and not more. Our adder takes 64 bits.
- Let's build our own components, it's more fun! :)
Now let's look into how we'll write these. Since we have 2 inputs to our adder and one output, we'll need 2 different kinds of components. One which will allow us to write to and one which will allow us to read from. Let's look at these now.
Note that when we say output
for a custom component, we are referring to the direction of the port that is actually used in the component itself. So an output
component will be connected to the input
s of our adder and vice versa.
Looking at our interface requirements for Avalon Memory Map, we will require the following ports:
- clk
- reset
- write - Flag to indicate whether we are writing or not.
- writedata - Actual data that is passed.
- pio_out - The port that connects to one of the inputs of our adder.
With this, I have come up with the following module which serves our purpose:
module pio64_out (
input logic clk,
input logic reset,
input logic avs_s0_write,
input logic [63:0] avs_s0_writedata,
output logic [63:0] pio_out
);
always_ff @ (posedge clk) begin
if (reset) begin
pio_out <= '0;
end else if (avs_s0_write) begin
pio_out <= avs_s0_writedata;
end else begin
pio_out <= pio_out;
end
end
endmodule
Save this in our working directory:
cd $DEWD
mkdir -p ip/pio64
cd ip/pio64
vim pio64_out.sv
# Save the file here.
Similarly, we will need the following ports for our input module:
- clk
- reset
- read - Flag to indicate whether we are reading or not.
- readdata - Actual data to return.
- pio_in - The port that connects to the output of our adder.
With this, we have the following design:
module pio64_in (
input logic clk,
input logic reset,
input logic avs_s0_read,
output logic [63:0] avs_s0_readdata,
input logic [63:0] pio_in
);
always_comb begin
if (avs_s0_read) begin
avs_s0_readdata = pio_in;
end else begin
avs_s0_readdata = 'x;
end
end
endmodule
Save this in our working directory:
cd $DEWD
cd ip/pio64
vim pio64_in.sv
# Save the file here.
Back in Platform Designer, click on the New Component...
to start the wizard and fill in the details:
Now click on the tab Files
and click on Add File...
and select pio64_out.sv
. Click on Analyze Synthesis Files
and if there are no errors, it should complete successfully.
Click on Signals & Interfaces
and make the following changes:
-
Rename
avalon_slave_0
topio64_out
. -
Change the
Type
in the dropdown toConduit
. -
Change the
Associated Reset
in the dropdown toreset
. -
Click on the signal
pio_out [64] readdata
in the left hand menu and type inexport
in theSignal Type
field. It should like the image below: -
Click on
s0
in the left hand menu and changeAssociated Reset
toreset
. It should now look as follows: -
Save the component with
Ctrl + s
and hitFinish...
.
Create a new component for the input as well. Repeat the same steps as above but replace out
with in
to keep the naming convention consistent. Sharing what my screens look like:
And that creates our custom components! In the next section we'll start wiring everything together.
Next | Wiring the Components
Back | Primer on Avalon MM
My First SoC - Simple Hardware Adder | Table of Contents