主要内容

为子系统生成可重用代码

HDL Coder™可以在模型层次结构的任何级别检测相同的原子子系统,或除了掩码参数值之外相同的原子子系统,并生成单个可重用的HDL模块实体.可重用的HDL代码生成为单个文件,并多次实例化。

为原子子系统生成可重用代码的需求

  • DefaultParameterBehavior金宝app®配置参数必须为内联.可以在命令行中使用set_paramhdlsetup函数。要在“配置参数”对话框中指定此设置,您必须具有金宝app仿真软件编码器™

    请注意

    使用hdlsetupInlineParams财产.启用该参数与设置相同DefaultParameterBehavior内联.设置InlineParams变化DefaultParameterBehavior价值可调

  • 不使用功能,如信号日志或使用块到工作空间到文件

  • 原子子系统必须是相同的,或者除了掩码参数值之外是相同的。

    • MaskParameterAsGeneric必须.有关更多信息,请参见从屏蔽子系统生成参数化的HDL代码

    • 掩码参数必须是不可调优的。代码生成器不共享具有可调掩码参数的原子子系统。

    • 掩码参数必须是标量。

    • 掩码参数数据类型必须为整数定点字长小于或等于32

    • 可调参数只能在常数获得,或比较恒定的块。

    • 端口数据类型必须匹配。

      如果更改可调掩码参数的值,则输出端口数据类型也会更改。如果其中一个原子子系统具有不同的端口数据类型,则为该子系统生成的代码也会不同。

