Documentation

Data Store Basics

A数据存储是您可以编写数据的存储库,您可以从中读取数据,而无需将输入或输出信号直接连接到数据存储。数据存储可在模型级别上访问,因此子系统和引用模型可以使用数据存储在不使用I/O端口的情况下共享数据。

When to Use a Data Store

Data stores can be useful when multiple signals at different levels of a model need the same global values, and connecting all the signals explicitly would clutter the model unacceptably or take too long to be feasible. Data stores are analogous to global variables in programs, and have similar advantages and disadvantages, such as making verification more difficult.

To share data between the instances of a reusable algorithm (for example, a subsystem in a custom library or a reusable referenced model), you can use a data store. For more information about data sharing for a reusable referenced model, seeShare Data Among Referenced Model Instances

数据存储和Software Verification

Data stores can have significant effects on software verification, especially in the area of data coupling and control. Models and subsystems that use only input and output ports to pass data result in clean, well-specified, and easily verifiable interfaces in the generated code.

与任何类型的全局数据一样,数据存储使验证更加困难。如果您的开发过程包括软件验证,请考虑计划在设计过程早期的数据存储的效果。

For more information, see RTCA DO-331, “Model-Based Development and Verification Supplement to DO-178C and DO-278A,” Section MB.6.3.3.b.

Blocks as a Signal Routing Alternative

In some cases, you may be able to use a simpler technique,块和块,获得类似于数据存储提供的结果。数据获取/从链接中的主要缺点是,它们通常在非虚拟子系统边界上无法访问,而可以在任何地方访问适当配置的数据存储。看到block reference pages for more information about Goto/From links.

Local and Global Data Stores

You can define two types of data stores:

  • Alocal data storeis accessible from anywhere in the model hierarchy that is at or below the level at which you define the data store, except from referenced models. You can define a local data store graphically in a model or by creating a model workspace signal object (金宝appsimulink.signal).

  • Aglobal data storeis accessible from throughout the model hierarchy, including from referenced models. Define a global data stores only in the MATLAB®base workspace, using a signal object. The only type of data store that a referenced model can access is a global data store.

In general, locate a data store at the lowest level in the model that allows access to the data store by all the parts of the model that need that access. Some examples of local and global data stores appear in数据存储示例

For information about using referenced models, seeModel References

Data Store Diagnostics

关于数据存储诊断

金宝app®提供各种运行时和编译时间诊断,您可以用来帮助避免数据存储问题。诊断可在“模型配置参数”对话框中找到,并且数据存储存储器块的参数对话框。Simu金宝applink Model Advisor通过列出数据存储错金宝app误更可能是由于诊断被禁用的情况而更有可能的情况来提供支持。

Detecting Access Order Errors

您可以使用数据存储运行时诊断来检测数据存储的意外序列读取和在仿真过程中发生的写入。您可以将这些诊断应用程序应用于所有数据存储,或允许每个数据存储存储器块设置自己的值。诊断是:

These diagnostics appear in the模型配置参数> Diagnostics > Data Validity > Data Store Memory blockpane, where each can have one of the following values:

  • 禁用所有— Disables this diagnostic for all data stores accessed by the model.

  • Enable all as warnings— Displays the diagnostic as a warning in the MATLAB Command Window.

  • Enable all as errors— Halts the simulation and displays the diagnostic in an error dialog box.

  • 使用本地设置- 允许每个数据存储存储器块为此诊断设置自己的值(默认值)。

The same diagnostics also appear in each Data Store Memory block parameters dialog boxDiagnosticstab. You can set each diagnostic tonone,warning, or错误。The value specified by an individual block takes effect only if the corresponding configuration parameter is使用本地设置。看模型配置参数:数据有效性诊断和the数据存储存储器documentation for more information.

The most conservative technique is to set all data store diagnostics toEnable all as errorsin模型配置参数>Diagnostics>Data Validity>数据存储存储器block。但是,在所有情况下,这种设置并不是最好的,因为它可以将预期的行为标记为错误。例如,下图显示了使用块优先级来强制的模型Data Store Readblock to execute before theData Store Writeblock:

An error occurred during simulation because the data storeAis read from theData Store Readblock before theData Store Write块更新商店。如果associated delay is intended, you can suppress the error by setting the global parameter检测读之前写to使用本地设置, then setting that parameter tonone在里面Diagnosticspane of the数据存储存储器block dialog box. If you use this technique, set the parameter to错误in all other数据存储存储器除了被故意排除在诊断之外的障碍之外。

Data Store Diagnostics and Models Referenced in Accelerator Mode.For models referenced in Accelerator mode, Simulink ignores the followingConfiguration Parameters>Diagnostics>Data Validity>数据存储存储器blockparameters if you set them to a value other than禁用所有

  • 检测读之前写(ReadBeforeWriteMsg)

  • 在阅读后检测写(WriteAfterReadMsg)

  • Detect write after write(Witterwritemsg)

You can use the Model Advisor to identify models referenced in Accelerator mode for which Simulink ignores the configuration parameters listed above.

  1. 在Simuli金宝appnk编辑中,在Modelingtab, clickModel Advisor

  2. SelectBy Task

  3. Run theCheck diagnostic settings ignored during accelerated model reference simulationcheck.

数据存储诊断和MATLAB功能块。Diagnostics might be more conservative for data store memory used byMATLAB Function块。例如,如果将数据存储存储器的数组传递给MATLAB函数,则优化a = foo(a)might result in MATLAB marking the entire contents of the array as read or written, even though only some elements were accessed.

Detecting Multitasking Access Errors

如果从一个任务中读取数据存储并在另一个任务中写入数据存储,则数据完整性可能会受到损害。例如,假设:

  1. A task is writing to a data store.

  2. A second task interrupts the first task.

  3. The second task reads from that data store.

If the first task had only partly updated the data store when the second task interrupted, the resulting data in the data store is inconsistent. For example, if the value is a vector, some of its elements may have been written in the current time step, while the rest were written in the previous step. If the value is a multi-word, it may be left in an inconsistent state that is not even partly correct.

除非您确定任务抢占不会引起数据完整性问题,请设置编译时间诊断模型配置参数> Diagnostics > Data Validity > Data Store Memory block > Multitask data storetowarning(the default) or错误。此诊断标志将在不同任务中读取并写入的数据存储的任何情况。下图说明了通过设置检测到的问题Multitask data storeto错误:

Since the data storeAis written to in the fast task and read from in the slow task, an error is reported, with suggested remedy. This diagnostic is applicable even in the case that a data store read or write is inside of a conditional subsystem. Simulink correctly identifies the task that the block is executing within, and uses that task for the purpose of evaluating the diagnostic.

下图显示了上述问题的一个解决方案:在数据存储读取后,将速率转换块放置在以前以较慢的速率访问数据存储的方法。

With this change, the data store write can continue to occur at the faster rate. This may be important if that data store must be read at that faster rate elsewhere in the model.

TheMultitask Data Store诊断也适用于数据存储的读取和写入引用模型。如果两个不同的儿童模型执行数据存储的读取和写入不同的任务,则当Simulink编译其共同的父型模型时,将检测到错误。金宝app

Detecting Duplicate Name Errors

Data store errors can occur due to duplicate uses of a data store name within a model. For instance, data store shadowing occurs when two or more data store memories in different nested scopes have the same data store name. In this situation, the data store memory referenced by a data store read or write block at a low level may not be the intended store.

为防止由重复的数据存储名称引起的错误,请设置编译时间诊断模型配置参数> Diagnostics > Data Validity > Data Store Memory block > Duplicate data store namestowarning或者错误。By default, the value of the diagnostic isnone, suppressing duplicate name detection. The next figure shows a problem detected by settingDuplicate data store namesto错误:

数据存储是ad at the bottom level of a subsystem hierarchy refers to a data store namedA, and two Data Store Memory blocks in the same model have that name, so an error is reported. This diagnostic guards against assuming that the data store read refers to the Data Store Memory block in the top level of the model. The read actually refers to the Data Store Memory block at the intermediate level, which is closer in scope to the Data Store Read block.

模型顾问中的数据存储诊断

The Model Advisor provides several diagnostics that you can use with data stores. See these sections for information about Model Advisor diagnostics for data stores:

检查数据存储存储器块,以了解多任务,强大的打字和阴影问题

Check data store block sample times for modeling errors

检查数据存储块是否启用了读/写诊断

指定数据存储的初始值

In general, to specify an initial value for a data store, you can use the same techniques that you use for other blocks. SeeInitialize Signals and Discrete States

With most blocks, you can take advantage of scalar expansion to minimize the effort of specifying an initial value for a nonscalar signal. When you specify a scalar initial value, each element in the signal uses that scalar.

However, when you set theDimensionsparameter to-1in a数据存储存储器block (the default), you cannot use scalar expansion. Instead, you must specify an initial value that has the same dimensions as the stored signal. To take advantage of scalar expansion of the initial value, set theDimensionsparameter to a specific value such as[1 2]或者[1 myDim](用于符号维度)。

看Also

|||

相关话题