필터 지우기
필터 지우기

Can I use typedef in a C-file S-function?

조회 수: 2 (최근 30일)
Brian Tremaine
Brian Tremaine 2021년 10월 20일
편집: Brian Tremaine 2021년 10월 20일
I'm simulating some C code from an STM32 MCU in a Matlab Simulink model using a C-file S-Function. In my MCU code I use a typedef as follows:
typedef enum
{
DECEL = 0, //
ACCEL = 1, //
COAST = 2 //
} PFD_State_t;
I'd like to use this typedef in my S-Function mdlUpdate function to compute my algorithm using a case statement based on the enum. How do I do this? Can I include my own custom *.h file when compiling the S-Function?
Thanks,
Brianinclde
  댓글 수: 2
James Tursa
James Tursa 2021년 10월 20일
편집: James Tursa 2021년 10월 20일
You should be able to use any valid C/C++ code in an S-Function, including using header h files. Have you tried something that didn't work? Can you post it?
Brian Tremaine
Brian Tremaine 2021년 10월 20일
편집: Brian Tremaine 2021년 10월 20일
I had not tried it until just now and it looks like it's working. The total model is not complete, but compiling does not return any complains.
I added the file phase_det.h in my local project directory where the *.slx file resides. In the S-Function file I added the line #include "phase_det.h".
In the mdlUpdate function I am declaring and assigning variables using the new type. It compiles without error; so no problems yet. I had seen some Matlab documentation on creating custom typedefs for Simulink and that was rather confusing to me, hence my question.
Thanks,
Brian

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Block and Blockset Authoring에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by