XBlock_Scripting - david-macmahon/wiki_convert_test GitHub Wiki

Xilinx Documentation (Extracted from System Generator for DSP Reference Guide, ver 10.1) media:XBlock doc.pdf

Creating an xBlock-Scripted Subsystem from Scratch

1. Follow the example 'MACC in a Masked Subsystem' (p. 480) in the above document to create an xBlock script. Save it as a .m file. (NOTE: To avoid naming conflicts with existing Simulink scripts, ensure that xBlock script names are of the form *_init_xblock.m.) The xBlock() function that adds Xilinx blocks to the design takes the block parameters as the second argument. It should be of the form struct('<param1'>, '', '', '', ...). To find the names of the parameters that you would like to change, select a block of the same type from any open design, or drag and drop a new block from the Simulink Library Browser. Once this block is selected, go to the MATLAB Command Window and run get_param(gcb, 'ObjectParameters'), where gcb stands for 'get current block', to get a list of all the parameter names. Note that the parameter names listed may not be obvious matches to what you see in the block configuration dialog box for the block you are trying to configure - to figure out the names and expected values, the easiest thing to do is to drag a new block in, configure it the way you want it to be in the final script, and run get_param(gcb, '<param_name>'), where <param_name> is one of the names from the list of parameters.

2. Drag a 'Subsystem' block from Simulink/Ports & Subsystems and drop it in your design. Rename it to your choice of block name. Right click on it and click 'Create Mask'. In the Mask Editor box that opens up, go to the 'Parameters' tab, click the 'Add parameter' button, enter your message in 'Prompt' and the name of the variable corresponding to that parameter in 'Variable'. Go to the Initialization tab and enter the following:

   config.source = str2func('<xblock_function_name>');     config.toplevel = gcb;    config.depend = {'<xblock_script_name>'};     xBlock(config, {<param_var1><param_var2>, ...});

Hit OK.

3. Double-click the subsystem, input the parameter values of your choice, and hit OK. The block should now redraw itself using the initialization script.

xBlock-izing an Existing Subsystem

Xilinx provides a utility function xlsub2script that generates an xBlock script from an existing subsystem. It does an imperfect job - for instance, it does not support signal routing using 'From' and 'Goto' tags.

Debugging and Troubleshooting

Link Error

xlsub2script(gcb) ??? Input argument "c_output" is undefined.

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xlsub2script.p>create_one_block at 335

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xlsub2script.p>xlsub2script at 58 % xlsub2script(subsystem, options);

Cause: This cryptic error occurs when the command 'xlsub2script(gcb)' is run on a block that is still library-linked

Fix: Break the link and continue.

Mask still uses {get,set}_param

??? Error using ==> create_maskinit at 748 untitled1/c_to_ri has Simulink function calls, such as gcb, get_param, set_param, add_block. Please remove these calls and run xlsub2script again or you can pick a different subsystem to run xlsub2script.

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xlsub2script.p>standard_flow at 933

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xlsub2script.p>xlsub2script at 76

Cause: The mask initialization dialog calls a function that invokes simulink mask scripting. The check is fully-recursive

Fix: Delete all the offending mask initialization code. Commenting out is not sufficient because xlsub2script checks by string-parsing, rather than actually calling the function in a 'try/catch'.

Subsystem uses "goto" and "from" tags

??? xlsub2script(gcb)Error using ==> check_goto at 922 You have the following Goto blocks, please modify the model to remove them and run xlsub2script again:

'Modelname/Goto82'

Error in ==> /tools/xilinx/11.5/DSP_Tools/lin64/sysgen/bin/xlsub2script.p>xlsub2script at 71

Cause: xlsub2script is not equipped to infer connectivity from the tags.

Fix: Re-draw the subsystem without the tags.

Stray Wires

??? Error using ==> create_one_signal at 610 Invalid Simulink object handle.

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xlsub2script.p>create_one_assign_out at 279

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xlsub2script.p>create_assign_outs at 265

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xlsub2script.p>standard_flow at 1019

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xlsub2script.p>xlsub2script at 76

Cause: xlsub2script is trying to infer connectivity of a wire that has no endpoint

Fix: Remove stray wires and re-run the script

Error with C++ vector library

??? Error using ==> xl_script_globals vector::_M_range_check

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xl_script_callbacks.p>xSignal_addDst at 836

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xl_script_callbacks.p>xl_script_callbacks at 15

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/@xSignal/subsref.p>subsref at 68

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xl_script_callbacks.p>connect_port_from_cell at 979

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xl_script_callbacks.p>xBlock_portMap at 938

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/xl_script_callbacks.p>xl_script_callbacks at 13

Error in ==> /tools/xilinx/11.4/DSP_Tools/lin64/sysgen/bin/@xBlock/xBlock.p>xBlock at 520

Error in ==> fft_biplex_real_4x_init_xblock at 118 xBlock( struct('name', 'bi_real_unscr_4x', 'source', 'casper_library_ffts_internal/bi_real_unscr_4x'), ...

Cause: Unknown! Occurs when trying to instantiate a bi_real_unscr_4x block from the casper_library inside an xBlock-ed fft_biplex_real_4x, possibly for other blocks

Fix: ????

Command line testing

Creating library blocks

1. Draw a block from command line

2. Mask the subsystem

3. Add all parameters

4. Add initialization script and block documentation

  See #Create`` ``a`` ``library`` ``block

Examples

Simple block

Create a block from scratch

Create a block from an existed non-xBlock


  1. Clear all mask initialization script containing {get,set}_param from the target block and all its sub-blocks (See Mask still uses {get,set}_param )

  2. Select target block. In command line, enter

      -
        \>\> xlsub2script(gcb)
    
  3. This should give you a *.m file. Change the file name and function name to desired form. (See #Use)

  4. In most cases you need to edit this file according to original _init.m file to make this new xBlock functionally the same with the old block.

See also the documentation of function xlsub2script in XBlock_doc.pdf

xBlock within an xBlock

Library block within an xBlock

Create a library block

Block Annotation

Drawing top-level systems

The xBlock functions prefer to draw subsystems, not the top-level system. So they cannot be easily used to do things like automatically drawing test-benches, which requires drawing at the highest level of the system. At least in MATLAB 2012b, xBlock scripting will enable you to generate all the blocks you need, but the behavior of the xSignal() function call is quite strange. The simulink drawing functions (add_line, reuse_line, etc.) remain the only way to connect up the blocks of the top-level system. Note that for the top level, there's no problem with combining the two scripting methods.

⚠️ **GitHub.com Fallback** ⚠️