MATLAB Link for Code Composer Studio Development Tools | ![]() ![]() |
Execute C or GEL (General Extension Language) expressions on the target
Syntax
Description
result = cexpr(cc,'
executes the specified expression on the target processor refered to by expression
',timeout)
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,'
is the same as the preceding syntax except the expression
')
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.
cexpr
returns a result in MATLAB when you use a C statement as the expression argument. In the first example syntax in "Examples", result = cexpr(cc,'x.a')
, MATLAB returns result
= the value of x.a
on the target. In more concrete form, the syntax result = cexpr(cc,'x.b=10')
sets x.b
to 10
on the target and returns result = 10
to your MATLAB workspace.
cexpr
does not return results to MATLAB.
cexpr
. To access variables using cexpr
, the variables must be either global or within the current scope. When you try to read or write to a variable outside the current scope, MATLAB returns errors like the following:
main
are available without extra effort. To get to variables defined locally in subprograms, use breakpoints and the runtohalt
input option in run
to set your program to the right scope, then use cexpr
to return the information.
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
![]() | cd | clear | ![]() |