How can i use to initialize for one-time execute code?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How can i use to initialize for one-time execute code?

ソリューションへジャンプ
7,311件の閲覧回数
byeongjinkim
Contributor II

I want to initialization code for one-time execute.

example)

main()

{

   --initialization---

   a = port input value (port input at power-on)

  ---------------------

   while(1)

   {

      b = current port input value

      if (a ~= b)

      {~~~~~~~

      }

   }

}

how can i use to one time execute code?

0 件の賞賛
返信
1 解決策
5,752件の閲覧回数
Daniel_Popa
NXP Employee
NXP Employee

Hi byeongjinkim‌,

Simulink generated code has 3 main functions:

- step()

- initialize()

- terminate()

You need to inject the code into the initialize function because that is called only once in the beginning.

Capture.JPG

You can do this by using 2 standard (S-Function Builder and Initialize Function) Simulink blocks and one file from the Toolbox (mcd_s12zvm_user_copy_required_files.m)

The procedure is like this (an example is attached)

1: First you add the Initialize Function Block into your model

1.JPG

2: inside the Initialize function you add the S-Function Builder

2.JPG

3: inside the S-Function Builder you call your custom C-functions/C-files/C-headers

3.JPG

4.JPG

4: Use Toolbox Custom file copy to move all the custom files into the automatic generated folder before building the application

6.JPG

5: You build the application and check if the code was injected in the right place.

7.JPG

Please find attached an example - all you have to do is to:

- copy and replace the file: mcd_s12zvm_user_copy_required_files.m into c:\MCToolbox\mctbx_9s12zvm\mctbx_s12zvm\mctbx_s12zvm\mscripts\ folder

- add you own code into my_code function.

Hope this helps!

Daniel

元の投稿で解決策を見る

5 返答(返信)
5,753件の閲覧回数
Daniel_Popa
NXP Employee
NXP Employee

Hi byeongjinkim‌,

Simulink generated code has 3 main functions:

- step()

- initialize()

- terminate()

You need to inject the code into the initialize function because that is called only once in the beginning.

Capture.JPG

You can do this by using 2 standard (S-Function Builder and Initialize Function) Simulink blocks and one file from the Toolbox (mcd_s12zvm_user_copy_required_files.m)

The procedure is like this (an example is attached)

1: First you add the Initialize Function Block into your model

1.JPG

2: inside the Initialize function you add the S-Function Builder

2.JPG

3: inside the S-Function Builder you call your custom C-functions/C-files/C-headers

3.JPG

4.JPG

4: Use Toolbox Custom file copy to move all the custom files into the automatic generated folder before building the application

6.JPG

5: You build the application and check if the code was injected in the right place.

7.JPG

Please find attached an example - all you have to do is to:

- copy and replace the file: mcd_s12zvm_user_copy_required_files.m into c:\MCToolbox\mctbx_9s12zvm\mctbx_s12zvm\mctbx_s12zvm\mscripts\ folder

- add you own code into my_code function.

Hope this helps!

Daniel

5,752件の閲覧回数
byeongjinkim
Contributor II

A build error occurs.

pastedImage_2.png

pastedImage_1.png

matlab version : 2015a

you attached '*.slx' file is 2016 version. so, not open.

i used '.mdl' file.

what is the command "rp_copy"?

this is not find matlab command.

0 件の賞賛
返信
5,752件の閲覧回数
Daniel_Popa
NXP Employee
NXP Employee

Hello,

The build error indicates that the custom files were not copied inside the *_mcd_rtw folder where those are needed to be.The  rp_copy is a toolbox function.Try the open the m file in the MATLAB editor and place a breakpoint and then build again. Does the breakpoint gets hit?If  not then the file was not copied in the location expected by the toolbox.

Idid not know your MATLAB version and I exported the mdl in 2014 version just to be covered. It should works.

Best regards, Daniel

0 件の賞賛
返信
5,752件の閲覧回数
byeongjinkim
Contributor II

initialize function block is not supported in simulink of matlab version 2015a.

pastedImage_2.png

matlab command "help rp_copy" --> not find rp_copy

rp_copy is wrong. The exact command is "copyfile".

pastedImage_3.png

after corrected command, compile is right operating.

pastedImage_1.png

but, initialize function is wrong position.

i think, initialize function block is not operation in 2015a version.

0 件の賞賛
返信
5,752件の閲覧回数
Daniel_Popa
NXP Employee
NXP Employee

Hi byeongjinkim‌,

You're right - it look the Simulink introduced the Simulink Block Initialize Function after 2015.

Capture.JPG

I think there is still a hope even in the older Matlabs - even if you will not have the block in Simulink.

Can you try this approach Integrate Custom C/C++ Code for Simulation - MATLAB & Simulink ?

Hope this will work for you!

Daniel

0 件の賞賛
返信