User`s guide
6 Program Architecture
6-18
model.reg), execute, the run-time interface starts execution by calling
MdlStart. This routine is called once at start-up.
The function
MdlStart has four basic sections:
- Code to initialize the states for each block in the root model that has states.
A subroutine call is made to the “initialize states” routine of conditionally
executed subsystems.
- Code generated by the one-time initialization (start) function for each
block in the model.
- Code to enable: 1) the blocks in the root model that have enable methods,
2) the blocks inside triggered or function-call subsystems residing in the
root model. Simulink blocks can have enable and disable methods. An
enable method is called just before a block starts executing, and the
disable method is called just after the block stops executing.
- Code for each block in the model that has a constant sample time.
•
MdlOutputs(int_T tid) — MdlOutput is responsible for updating the output
of blocks at appropriate times. The
tid (task identifier) parameter identifies
thetaskthatinturnmapswhentoexecuteblocksbasedupontheirsample
time. This routine is invoked by the run-time interface during major and
minor time steps. The major time steps are when the run-time interface is
taking an actual time step (i.e., it is time to execute a specific task). If your
model contains continuous states, the minor time steps will be taken. The
minor time steps are when the solver is generating integration stages, which
are points between major outputs. These integration stages are used to
compute the derivatives used in advancing the continuous states.
•
MdlUpdate(int_T tid) — MdlUpdate is responsible for updating the discrete
states and work vector state information (i.e., states that are neither
continuous nor discrete) saved in work vectors. The
tid (task identifier)
parameter identifies the task that in turn indicates which sample times are
active allowing you to conditionally update states of only active blocks. This
routine is invoked by the run-time interface after the major
MdlOutput has
been executed.
•
MdlDerivatives(void) — MdlDerivatives is responsible for returning the
block derivatives. This routine is called in minor steps by the solver during
its integration stages. All blocks that have continuous states have an
identical number of derivatives. These blocks are required to compute the
derivatives so that the solvers can integrate the states.