You can specify a list of generics to pass to the module when Vitis Model Composer compiles the model into HDL. You can extract values for these generics from mask parameters and propagated port information (for example, port width, type, and rate). This flexible generic assignment supports highly parametric modules that are customized based on the Simulink environment surrounding the black box.
The addGeneric method lets you define the
generics passed to your module when the design compiles into hardware. The following
code shows how to set a VHDL Integer generic, dout_width, to a value of 12.
addGeneric('dout_width','Integer','12');
You can set generic values based on port on propagated input port information (for example, a generic specifying the width of a dynamic output port).
A black box's configuration M-function runs at several different points
during model compilation. You can invoke the configuration function before the data
types (or rates) propagate to the black box. If you are setting generic values based on
input port types or rates, nest addGeneric the calls
inside a conditional statement that checks the value of the inputTypesKnown or inputRatesKnown
variables. For example, the width of the dout port can
be set based on the value of din as follows:
if (this_block.inputTypesKnown)
% set generics that depend on input port types
this_block.addGeneric('dout_width', ...
this_block.port('din').width);
end
You can configure generic values based on mask parameters associated with
a block box. SysgenBlockDescriptor provides a member
variable, blockName, which is a string representation
of the black box's name in Simulink. You can use
this variable to gain access the black box associated with the particular configuration
M-function. For example, assume a black box defines a parameter named init_value. A generic with name init_value can be set as follows:
simulink_block = this_block.blockName;
init_value = get_param(simulink_block,'init_value');
this_block.addGeneric('init_value', 'String', init_value);
- Copy a black box into a Simulink library or model.
- Break the link on the black box.
- Add the desired parameters to the black box dialog box.