User`s guide

6 Custom xPC Targetâ„¢ Driver Notes
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 success ful, the driver then
executes
mdlTerminate.
If
mdlStart does not successfully complete, the application does not execute
mdlTerminate.(Typically,mdl Star t might not successfully complete if
the application cannot find a referenced I/O board o r 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, r eset it to th e 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 descripti on distinguishes between the driver initialization an d
applicatio n start phases, you do n ot need to actu ally differentiate betw een
them. If you do need to do so, use the
xpcIsModelInit function. This function
returns
1 while the model is initializing, and 0 otherwise.
6-4