| Contents | Index |
When you load a target application onto a target computer, the driver executes the mdlStart callback method. If mdlStart completes and the software does not detect an error, the driver then executes mdlTerminate.
If mdlStart does not complete or the software detects an error, the application does not execute mdlTerminate. (Typically, mdlStart might not complete if the application cannot find a referenced I/O board or if the board does not initialize.)
When the target application does start, it executes mdlStart again, then repeatedly executes mdlOutputs. At the end of target application execution, the application calls the mdlTerminate function.
With the above considerations, write mdlStart and mdlTerminate so that they cancel each other out. The mdlTerminate function should deallocate any resources allocated in mdlStart. For example, if you set an output to high in mdlStart, reset it to the default level in mdlTerminate. (Failure to reset the output causes a high output before the application starts.) As another example, if, in the mdlStart function, you allocate memory, have mdlTerminate free the memory.
Although this description distinguishes between the driver initialization and application start phases, you do not need to actually differentiate between them. If you do need to do so, use the xpcIsModelInit function. This function returns 1 while the model is initializing, and 0 otherwise.
![]() | S-Function Guidelines | DMA Considerations | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |