User`s guide

Model Execution
6-15
Program Execution
As the previous section indicates, a real-time program may not require 100% of
the CPU’s time. This provides an opportunity to run background tasks during
thefreetime.
Background tasks include operations like writing data to a buffer or file,
allowing access to program data by third-party data monitoring tools, or using
Simulink external mode to update program parameters.
It is important, however, that the program be able to preempt the background
task at the appropriate time to ensure real-time execution of the model code.
The way the program manages tasks depends on capabilities of the
environment in which it operates.
External Mode Communication
External mode allows communication between the Simulink block diagram
and the stand-alone program that is built from the generated code. In this
mode, the real-time program functions as an interprocess communication
server, responding to requests from Simulink. See Chapter 4, “External Mode,”
for information on external mode.
Data Logging
You can use the built-in data logging capabilities provided by the Real-Time
Workshop or you can use third-party data logging tools with your program (see
Chapter 5, “Data Logging and Signal Monitoring,” for more information).
The MathWorks also provides data logging facilities for creating a
model.mat
file at the completion of the model execution. This data logging facility is useful
for code validation and high-speed simulations. See the generic real-time
target,
grt, described in “Building Generic Real-Time Programs” on page 2-12.
Logging Differences Between Singletasking
and Multitasking Model Execution
If you examine how LogTXY is called in the singletasking and multitasking
environments, you will notice that for singletasking LogTXY is called after
ModelOutputs. During this ModelOutputs call, all blocks that have a hit at
time t are executed, whereas in multitasking, LogTXY is called after
ModelOutputs(tid=0) that executes only the blocks that have a hit at time t and