MATLAB Link for Code Composer Studio Development Tools    

Running the Application

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:

  1. Restart the program you loaded on the target. restart ensures the program counter (PC) is at the beginning of the executable code on the processor.
  1. Restarting the target does not start the program executing. You use run to start program execution.

  1. Type cc.run('run');
  1. Using '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

  1. Type the following functions to enable the write channel and verify that the enable takes effect.
  1. If MATLAB responds ans = 0 your channel is not enabled and you cannot proceed with the tutorial. Try to enable the channel again and reverify the status.

  1. Write some data to the target. Check that you can write to the target, then use writemsg to send the data. You do not need to type the if-test code shown.
  1. We included the 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

  1. Type the following to check the number of available messages to read from the target.
  1. 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.

  1. Type the following to verify that your read channel ochan is enabled for communications.
  1. You should get back ans = 0--you have not enabled the channel yet.

  1. Now enable and verify 'ochan'.
  1. To show that ochan is ready, MATLAB responds ans = 1. If not, try enabling ochan again.

  1. Type
  1. The pause function gives the processor extra time to process the data in indata and transfer the data to the buffer you configured for ochan.

  1. Repeat the check for the number of messages in the queue. There should be 20 messages available in the buffer.
  1. With 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.

  1. Read one message from the queue into variable outdata.
  1. Notice the '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.

  1. You can read data into cell arrays, rather than into simple double-precision variables. Use the following function to read three messages to cell array outdata, an array of three, 1-by-10 vectors. Each message is a 1-by-10 vector stored on the processor.
  2. Cell array outdata contains three messages. Look at the second message, or matrix, in outdata by using dereferencing with the array.
  3. Read two messages from the target into two 2-by-5 matrices in your MATLAB workspace.
  1. To specify the number of messages to read and the data format in your workspace, you used the siz and nummsgs options set to [2 5] and 2.

  1. You can look at both matrices in outdata by dereferencing the cell array again.

        7     9     11     13     15

  1. For a change, read a message from the queue into a column vector.
  2. The MATLAB Link for Code Composer Studio provides a function for reading messages into matrices -- readmat. Use readmat to read a message into a 5-by-2 matrix in MATLAB.
  1. Since a 5-by-2 matrix requires ten elements, MATLAB reads one message into outdata to fill the matrix.

  1. To check your progress, see how many messages remain in the queue. You have read eight messages from the queue so 12 should remain.
  2. To demonstrate the connection between messages and a matrix in MATLAB, read data from 'ochan' to fill a 4-by-5 matrix in your workspace.
  1. Filling the matrix required two messages worth of data.

  1. To verify that the last step used two messages recheck the message count. You should find 10 messages waiting in the queue.
  2. Continuing with matrix reads, fill a 10-by-5 matrix (50 matrix elements or five messages).
  3. Recheck the number of messages in the queue to see that five remain.
  4. 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.
  5. Empty the remaining messages from the queue and verify that the queue is empty.
  1. With the 'all' option, flush discards all messages in the ochan queue.


  Configuring Communications Channels Closing the Links or Cleaning Up