Data Transfer Representation and Processing - MATLAB & Simulink (original) (raw)
Main Content
What Is a Data Transfer?
A data transfer occurs between blocks that represent callable functions and exchange data over a signal line. The representation of a data transfer in a model depends on whether the model is a rate-based model or an export-function model. If the model is rate based, whether the connected blocks use the same sample rate. Single-rate data transfers and data transfers between exported functions are represented as a signal line that connects the functions.
This figure shows a single-rate data transfer between function-call subsystems. Both function-call subsystems are configured to use a sample rate of 1.0 seconds.
Multirate data transfers are data transfers between function blocks that are configured to use different sample rates. You represent a data transfer in a model by configuring Simulink® to automatically insert a Rate Transition block or by inserting the block manually on the signal line that connects the function blocks.
This figure shows a multirate data transfer between function-call subsystems. One function-call subsystem is configured to use a sample rate of 1.0 seconds and the other function-call subsystem is configured to use a sample rate of 2.0 seconds.
Data Transfer Considerations
When designing a multirate model, for each data transfer consider the importance of:
- Data integrity
- Determinism
- Latency
- Memory usage
Data Integrity
The data integrity of a data transfer concerns the accuracy, consistency, and completeness of data during transfer and processing. Data integrity can be compromised when the input to a block changes during the execution of the block and when preemption occurs.
Consider this sample scenario:
- A faster block supplies input to a slower block.
- The slower block reads an input value _V_1 from the faster block and begins computations using that value.
- Another execution of the faster block preempts the computations of the slower block and computes a new output value _V_2.
- A data integrity problem arises when the slower block resumes execution. The slower block continues its computations using the new input value_V_2.
This type of data transfer is unprotected. For a description of unprotected data transfers, see Fast-to-Slow Periodic Rate Transitions During Generated Code Execution.
For a protected data transfer, the output _V_1 of the faster block is held until the slower block finishes executing.
Determinism
A data transfer is deterministic if the timing of the transfer is completely predictable given:
- Availability of data
- Sample rates of the connected blocks
- Time at which the output signal destination block of the data transfer begins execution relative to when the input signal source block of the data transfer ends execution.
Latency
Latency of a data transfer is the time delay that results from the data being transferred to reach the receiving block. Depending on your application requirements, you might need to favor minimizing data transfer latency over data integrity and determinism.
Memory Usage
Depending on your application requirements, you might need to favor minimizing memory usage for data transfers over data integrity and determinism.
Code Generation Data Transfer Assumptions
When producing code for data transfers between functions, the code generator makes these assumptions:
- Data transfers occur between a single reading function and a single writing function.
- A read or write of a variable that has a size of one byte is atomic.
- When two the tasks associated with functions interact through a data transfer, only one of the tasks can preempt the other. If you deploy the functions to a multicore target system, the associated tasks can execute concurrently.
- For periodic functions, the task associated with the function that has the faster rate has higher priority than the task associated with the function that has the slower rate and preempts the slower rate task.
- Tasks run on a single processor. Time slicing is not allowed.
- Processes do not crash or restart (especially while data is transferred between tasks).
Make sure that your model, code, and target environment align with these assumptions.
Data Transfer Limitations
- Rate Transition blocks are not supported in export-function models that are configured to use a service code interface.
- The code generator does not separate the code and data for Rate Transition blocks that connect to variable-size signals or are inside of aFor Each Subsystem block.