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

조회 수: 11 (최근 30일)
Mu Yi
Mu Yi 2012년 8월 24일
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

채택된 답변

TAB
TAB 2012년 8월 24일
편집: TAB 2012년 8월 24일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by