How to add a C header file to the C-Mex S-function?

Dear all,
I'm trying to convert a C programme to C-Mex S-function used by RTW. But there are many coustom functions in the original C programme, how do I define these functions in C-Mex S-function which can be compiled by RTW?
(1)is it feasible to write the function before the statement "static void mdlInitializeSizes(SimStruct *S)" in C-Mex S-function? Then the functions can be call in this C-Mex S-function file? Like:
#define S_FUNCTION_NAME Realnlmpc
#define S_FUNCTION_LEVEL 2
#include "simstruc.h"
#include <stdlib.h>
void function1(int a,int b)
{
}
void function2(int c,int d)
{
}
static void mdlInitializeSizes(SimStruct *S)
{
}
(2)convert each C function to C-Mex file,then use the mexCallMATLAB command to call the functions from C-Mex S-function, but I want to know can the files in this way be compiled by RTW Target and xPC Target?
(3)convert the C functions to C header files and include the header in the C-Mex S-function, But I don't know how to add the header files to the C-Mex S-function.
Your help will be greatly appreciated! Thank you very much!
Yi Mu

 Accepted Answer

TAB
TAB on 24 Aug 2012
Edited: TAB on 24 Aug 2012
Better you use the Legacy code tool or S-function builder for such requirement. They can create the s-function which calls your existing functions.
Also for code generation inlining TLC file is required for s-function. Above tools generates TLC files also which will save your time in writting TLCs.

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Asked:

on 24 Aug 2012

Community Treasure Hunt

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

Start Hunting!