为虚拟子系统生成可重用代码的需求

  • DefaultParameterBehavior金宝app“Simulink配置参数”必须为内联.可以在命令行中使用set_paramhdlsetup函数。要在“配置参数”对话框中指定此设置,您必须具有金宝app仿真软件编码器

    请注意

    使用hdlsetupInlineParams财产.启用该参数与设置相同DefaultParameterBehavior内联.设置InlineParams变化DefaultParameterBehavior价值可调

  • 不使用日志功能,如信号日志或块到工作空间到文件

  • 虚拟子系统必须完全相同,或者除了掩码参数值之外完全相同。

    • SubsystemReuse必须设置为原子和虚拟的

      • 设置SubsystemReuse原子和虚拟的减少人工代数错误,并提高识别相同的子系统,不管他们的拓扑结构在其余的设计。识别相似的子系统有助于资源共享。

      • 要将这些值设置为所需设置,请在MATLAB命令窗口中输入:

        hdlset_param (“myHDLModel”“SubsystemReuse”原子和虚拟的
      • 或者,您可以从顶层设置此选项HDL代码生成窗格中的。下全局设置>编码风格,你可以改变代码重用设置为所需选项。

      • 前面的命令设置SubsystemReuse选项为您的项目。若要仅为当前代码生成会话设置此选项,请输入:

        makehdl (< DUT系统>,“SubsystemReuse”原子和虚拟的
    • MaskParameterAsGeneric必须.有关更多信息,请参见从屏蔽子系统生成参数化的HDL代码

    • 掩码参数必须是不可调优的。代码生成器不共享具有可调掩码参数的原子子系统。

    • 掩码参数必须是标量。

    • 掩码参数数据类型必须为整数定点字长小于或等于32

    • 可调参数只能在常数获得,或比较恒定的块。

    • 端口数据类型必须匹配。

      如果更改可调掩码参数的值,则输出端口数据类型也会更改。如果其中一个原子子系统具有不同的端口数据类型,则为该子系统生成的代码也会不同。

为原子子系统生成可重用代码

如果您的设计包含相同的原子子系统,编码器生成一个HDL模块实体对子系统进行多次实例化。

例子

打开hdlcoder_reusable_code_identical_subsystem模型,以查看包含三个相同原子子系统的DUT子系统的示例。

HDL编码器生成一个VHDL®文件,vsum.vhd,用于三个子系统。

makehdl (“hdlcoder_reusable_code_identical_subsystem / DUT”
###为'hdlcoder_reusable_code_identical_subsystem/DUT'生成HDL。###启动HDL检查。###生成新的验证模型:gm_hdlcoder_reusable_code_identical_subsystem_vnl。###验证模型生成完成###开始VHDL代码生成'hdlcoder_reusable_code_identical_subsystem'。###在hdl_prj\hdlsrc\hdlcoder_reusable_code_identical_subsystem\Sum_of_Elements.vhd上工作,例如hdl_prj\hdlsrc\hdlcoder_reusable_code_identical_subsystem\Sum_of_Elements.vhd。###在hdl_prj\hdlsrc\hdlcoder_reusable_code_identical_subsystem\vsum.vhd上工作。###在hdl_prj\hdlsrc\hdlcoder_reusable_code_identical_subsystem\DUT上工作,hdl_prj\hdlsrc\hdlcoder_reusable_code_identical_subsystem\DUT.vhd。###生成包文件hdl_prj\hdlsrc\hdlcoder_reusable_code_identical_subsystem\DUT_pkg.vhd. ######创建HDL代码生成检查报告DUT_report.html ### HDL code generation complete.

为DUT子系统生成的代码,DUT.vhd的三个实例化vsum组件。

架构rtl OF DUT IS——Component Declarations Component vsum PORT(In1: IN vector_of_std_logic_vector16(0 TO 9);——int16 [10] Out1: OUT std_logic_vector(19 DOWNTO 0)——sfix20;结束组件;——组件配置语句:vsum USE ENTITY work.vsum(rtl);——Signals SIGNAL vsum_out1: std_logic_vector(19 DOWNTO 0);——ufix20 SIGNAL vsum1_out1: std_logic_vector(19 DOWNTO 0);——ufix20 SIGNAL vsum2_out1: std_logic_vector(19 DOWNTO 0);——ufix20 BEGIN u_vsum: vsum PORT MAP(In1 => In1,——int16 [10] Out1 => vsum_out1——sfix20);u_vsum1: vsum PORT MAP(In1 => In2,——int16 [10] Out1 => vsum1_out1——sfix20);u_vsum2: vsum PORT MAP(In1 => In3,——int16 [10] Out1 => vsum2_out1——sfix20); Out1 <= vsum_out1; Out2 <= vsum1_out1; Out3 <= vsum2_out1; END rtl;

为具有可调掩码参数的原子子系统生成可重用代码

如果您的设计包含除了可调掩码参数值之外完全相同的原子子系统,那么您可以生成一个HDL模块实体的子系统。在生成的代码中模块实体实例化多次。

要为相同的原子子系统生成可重用代码,请启用MaskParameterAsGeneric的模型。默认情况下,MaskParameterAsGeneric是禁用的。

例如,要为具有可调参数的原子子系统生成可重用代码,请打开hdlcoder_reusable_code_parameterized_subsystem模型中,然后输入:

hdlset_param (“hdlcoder_reusable_code_parameterized_subsystem”“MaskParameterAsGeneric”“上”

或者,在“配置参数”对话框中,在HDL代码生成>全局设置>编码风格选项卡中,使从屏蔽子系统生成参数化的HDL代码选择。

例子

hdlcoder_reusable_code_parameterized_subsystem模型展示了一个DUT子系统的示例,其中包含的原子子系统除了可调掩码参数值之外都是相同的。

hdlcoder_reusable_code_parameterized_subsystem / DUT,增益模块是子系统,增益值由可调掩模参数表示。增益值为:4gain_module, 5gain_module1, 7代表gain_module2

MaskParameterAsGeneric启用时,HDL编码器生成单个源文件,gain_module.v,用于三个增益模块子系统。

makehdl (“hdlcoder_reusable_code_parameterized_subsystem / DUT”“MaskParameterAsGeneric”“上”...“开发”“Verilog”
###为'hdlcoder_reusable_code_parameterized_subsystem/DUT'生成HDL。###启动HDL检查。###开始Verilog代码生成'hdlcoder_reusable_code_parameterized_subsystem'。###在hdlsrc / hdlcoder_reusable_code_parameterized_subsystem/DUT/gain_module上工作###在hdlsrc\hdlcoder_reusable_code_parameterized_subsystem\DUT上工作###创建HDL代码生成检查报告DUT_report.html### HDL代码生成完成。

为DUT子系统生成的代码,DUT.v的三个实例化gain_module组件。

模块DUT (In1, In2, In3, Out1, Out2, Out3);输入[7:0]三机一体;// uint8 input [7:0] In2;// uint8 input [7:0] In3;// uint8 output [31:0] Out1;//输出[31:0]Out2;//输出[31:0]Out3;// uint32 wire [31:0] gain_module_out1;// uint32 wire [31:0] gain_module1_out1;// uint32 wire [31:0] gain_module2_out1; // uint32 gain_module # (.myGain(4) ) u_gain_module (.In1(In1), // uint8 .Out1(gain_module_out1) // uint32 ); assign Out1 = gain_module_out1; gain_module # (.myGain(5) ) u_gain_module1 (.In1(In2), // uint8 .Out1(gain_module1_out1) // uint32 ); assign Out2 = gain_module1_out1; gain_module # (.myGain(7) ) u_gain_module2 (.In1(In3), // uint8 .Out1(gain_module2_out1) // uint32 ); assign Out3 = gain_module2_out1; endmodule // DUT

gain_module.v,myGainVerilog®参数为可调掩码参数生成。

模块gain_module (In1, Out1);输入[7:0]三机一体;// uint8 output [31:0] Out1;// uint32 parameter [31:0] myGain = 4;// ufix32 wire [31:0] kconst;// ufix32 wire [39:0]// ufix40 wire [31:0]//指定kconst = myGain;赋值Gain_mul_temp = kconst * In1;分配Gain_out1 = Gain_mul_temp[31:0]; assign Out1 = Gain_out1; endmodule // gain_module

如果输入模型有包含掩码信息(如掩码变量和掩码初始化代码)的子系统,那么这些子系统的掩码信息将保留在生成的模型中。如果您不需要这些信息,您可以删除它。

相关的话题