About Code generation in the Model Based Software

cancel
Showing results for 
Search instead for 
Did you mean: 

About Code generation in the Model Based Software

Jump to solution
2,009 Views
edenli
Contributor V

Hi Guys,

I used the simulink/stateflow call external *.c and *.h files,and generated the Test_1_initialize(void) as below,

182591_182591.pngpastedImage_3.png

but,i wanna put the int_xx() function of the ad.c file in Test_1_initialize(void),shown as yellow mark.

182569_182569.pngpastedImage_2.png

I put stateflow in the Initialize Function,simulink shows that it is not supported,so i don't know how to do!

The attachment is the model built by myself.

182593_182593.pngpastedImage_5.png

Who can help me?Thanks very much!

Original Attachment has been moved to: Model.zip

1 Solution
579 Views
dumitru-daniel_
NXP Employee
NXP Employee

It is not a direct call of your function but functionally is the same outcome.

The Matlab S-function will call your custom function via a wrapper:

pastedImage_1.png

That in turns calls the user code:

1.JPG

All you have to do is:

#1: place the S-function in the Initialize Function Block

2.JPG

#2: customize the S-function Builder to reference the code you want to call

3.JPG

#3: follow the tip#3 to copy all custom files in the final generation code folder: https://community.nxp.com/thread/449904 

5.JPG

Attached is and example with Matlab/Simulink + copy file(that needs to customized for each PC)

Hope this helps!

Best regards,
Daniel

View solution in original post

0 Kudos
3 Replies
579 Views
dumitru-daniel_
NXP Employee
NXP Employee

Hi Eden Li, 

The Simulink error you are getting is normal and is listed as a Mathworks limitation: Initialize, Reset, and Terminate Function Limitations - MATLAB & Simulink - MathWorks Deutschland 

Charts are not supported by the block you want to use in your model.

Nonetheless, we may offer you and alternative:

Just recently another member of the community had a similar request: please see this topic:MCToolbox can't find my hand written code. Does it support S-Function? 

We've also created a tip for it: MBD Toolbox - Tip of the Day‌ Tip #3: MBD Toolbox - Add custom code to your Simulink model

Let us know if you managed to implement your functionality this way.

Hope it helps!

Daniel

0 Kudos
579 Views
edenli
Contributor V

Hi daniel,

I haven't realize this function ,The link you had sent to seams not realize  my goal that mentaioned abve(the yellow mark) .

0 Kudos
580 Views
dumitru-daniel_
NXP Employee
NXP Employee

It is not a direct call of your function but functionally is the same outcome.

The Matlab S-function will call your custom function via a wrapper:

pastedImage_1.png

That in turns calls the user code:

1.JPG

All you have to do is:

#1: place the S-function in the Initialize Function Block

2.JPG

#2: customize the S-function Builder to reference the code you want to call

3.JPG

#3: follow the tip#3 to copy all custom files in the final generation code folder: https://community.nxp.com/thread/449904 

5.JPG

Attached is and example with Matlab/Simulink + copy file(that needs to customized for each PC)

Hope this helps!

Best regards,
Daniel

View solution in original post

0 Kudos