How to use C code generated from s-function in separated pure C code project ?

1 vue (au cours des 30 derniers jours)
Hi guys,
Here is the initial state I have:
I work with matlab R2018b, I have a simulink model that have two input parameters, one output parameter and I want to use this model in a C project. I tried embedded coder to generate C code but I would like other developpers to only have access to the headers and a binary file. I had a look on the forum and heard about S-Function. I followed this tutorial (selecting rtwsfcn.tlc as the system target file).
In my workspace, it generates the following files:
<ModelName>_sf.h
<ModelName>_sf.c
<ModelName>_sf.mexw64
And also the folder called "<ModelName>_sfcn_rtw" that contains a lot of different files.
But now, I am stucked.
Which files are interresting for me in order to use the source code associated to the S-Function in my other C project ?
Am I missing other steps to use properly the s-function ?
I also had a look inside the headers and source file, and I am a little bit confused. In some headers, there some includes like
#include simstruc.h or #include fixedpoint.h but they are not present in the generated folder.
There is a place I can find them ? And also the associated .c file ?
Thank you in advance, and have a great day.

Réponses (1)

Swathi
Swathi le 15 Sep 2022
It is noted that the intent is to create executable code from a Simulink Model (with 2 inputs and 1 input) such that fellow developers are only allowed to access the header and binary files.
Accordingly, a tutorial was followed to deploy S-Function by selecting rtwsfcn.tlc as the system target file.
There are different files needed to deploy a generated S-Function block for simulation versus code generation.
>> To deploy your generated S-Function block for inclusion in other models for simulation, you need only supply the binary MEX-file object that was generated in the current working folder when the S-Function block was created.
The required file is:
  • <ModelName>.mexext
where mexext is a platform-dependent MEX-file extension (see mexext).
>> To deploy your generated S-Function block for inclusion in other models for code generation, all the files that were generated in the current working folder when the S-Function block was created, must be provided. The required files are:
  • <ModelName>.c or <model_name>.cpp.
  • <ModelName>_sf.h
  • <ModelName>_sf.mexext
  • Subfolder <ModelName>_sfcn_rtw and its contents
( For further details on effectively using the S-Function, there is a guide that can be leveraged here. )
In order to use the source code associated to the S-Function for other C project(s), there is flexibility to reuse the generated code for identical subsystems that occur in multiple instances within a model and across referenced models. More details about which can be found at Control Generation of Subsystem Functions (Simulink Coder).
However, it is important to note that a '.mex' of an S-Function, (<ModelName>_sf.mexw64 in this case) is only good for Simulation, that is for Model update, Simulating in Normal mode, and Accelerator mode (by default).
Whereas, to generate the code, you would need -
1) Noninlined S-Function - A source file of your S-Function.
2) Inline S-Function - It is necessary to have a '.tlc' file for your S-Function in-order to generate Inline code and Simulate in Rapid accelerator mode.
Therefore, if either the source file or the .tlc file is not present, it is not possible to generate code for your S-Function.
Since you probed into the contents of the header and source file, and came across -
  • #include simstruc.h
  • #include fixedpoint.h
These preprocessor directives are an integral part of the Structure of an S-Function described here.

Catégories

En savoir plus sur Target Language Compiler dans Help Center et File Exchange

Tags

Produits


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by