Products & Services Solutions Academia Support User Community Company

Learn more about xPC Target   

mdlStart and mdlTerminate Considerations

When you load a target application onto a target PC, the driver executes the mdlStart callback method. If the execution is successful, the driver then executes mdlTerminate.

If mdlStart does not successfully complete, the application does not execute mdlTerminate. (Typically, mdlStart might not successfully complete if the application cannot find a referenced I/O board or if the board does not successfully 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. Ensure that mdlTerminate deallocates any resources that you 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.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS