主要内容

传统功能中的复杂信号

此示例显示如何使用传统代码工具使用复杂信号集成传统C功能。

遗留代码工具允许您:

  • 提供遗留功能规范,

  • 生成在仿真期间使用的C-MEX S函数,以调用遗留代码,以及

  • 编译并构建生成的S函数进行仿真。

提供遗留功能规范

具有遗留代码工具提供的函数将特定的数据结构或结构数组作为参数。通过使用“初始化”作为第一个输入来初始化数据结构。初始化结构后,您必须将其属性分配给与已集成的传统代码对应的值。在此示例中调用的遗留功能的原型是:

void cplx_gain(creal_t *输入,creal_t * gain,creal_t *输出);

where creal_T is the complex representation of a double. The legacy source code is found in the filescplxgain.h.andcplxgain.c.

%sldemo_sfun_gain_scalar.def = letacacy_code('初始化');def.SFunctionName ='sldemo_sfun_cplx_gain';def.outputfcnspec =.'void cplx_gain(complex u1[1], complex p1[1], complex y1[1])';def.headerfiles = {'cplxgain.h'};def.SourceFiles = {'cplxgain.c'};def.incpaths = {'sldemo_lct_src'};def.srcpaths = {'sldemo_lct_src'};

生成和编译S函数以在仿真期间使用

使用第一个输入设置为“generate_for_sim”来调用函数legacy_code(),以便根据输入参数'def'提供的描述自动生成和编译c-mex s函数。此S函数用于调用仿真中的遗留功能。在文件中找到了S函数的源代码sldemo_sfun_cplx_gain.c

Legacy_code('generate_for_sim'那def);
###开始编译SLDEMO_SFUN_CPLX_GAIN MEX(' -  I / TMP / BDOC22A_1891349_107669 / TP2E4ADC6E / EX34942047 / SLDEMO_LCT_SRC','-I / TMP / BDOC22A_1891349_107669 / TP2E4ADC6E / EX34942047','-C','-OUTDIR','/ TMP /bdoc22a_1891349_107669 / tpad5ba40e_d3d4_4b23_bfaa_44df255bee08','/tmp/bdoc22a_189/tp2e4aadc6e/ex34942047/sldemo_lct_src/cplxgain.c')与'gcc'建立。MEX成功完成。mex('sldemo_sfun_cplx_gain.c', '-I/tmp/Bdoc22a_1891349_107669/tp2e4adc6e/ex34942047/sldemo_lct_src', '-I/tmp/Bdoc22a_1891349_107669/tp2e4adc6e/ex34942047', '/tmp/Bdoc22a_1891349_107669/tpad5ba40e_d3d4_4b23_bfaa_44df255bee08/cplxgain.o') Building用'gcc'。MEX成功完成。###完成编译sldemo_sfun_cplx_gain ###退出

生成RTWMAKECFG.M文件以进行代码生成

After the TLC block file is created, the function legacy_code() can be called again with the first input set to 'rtwmakecfg_generate' in order to generate an rtwmakecfg.m file to support code generation through Simulink® Coder™. Generate the rtwmakecfg.m file if the required source and header files for the S-functions are not in the same directory as the S-functions, and you want to add these dependencies in the makefile produced during code generation.

注意:仅当您将在加速模式下模拟模型时才完成此步骤。

Legacy_code('rtwmakecfg_generate'那def);

生成屏蔽的S函数块,用于调用生成的S函数

后C-MEX s函数源代码被编译,function legacy_code() can be called again with the first input set to 'slblock_generate' in order to generate a masked S-function block that is configured to call that S-function. The block is placed in a new model and can be copied to an existing model.

% legacy_code('slblock_generate', def);

Integration with Legacy Code

该模型sldemo_lct_cplxgain.显示与遗留代码的集成。子系统Complex_Gain用作通过生成S函数呼叫传统C函数的线束。

如果isempty(find_system('SearchDepth',0,'姓名''sldemo_lct_cplxgain'))Open_System('sldemo_lct_cplxgain')Open_System('sldemo_lct_cplxgain / complex_gain')SIM('sldemo_lct_cplxgain');end

也可以看看