Products & Services Solutions Academia Support User Community Company

Specifying Block Implementations and Parameters in the Control File

Overview

The coder provides a default HDL block implementation for all supported blocks. In addition, the coder provides selectable alternate HDL block implementations for several block types. Using selection/action statements (forEach or forAll method calls) in a control file, you can specify the block implementation to be applied to all blocks of a given type (within a specific modelscope) during code generation. For many implementations, you can also pass in implementation parameters that provide additional control over code generation details.

You select HDL block implementations by specifying an implementation package and class, in the form package.class. Pass in the package.class specification and implementation parameters (if any) to the implementation argument of a forEach or forAll call, as in the following example.

config.forEach('*',...
 'built-in/Sum', {},...
 'hdldefaults.SumRTW, {'OutputPipeline', 2});

Given the package.class specification, the coder will call the appropriate code generation method. You do not need to know any internal details of the implementation classes.

Generating Selection/Action Statements with the hdlnewforeach Function

Determining the block path, type, implementation package.class specification, and implementation parameters for a large number of blocks in a model can be time-consuming. Use the hdlnewforeach function to create selection/action statements in your control files. Given a selection of one or more blocks from your model, hdlnewforeach returns the following for each selected block, as string data in the MATLAB workspace:

Having generated this information, you can copy and paste the strings into your control file.

hdlnewforeach Example

This example uses hdlnewforeach to construct a forEach call that specifies generation of two output pipeline stages after the output of a selected Sum block within the sfir_fixed demo model. To create the control file:

  1. In the MATLAB Command Window, select File > New > M-File. The MATLAB Editor opens an empty M-file.

  2. Create a skeletal control file by entering the following code into the M-file window:

    function c = newforeachexamp
    c = hdlnewcontrol(mfilename);
    
    % Set top-level subsystem from which code is generated.
    c.generateHDLFor('sfir_fixed/symmetric_fir');
    % INSERT FOREACH CALL BELOW THIS LINE.
    
  3. Save the file as newforeachexamp.m.

  4. Open the sfir_fixed demo model.

  5. Before invoking hdlnewforeach, you must run checkhdl or makehdl to build in-memory information about the model. At the MATLAB command prompt, run checkhdl on the symmetric_fir subsystem, as shown in the following code example:

    checkhdl('sfir_fixed/symmetric_fir')
    ### Starting HDL Check.
    ### HDL Check Complete with 0 errors, warnings and messages.
  6. Close the checkhdl report window and activate the sfir_fixed model window.

  7. In the symmetric_fir subsystem window, select the Add4 block, as shown in the following figure.

Now you are ready to generate a forEach call for the selected block:

  1. Type the following command at the MATLAB prompt.

    [cmd,impl,parms] = hdlnewforeach(gcb)
    
  2. The command returns the following results:

    c.forEach('sfir_fixed/symmetric_fir/Add4',...
     'built-in/Sum', {},...
     'hdldefaults.SumRTW', {});
    
    impl = 
    
        {4x1 cell}
    
    
    parms = 
    
        {1x2 cell}    {1x2 cell}    {1x2 cell}    {1x2 cell}

    The first return value, cmd, contains the generated forEach call. The forEach call specifies the default implementation for the Sum block: hdldefaults.SumRTW'. Also by default, no parameters are passed in for this implementation.

  3. The second return value, impl, is a cell array containing three strings representing the available implementations for the Sum block. The following example lists the contents of the impl array:

     impl{1}
    
    ans = 
    
        'hdldefaults.SumCascadeHDLEmission'
        'hdldefaults.SumLinearHDLEmission'
        'hdldefaults.SumRTW'
        'hdldefaults.SumTreeHDLEmission'

    See the table Built-In/Sum for information about these implementations.

  4. The third return value, parms, is a cell array containing three strings that represent the available implementations parameters corresponding to the previously listed Sum block implementations. The following example lists the contents of the parms array:

     >> parms{1:4}
    
    ans = 
    
        'InputPipeline'    'OutputPipeline'
    
    
    ans = 
    
        'InputPipeline'    'OutputPipeline'
    
    
    ans = 
    
        'InputPipeline'    'OutputPipeline'
    
    
    ans = 
    
        'InputPipeline'    'OutputPipeline'

    This listing shows that each of the Sum block implementations has two parameters, 'InputPipeline' and 'OutputPipeline'. This indicates that parameter/value pairs of the form {'OutputPipeline',val} can be passed in with any of the Sum block implementations.

    hdlnewforeach does not provide information about the data type, valid range, or other constraints on val. Some implementation parameters take numeric values, while others take strings. See Block Implementation Parameters for details on implementation parameters.

  5. Copy the three lines of forEach code from the MATLAB Command Window and paste them into the end of your newforeachexamp.m file:

    % INSERT FOREACH CALL BELOW THIS LINE.
    c.forEach('sfir_fixed/symmetric_fir/Add4',...
     'built-in/Sum', {},...
     'hdldefaults.SumRTW', {});
    
  6. In this example, you will specify the default Sum block implementation for the Add4 block, but with generation of two output pipeline stages before the final output. To do this, pass in the 'OutputPipeline' parameter with a value of 2. Modify the final line of the forEach call in your control file:

    % INSERT FOREACH CALL BELOW THIS LINE.
    c.forEach('sfir_fixed/symmetric_fir/Add4',...
     'built-in/Sum', {},...
     'hdldefaults.SumRTW', {'OutputPipeline', 2});
    
  7. Save the control file.

  8. The following code shows the complete control file:

    function c = newforeachexamp
    c = hdlnewcontrol(mfilename);
    
    
    % Set top-level subsystem from which code is generated.
    c.generateHDLFor('sfir_fixed/symmetric_fir');
    % INSERT FOREACH CALLS HERE.
    c.forEach('sfir_fixed/symmetric_fir/Add4',...
     'built-in/Sum', {},...
     'hdldefaults.SumRTW', {'OutputPipeline', 2});
    

The demo "Getting Started with Output Pipeline Commands in Control Files" gives a more detailed example of pipelining, including analysis of resulting clock rate improvements in a synthesized HDL model.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS