Memory Copy - Copy to and from memory section

Library

Core Support in Embedded IDE Link™ VS

Description

In generated code, this block copies variables or data from and to target memory as configured by the block parameters. Your model can contain as many of these blocks as you require to manipulate memory on your target.

Each block works with one variable, address, or set of addresses provided to the block. Parameters for the block let you specify both the source and destination for the memory copy, as well as options for initializing the memory locations.

Using parameters provided by the block, you can change options like the memory stride and offset at run time. In addition, by selecting various parameters in the block, you can write to memory at program initialization, at program termination, and at every sample time. The initialization process occurs once, rather than occurring for every read and write operation.

With the custom source code options, the block enables you to add custom ANSI® C source code before and after each memory read and write (copy) operation. You can use the custom code capability to lock and unlock registers before and after accessing them. For example, some processors have registers that you may need to unlock and lock with EALLOW and EDIS macros before and after your program accesses them.

Block Operations

This block performs operations at three periods during program execution—initialization, real-time operations, and termination. With the options for setting memory initialization and termination, you control when and how the block initializes memory, copies to and from memory, and terminates memory operations. The parameters enable you to turn on and off memory operations in all three periods independently.

Used in combination with the Memory Allocate block, this block supports building custom device drivers, such as PCI bus drivers or codec-style drivers, by letting you manipulate and allocate memory. This block does not require the Memory Allocate block to be in the model.

In a simulation, this block does not perform any operation. The block output is not defined.

Copy Memory

When you employ this block to copy an individual data element from the source to the destination, the block copies the element from the source in the source data type, and then casts the data element to the destination data type as provided in the block parameters.

Dialog Box

The block dialog box contains multiple tabs:

The dialog box images show many of the available parameters enabled. Some parameters shown do not appear until you select one or more other parameters. Some parameters are not shown in the figures, but the text describes them and how to make them available.

Sections that follow describe the parameters on each tab in the dialog box.

Source Parameters

Copy from

Select the source of the data to copy. Choose one of the entries on the list:

Depending on the choice you make for Copy from, you see other parameters that let you configure the source of the data to copy.

Specify address source

This parameter directs the block to get the address for the variable either from an entry in Address or from the input port to the block. Select either Specify via dialog or Input port from the list. Selecting Specify via dialog activates the Address parameter for you to enter the address for the variable.

When you select Input port, the port label on the block changes to &src, indicating that the block expects the address to come from the input port. Being able to change the address dynamically lets you use the block to copy different variables by providing the variable address from an upstream block in your model.

Source code symbol

Specify the symbol (variable) in the source code symbol table to copy. The symbol table for your program must include this symbol. The block does not verify that the symbol exists and uses valid syntax. Enter a string to specify the symbol exactly as you use it in your code.

Address

When you select Specify via dialog for the address source, you enter the variable address here. Addresses should be in decimal form. Enter either the decimal address or the address as a hexadecimal string with single quotations marks and use hex2dec to convert the address to the proper format. The following example converts Ox1000 to decimal form.

4096 = hex2dec('1000');

For this example, you could enter either 4096 or hex2dec('1000') as the address.

Data type

Use this parameter to specify the type of data that your source uses. The list includes the supported data types, such as int8, uint32, and Boolean, and the option Inherit from input port for inheriting the data type for the variable from the block input port.

Data length

Specifies the number of elements to copy from the source location. Each element has the data type specified in Data type.

Use offset when reading

When you are reading the input, use this parameter to specify an offset for the input read. The offset value is in elements with the assigned data type. The Specify offset source parameter becomes available when you check this option.

Specify offset source

The block provides two sources for the offset — Input port and Specify via dialog. Selecting Input port configures the block input to read the offset value by adding an input port labeled src ofs. This port enables your program to change the offset dynamically during execution by providing the offset value as an input to the block. If you select Specify via dialog, you enable the Offset parameter in this dialog box so you can enter the offset to use when reading the input data.

Offset

Offset tells the block whether to copy the first element of the data at the input address or value, or skip one or more values before starting to copy the input to the destination. Offset defines how many values to skip before copying the first value to the destination. Offset equal to one is the default value and Offset accepts only positive integers of one or greater.

Stride

Stride lets you specify the spacing for reading the input. By default, the stride value is one, meaning the generated code reads the input data sequentially. When you add a stride value that is not equal to one, the block reads the input data elements not sequentially, but by skipping spaces in the source address equal to the stride. Stride must be a positive  integer.

The next two figures help explain the stride concept. In the first figure you see data copied without any stride. Following that figure, the second figure shows a stride value of two applied to reading the input when the block is copying the input to an output location. You can specify a stride value for the output with parameter Stride on the Destination pane. Compare stride with offset to see the differences.

Destination Parameters

Copy to

Select the destination for the data. Choose one of the entries on the list:

Depending on the choice you make for Copy from, you see other parameters that let you configure the source of the data to copy.

Specify address source

This parameter directs the block to get the address for the variable either from an entry in Address or from the input port to the block. Select either Specify via dialog or Input port from the list. Selecting Specify via dialog activates the Address parameter for you to enter the address for the variable.

When you select Input port, the port label on the block changes to &dst, indicating that the block expects the destination address to come from the input port. Being able to change the address dynamically lets you use the block to copy different variables by providing the variable address from an upstream block in your model.

Source code symbol

