MATLAB Answers

Interface generation in example rtwdemo_mrmtbb

2 views (last 30 days)
Adel Fernandez
Adel Fernandez on 12 Sep 2019
Answered: TecBen on 23 Sep 2019
If code is generated from rtwdemo_mrmtbb example with the option Templates -> Generate an example main program selected, the following C header is generated
extern void rtwdemo_mrmtbb_initialize(void);
extern void rtwdemo_mrmtbb_step0(void);
extern void rtwdemo_mrmtbb_step1(void);
That is correct in order to use the step function as a task, but if the option Templates -> Generate an example main program is cleared the interface generated is
extern void rtwdemo_mrmtbb_initialize(void);
extern void rtwdemo_mrmtbb_step(int_T tid);
It is possible to generate the first header, without generating the main program? I thought that option would not affect the generated header.

Answers (1)

TecBen on 23 Sep 2019
I think the possible different designs of the Model Entry-Point Functions are well defined in this doc link
A possible workaround to get different external definitions could be to use Customize Build Process with "sl_customization.m". After the hook point "before_make" where all code files from the SImulink model are generated you can place your file handling code and modify the C-code source files by adding MATLAB code to the "STF_make_rtw_hook.m" template file.
To create a custom STF_make_rtw_hook hook file for your build procedure, copy and edit the example ert_make_rtw_hook.m file, which is located in the foldermatlabroot/toolbox/coder/embeddedcoder (open), as follows:
Copy ert_make_rtw_hook.m to a folder in the MATLAB path. Rename it in accordance with the naming conventions described in Conventions for Using the STF_make_rtw_hook File. For example, to use it with the GRT target grt.tlc, rename it to grt_make_rtw_hook.m.
Rename the ert_make_rtw_hook function within the file to match the file name.
Implement the hooks that you require by adding code to case statements within the switch hookMethod statement.
For example, in the "ert_make_rtw_hook.m" which you have copied into the folder where your Simulink model was saved you can add our MATLAB code in the switch/case section "before_make" to open the header file where the /* Model entry point functions */ are defined and modify it with MATLAB Low-Level File I/O functions like fopen(..).
Tip: when you change your custom "ert_make_rtw_hook.m" file code, then run in the MATLAB command window "sl_refresh_customizations" so that the changes are adopted for the next model build.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!