MATLAB Link for Code Composer Studio Development Tools | ![]() ![]() |
To this point you have been doing housekeeping functions that are common to any application you run on the target. You load the target, configure the communications, and set up other properties you need.
In this tutorial task, you use a specific application to demonstrate a few of the functions available in the MATLAB Link for Code Composer Studio that let you experiment with your application while you develop your prototype. To demonstrate the link for RTDX readmat
, readmsg
, and writemsg
functions, you write data to your target for processing, then read data from the target after processing:
restart
ensures the program counter (PC) is at the beginning of the executable code on the processor.
run
to start program execution.
run
' for the run
mode tells the processor to continue to execute the loaded program continuously until it receives a halt directive. In this mode, control returns to MATLAB so you can work in MATLAB while the program runs. Other options for the mode are
runtohalt
'--start to execute the program and wait to return control to MATLAB until the process reaches a breakpoint or execution terminates.
tohalt
'--change the state of a running processor to 'runtohalt
' and wait to return until the program halts. Use tohalt
mode to stop the running processor cleanly.
ans = 0
your channel is not enabled and you cannot proceed with the tutorial. Try to enable the channel again and reverify the status.
writemsg
to send the data. You do not need to type the if-test code shown.
if
-statement to simulate writing the data from within a MATLAB script. The script uses iswritable to check that the input channel is functioning. If iswritable
returns 0
the script would skip the write and exit the program, or respond in some way. When you are writing or reading data to your target in a script or M-file, checking the status of the channels can help you avoid errors during execution.
As your application runs you may find it helpful to display progress messages. In this case, the program directed MATLAB to print a message as it reads the data from the target by adding the function
num_of_msgs
should be zero. Using this process to check the amount of data can make your reads more reliable by letting you or your program know how much data to expect.
pause
function gives the processor extra time to process the data in indata
and transfer the data to the buffer you configured for ochan
.
num_of_msgs = 20
, you could use a looping structure to read the messages from the queue in to MATLAB. In the next few steps of this tutorial you read data from the ochan
queue to different data formats within MATLAB.
int16
' represent
option. When you read data from your target you need to tell MATLAB the data type you are reading. You wrote the data in step 4 as 16-bit integers so you use the same data type here.
While performing reads and writes, your process continues to run. You did not need to stop the processor to get the data or send the data, unlike using most debuggers and breakpoints in your code. You placed your data in memory across an RTDX channel, the processor used the data, and you read the data from memory across an RTDX channel, without stopping the processor.
outdata
, an array of three, 1-by-10 vectors. Each message is a 1-by-10 vector stored on the processor.
outdata
contains three messages. Look at the second message, or matrix, in outdata
by using dereferencing with the array.
siz
and nummsgs
options set to [2 5]
and 2
.
readmat
. Use readmat
to read a message into a 5-by-2 matrix in MATLAB.
outdata
to fill the matrix.
'ochan'
to fill a 4-by-5 matrix in your workspace.
outdata = cc.rtdx.readmat('ochan','int16',[4 5]) outdata = 12 13 14 15 16 13 14 15 16 17 14 15 16 17 18 15 16 14 18 19 16 17 18 19 20 17 18 19 20 21 18 19 20 21 22 19 20 21 22 23 20 21 22 23 24 21 22 23 24 25
flush
lets you remove messages from the queue without reading them. Data in the message you remove is lost. Use flush to remove the next message in the read queue. Then check the waiting message count.
![]() | Configuring Communications Channels | Closing the Links or Cleaning Up | ![]() |