Specify the symbol (variable) in the source code symbol table to copy. The symbol table for your program must include this symbol. The block does not verify that the symbol exists and uses valid syntax.

Address

When you select Specify via dialog for the address source, you enter the variable address here. Addresses should be in decimal form. Enter either the decimal address or the address as a hexadecimal string with single quotations marks and use hex2dec to convert the address to the proper format. This example converts Ox2000 to decimal form.

8192 = hex2dec('2000');

For this example, you could enter either 8192 or hex2dec('2000') as the address.

Data type

Use this parameter to specify the type of data that your variable uses. The list includes the supported data types, such as int8, uint32, and Boolean, and the option Inherit from source for inheriting the data type for the variable from the block input port.

Specify offset source

The block provides two sources for the offset—Input port and Specify via dialog. Selecting Input port configures the block input to read the offset value by adding an input port labeled src ofs. This port enables your program to change the offset dynamically during execution by providing the offset value as an input to the block. If you select Specify via dialog, you enable the Offset parameter in this dialog box so you can enter the offset to use when writing the output data.

Offset

Offset tells the block whether to write the first element of the data to be copied to the first destination address location, or skip one or more locations at the destination before writing the output. Offset defines how many values to skip in the destination before writing the first value to the destination. One is the default offset value and Offset accepts only positive integers of one or greater.

Stride

Stride lets you specify the spacing for copying the input to the destination. By default, the stride value is one, meaning the generated code writes the input data sequentially to the destination in consecutive locations. When you add a stride value not equal to one, the output data is stored not sequentially, but by skipping addresses equal to the stride. Stride must be a positive integer.

This figure shows a stride value of three applied to writing the input to an output location. You can specify a stride value for the input with parameter Stride on the Source pane. As shown in the figure, you can use both an input stride and output stride at the same time to enable you to manipulate your memory more fully.

Sample time

Sample time sets the rate at which the memory copy operation occurs, in seconds. The default value Inf tells the block to use a constant sample time. You can set Sample time to -1 to direct the block to inherit the sample time from the input, if there is one, or the Simulink® software model (when there are no input ports on the block). Enter the sample time in seconds as you need.

Options Parameters

Set memory value at initialization

When you check this option, you direct the block to initialize the memory location to a specific value when you initialize your program at run time. After you select this option, use the Set memory value at termination and Specify initialization value source parameters to set your desired value. Alternately, you can tell the block to get the initial value from the block input.

Specify initialization value source

After you check Set memory value at initialization, use this parameter to select the source of the initial value. Choose either

Initialization value (constant)

If you check Set memory value at initialization and choose Specify constant value for Specify initialization value source, enter the constant value to use in this field. Any real value that meets your needs is acceptable.

Initialization value (source code symbol)

If you check Set memory value at initialization and choose Specify source code symbol for Specify initialization value source, enter the symbol to use in this field. Any symbol that meets your needs and is in the symbol table for the program is acceptable. When you enter the symbol, the block does not verify whether the symbol is a valid one. If it is not valid you get an error when you try to compile, link, and run your generated code.

Apply initialization value as mask

You can use the initialization value as a mask to manipulate register contents at the bit level. Your initialization value is treated as a string of bits for the mask.

Checking this parameter enables the Bitwise operator parameter for you to define how to apply the mask value.

To use your initialization value as a mask, the output from the copy has to be a specific address. It cannot be an output port, but it can be a symbol.

Bitwise operator

To use the initialization value as a mask, select one of the entries on the following table from the Bitwise operator list to describe how to apply the value as a mask to the memory value.

Bitwise Operator List Entry

Description

bitwise AND

Apply the mask value as a bitwise AND to the value in the register.

bitwise OR

Apply the mask value as a bitwise OR to the value in the register.

bitwise exclusive OR

Apply the mask value as a bitwise exclusive OR to the value in the register.

left shift

Shift the bits in the register left by the number of bits represented by the initialization value. For example, if your initialization value is 3, the block shifts the register value to the left 3 bits. In this case, the value must be a positive integer.

right shift

Shift the bits in the register to the right by the number of bits represented by the initialization value. For example, if your initialization value is 6, the block shifts the register value to the right 6 bits. In this case, the value must be a positive integer.

Applying a mask to the copy process lets you select individual bits in the result, for example, to read the value of the fifth bit by applying the mask.

Set memory value at termination

Along with initializing memory when the program starts to access this memory location, this parameter directs the program to set memory to a specific value when the program terminates.

Set memory value only at initialization/termination

This block performs operations at three periods during program execution—initialization, real-time operations, and termination. When you check this option, the block only does the memory initialization and termination processes. It does not perform any copies during real-time operations.

Insert custom code before memory write

Select this parameter to add custom ANSI C code before the program writes to the specified memory location. When you select this option, you enable the Custom code parameter where you enter your ANSI C code.

Custom code

Enter the custom ANSI C code to insert into the generated code just before the memory write operation. Code you enter in this field appears in the generated code exactly as you enter it.

Insert custom code after memory write

Select this parameter to add custom ANSI C code immediately after the program writes to the specified memory location. When you select this option, you enable the Custom code parameter where you enter your ANSI C code.

Custom code

Enter the custom ANSI C code to insert into the generated code just after the memory write operation. Code you enter in this field appears in the generated code exactly as you enter it.

See Also

Memory Allocate

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS