Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20688 Discussions

sopc builder custom component and passing parameters to VHDL package

Altera_Forum
Honored Contributor II
1,128 Views

I have written a custom SOPC builder component in VHDL. 

Right now I have SOPC builder auto-generating a package 

that contains custom type definitions that are used throughout my 

custom SOPC builder component. These type definitions are based on the settings input by the user in the SOPC builder GUI. 

 

This package is then included in each of the VHDL 

files of my custom component using the construct: 

 

library work; 

use work.custom_package.all; 

 

Now, the problem with this formulation is that I can only have one instance 

of the component in my sopc system. 

 

Does anyone have a workaround for this, where I can generate multiple 

unique package files, each one associated with a particular instantiation of my custom VHDL component? 

 

In a perfect world, I might be able to use VHDL 2008 constructs which allow for passing custom types as generic parameters on a component. 

Quartus and SOPC do not support this. 

 

Another intractable solution would be to remove all the custom types 

which are used all throughout my custom component and use generic 

parameters and std_logic_vectors types 

all the way through the project. At this point the component is too complex to try and remove all of the custom types and replace them with standard types (whose bitwidths, etc would be set via generics). 

 

A third undesirable workaround would involve auto-generating every single 

VHDL file used in my component and passing the name-decorated version of my custom package to a VHDL generation script which could then generate a customized, name-decorated version of each VHDL file needed for my component.  

This is kind of a nasty and inelegant way of doing what I want.  

 

What I would like to be able to do is have two instances of my custom 

component in my sopc system. Let's call them 

Custom1 and Custom2. My custom_component_hw.tcl script could then 

generate two unique VHDL packages associated with each instantiation. 

It would generate Custom1_Package.vhd and Custom2_Package.vhd. 

 

Is there a way to associate Custom1_Package.vhd with one instance of all of my custom VHDL source files and associate Custom2_Package.vhd with a 

second instance of them. I would prefer to not have to write a complex code generator script to allow for this.
0 Kudos
5 Replies
Altera_Forum
Honored Contributor II
384 Views

What kind of stuff is defined in the custom_package? is it full of constants, that define subtypes? 

 

could you not just define unconstrained types and then constrain them using generics on the entity? 

 

If its more complicated than than, cant you put the setup information into a record type, and then have an array of records with a generic on the component to select which setup to use?
0 Kudos
Altera_Forum
Honored Contributor II
384 Views

Here is an excerpt from the package: 

 

-- Constants defining the maximum resolutions 

constant MAX_INPUT_HORIZ_RESOLUTION : positive := 320; 

constant MAX_INPUT_VERT_RESOLUTION : positive := 240; 

constant MAX_OUTPUT_HORIZ_RESOLUTION : positive := 640; 

constant MAX_OUTPUT_VERT_RESOLUTION : positive := 480; 

constant MAX_HORIZ_RESOLUTION : positive := Maximum(MAX_INPUT_HORIZ_RESOLUTION,  

MAX_OUTPUT_HORIZ_RESOLUTION); 

constant MAX_VERT_RESOLUTION : positive := Maximum(MAX_INPUT_VERT_RESOLUTION, MAX_OUTPUT_VERT_RESOLUTION); 

 

-- Ensure that horizontal and vertical coordinates are capable of representing the width  

-- and height as well as internal coordinates, with a signed representation. 

constant HORIZ_COORD_BITS : positive := (Min_Bits(MAX_HORIZ_RESOLUTION) + 1); 

constant VERT_COORD_BITS : positive := (Min_Bits(MAX_VERT_RESOLUTION) + 1); 

 

-- Number of fractional bits used in coordinate representation 

constant COORD_FRACTION_BITS : positive := 2; 

 

-- Type definitions for raw coordinates and a point in Cartesian space 

subtype Horiz_Coord is sfixed((HORIZ_COORD_BITS - 1) downto -COORD_FRACTION_BITS); 

subtype Vert_Coord is sfixed((VERT_COORD_BITS - 1) downto -COORD_FRACTION_BITS); 

type Point is record 

x : Horiz_Coord; 

y : Vert_Coord; 

end record; 

 

Do you think I can change this to work as an array of record types? Even when the custom types are used to define ports on components?
0 Kudos
Altera_Forum
Honored Contributor II
384 Views

easily. 

 

Just forget about the subtype. Add the sizing on the actual port and have Horiz/vert_coord as separate ports, rather than the encapsulation you already tried to do.  

 

It means you will have a very long package, with a large array pre-defined, but you can then have 1 package that covers everything. Define a generic on the component to pick the array element (that selects all of the sizing), and away you go. Define some functions to tidy it all up to make it even better. 

 

Because all of your constants are actually only derived from 4 source constants, you will only need 4 elements in the record. 

 

type setup_t is record MAX_INPUT_HORIZ_RESOLUTION : positive; MAX_INPUT_VERT_RESOLUTION : positive; MAX_OUTPUT_HORIZ_RESOLUTION : positive; MAX_OUTPUT_VERT_RESOLUTION : positive; end record setup_t; type SETUP_ARRAY_t is array(natural range <>) of setup_t; constant SETUP_ARRAY : SETUP_ARRAY_t := ( (320, 240, 640, 480), (768, 1024, 1024, 1280), ....etc ); --define functions to generate all the bit numbers --then on instantiation entity my_ent is generic ( SETUP_SELECT : natural ); port ( Horiz_chord : out sfixed( h_high(SETUP_SELET) downto h_low(SETUP_SELECT) ); --h_high is a function that indexes into the SETUP_ARRAY )
0 Kudos
Altera_Forum
Honored Contributor II
384 Views

Generating this kind of package script from SOPC builder means that I would need to get settings from each of the instances that I have instantiated 

and then generate a single package file to support all the entered values. 

 

Is there any way to do this in the current TCL framework used for SOPC builder? I mean within the _hw.tcl file? 

 

As far as I know, I can only get values from the component that is currently being edited within the SOPC builder GUI, and then generate VHDL accordingly. How can I get user set parameters from all instances of a given component type? 

 

In other words: 

I set all of the settings on my custom_component1 GUI. 

I then instantiate custome_component2 and set its parameters from within the GUI. 

Now how do I take the settings from each of these instances to generate the package? I am not sure if there is any way to do this given the limited functionality of the SOPC builder TCL API.
0 Kudos
Altera_Forum
Honored Contributor II
384 Views

i have another question..after i defined sopc builder component and also compiled successfully in the quartus software,but connot find in the nios ide(system library)

0 Kudos
Reply