MATLAB Link for Code Composer Studio Development Tools    
cexpr

Execute C or GEL (General Extension Language) expressions on the target

Syntax

Description

result = cexpr(cc,'expression',timeout) executes the specified expression on the target processor refered to by cc and returns a result. If your program includes data in complex data structures and arrays, cexpr offers one way to access the data.

To run cexpr on your target, you must load a program to the processor. Your target processor does not need to be running the loaded program to execute cexpr. In operation cexpr is equivalent to using the CCS Command Line dialog. Refer to your CCS documentation for more information about using the command line in CCS.

When you place single quotation marks around the expression argument, MATLAB ignores the enclosed string, passing it to your target. The target processor evaluates the expression and returns the result to MATLAB. Any part of the expression argument that is not in single quotation marks gets evaluated by MATLAB and sent to the target processor along with the quoted portion. Using single quotation marks, you can combine MATLAB, GEL (the General Extension Language) , and C expressions within one cexpr command so that MATLAB sets a value on the target, the target uses the value, and returns the result to your MATLAB workspace. Refer to "Examples" for a code example that mixes C and MATLAB functions in one command.

After you execute the function, MATLAB waits timeout seconds for CCS to confirm successful completion of the operation. If the wait exceeds timeout seconds, MATLAB returns an error. Often, the timeout error means the confirmation was delayed but the succeeded.

Enter expression as a string in single quotation marks defining either a C expression, a GEL command, or a combination of both C and GEL. CCS defines the syntax for expression as either:

result = cexpr(cc,'expression') is the same as the preceding syntax except the timeout value defaults to the global timeout in cc. Use get(cc) to determine the global timeout value.

When you use cexpr, a few points can help you work effectively.

For more information on GEL and GEL files, refer to your CCS documention.

Examples

cexpr covers a broad range of uses. To introduce some of the possibilities, the following examples use both the C expression and GEL expression forms. Because executing the examples requires that specific variables and functions exist on the target, you cannot execute the code shown.

cexpr Syntax
Description
result = cexpr(cc,'x.a')
Returns the value of field a in structure x stored on your target. For this example, expression is x.a and result contains the value stored in x.a on the target.
result = cexpr(cc,'StartUp()')
Executes the GEL function StartUp on the target processor. expression is 'StartUp', a function in the GEL file that loads each time you start CCS. Note that GEL function names are case sensitive -- StartUp is not the same as startup. In this example, result is NULL or empty because GEL functions do not generate return values. Do not use an output argument with GEL expressions as input arguments.
result = cexpr(cc,'x.b = 10')
Sets and returns the value of the field b in structure x. Here the assignemt statement in single quotation marks replaces expression. x.b must be a structure in memory on your target and in the current program scope. After execution, result contains the value 10 returned from the target.
result = cexpr(cc,['x.c[2] =' int2str(z)])
Sets the value of x.c[2] to the string represented by integer z. In MATLAB, result contains the value stored in x.c[2] as returned from the target. Notice that the C expression is in single quotation marks, and the MATLAB int2str is not. Using single quotation marks directs MATLAB to ignore the C string that applies to the target processor and to evaluate int2str.

A note about the final example -- the variable z must be in your MATLAB workspace for int2str to work. In contrast, x.c[2] defines a value on your target, not in MATLAB.

See Also

address, read, write


  cd clear