Getting Started with Automation Interface

Introducing the Automation Interface Tutorial

Embedded IDE Link CC provides a connection between MATLAB software and a processor in CCS. You can use objects to control and manipulate a signal processing application using the computational power of MATLAB software. This approach can help you while you debug and develop your application. Another possible use for automation is creating MATLAB scripts that you use to verify and test algorithms that run in their final implementation on your production processor.

Before using the functions available with the objects, you must select a processor to be your processor because any object you create is specific to a designated processor and a designated instance of CCS IDE. Selecting a processor is only necessary for multiprocessor boards or multiple board configurations of CCS.

When you have only one board with a single processor, the object defaults to the existing processor. For the objects, the simulator counts as a board; if you have both a board and a simulator that CCS recognizes, you must specify the processor explicitly.

To get you started using objects for CCS IDE software, Embedded IDE Link CC includes a tutorial that introduces you to working with data and files. As you work through this tutorial, you perform the following tasks that step you through creating and using objects for CCS IDE:

  1. Select your processor.

  2. Create and query objects to CCS IDE.

  3. Use MATLAB software to load files into CCS IDE.

  4. Work with your CCS IDE project from MATLAB software.

  5. Close the connections you opened to CCS IDE.

The tutorial provides a working process (a workflow) for using Embedded IDE Link CC and your signal processing programs to develop programs for a range of Texas Instruments™ processors.

During this tutorial, you load and run a digital signal processing application on a processor you select. The tutorial demonstrates both writing to memory and reading from memory in the "Working with Links and Data" portion of the tutorial.

You can use the read and write methods, as described in this tutorial, to read and write data to and from your processor.

The tutorial covers the object methods and functions for Embedded IDE Link CC. The functions listed in the first table apply to CCS IDE independent of the objects — you do not need an object to use these functions. The methods listed in the second and third table requires a ticcs object that you use in the method syntax:

Functions for Working With Embedded IDE Link CC

The following functions do not require a ticcs object as an input argument:

FunctionDescription
ccsboardinfoReturn information about the boards that CCS IDE recognizes as installed on your PC.
clearRemove a specific object to CCS IDE or remove all existing objects.
ticcsConstruct an object to communicate with CCS IDE. When you construct the object you specify the processor board and processor.

Methods for Working with ticcs Objects in Embedded IDE Link CC software

The methods in the following table require a ticcs object as an input argument:

MethodDescription

address

Return the address and page for an entry in the symbol table in CCS IDE.

display

Display the properties of an object to CCS IDE and RTDX.

halt

Terminate execution of a process running on the processor.

info

Return information about the processor or information about open RTDX channels.

isrtdxcapable

Test whether your processor supports RTDX communications.

isrunning

Test whether the processor is executing a process.

read

Retrieve data from memory on the processor.

restart

Restore the program counter (PC) to the entry point for the current program.

run

Execute the program loaded on the processor.

visible

Set whether CCS IDE window is visible on the desktop while CCS IDE is running.

write

Write data to memory on the processor.

Embedded IDE Link CC Methods for Embedded Objects

The methods in the following table enable you to manipulate programs and memory with an embedded object:

MethodDescription

cast

Create a new object with a different datatype (the represent property) from an object in Embedded IDE Link CC. Demonstrated with a numeric object.

convert

Change the represent property for an object from one datatype to another. Demonstrated with a numeric object.

getmember

Return an object that accesses a single field from a structure. Demonstrated with a structure object.

list

Return various information listings from Code Composer Studio software.

read

Read the information at the location accessed by an object into MATLAB software as numeric values. Demonstrated with a numeric, string, structure, and enumerated objects.

readnumeric

Return the numeric equivalent of data at the location. Accessed by an object. Demonstrated with an enumerated object.

write

Write to the location referenced by an object. Demonstrated with numeric, string, structure, and enumerated objects.

Running Code Composer Studio Software on Your Desktop — Visibility

When you create a ticcs object , Embedded IDE Link CC starts CCS in the background.

When CCS IDE is running in the background, it does not appear on your desktop, in your task bar, or on the Applications page in the Task Manager. It does appear as a process, cc_app.exe, on the Processes tab in Microsoft® Windows Task Manager.

You can make the CCS IDE visible with the function visible. The function isvisible returns the status of the IDE—whether it is visible on your desktop. To close the IDE when it is not visible and MATLAB software is not running, use the Processes tab in Microsoft Windows Task Manager and look for cc_app.exe.

If a link to CCS IDE exists when you close CCS, the application does not close. Microsoft Windows software moves it to the background (it becomes invisible). Only after you clear all links to CCS IDE, or close MATLAB software, does closing CCS IDE unload the application. You can see if CCS IDE is running in the background by checking in the Microsoft Windows Task Manager. When CCS IDE is running, the entry cc_app.exe appears in the Image Name list on the Processes tab.

When you close MATLAB software while CCS IDE is not visible, MATLAB software closes CCS if it launched the IDE. This happens because the operating system treats CCS as a subprocess in MATLAB software when CCS is not visible. Having MATLAB software close the invisible IDE when you close MATLAB software prevents CCS from remaining open. You do not need to close it using Microsoft Windows Task Manager.

If CCS IDE is not visible when you open MATLAB software, closing MATLAB software leaves CCS IDE running in an invisible state. MATLAB software leaves CCS IDE in the visibility and operating state in which it finds it.

Running the Interactive Tutorial

You have the option of running this tutorial from the MATLAB software command line or entering the functions as described in the following tutorial sections.

To run the tutorial in MATLAB software, click run ccstutorial. This command launches the tutorial in an interactive mode where the tutorial program provides prompts and text descriptions to which you respond to move to the next portion of the lesson. The interactive tutorial covers the same information provided by the following tutorial sections. You can view the tutorial M-file used here by clicking ccstutorial.m.

Selecting Your Processor

Links for CCS IDE provides two tools for selecting a board and processor in multiprocessor configurations. One is a command line tool called ccsboardinfo which prints a list of the available boards and processors. So that you can use this function in a script, ccsboardinfo can return a MATLAB software structure that you use when you want your script to select a board without your help.

  1. To see a list of the boards and processors installed on your PC, enter the following command at the MATLAB software prompt:

    ccsboardinfo
    

    MATLAB software returns a list that shows you all the boards and processors that CCS IDE recognizes as installed on your system.

  2. To use the Selection Utility, boardprocsel, to select a board, enter

    [boardnum,procnum] = boardprocsel
    

    When you use boardprocsel, you see a dialog box similar to the following. Note that some entries vary depending on your board set.

  3. Select a board name and processor name from the lists.

    You are selecting a board and processor number that identifies your particular processor. When you create the object for CCS IDE in the next section of this tutorial, the selected board and processor become the processor of the object.

  4. Click Done to accept your board and processor selection and close the dialog box.

    boardnum and procnum now represent the Board name and Processor name you selected — boardnum = 1 and procnum = 0

Creating and Querying Objects for CCS IDE

In this tutorial section, you create the connection between MATLAB software and CCS IDE. This connection, or object, is a MATLAB software object that you save as variable cc.

You use function ticcs to create objects. When you create objects, ticcs input arguments let you define other object property values, such as the global timeout. Refer to the ticcs reference documentation for more information on these input arguments.

Use the generated object cc to direct actions to your processor. In the following tasks, cc appears in all function syntax that interact with CCS IDE and the processor:

  1. Create an object that refers to your selected board and processor. Enter the following command at the prompt.

    cc=ticcs('boardnum',boardnum,'procnum',procnum)
    

    If you were to watch closely, and your machine is not too fast, you see Code Composer Studio software appear briefly when you call ticcs. If CCS IDE was not running before you created the new object, CCS launches and runs in the background.

  2. Enter visible(cc,1) to force CCS IDE to be visible on your desktop.

    Usually, you need to interact with Code Composer Studio software while you develop your application. The first function in this tutorial, visible, controls the state of CCS on your desktop. visible accepts Boolean inputs that make CCS either visible on your desktop (input to visible = 1) or invisible on your desktop (input to visible = 0). For this tutorial, use visible to set the CCS IDE visibility to 1.

  3. Next, enter display(cc) at the prompt to see the status information.

    TICCS Object:
      API version      : 1.0
      Processor type   : C67
      Processor name   : CPU
      Running?         : No
      Board number     : 0
      Processor number : 0
      Default timeout  : 10.00 secs
    
      RTDX channels    : 0
    

    Embedded IDE Link CC provides three methods to read the status of a board and processor:

  4. Type linkinfo = info(cc).

    The cc link status information provides information about the hardware as follows:

    linkinfo = 
    
          boardname: 'C6711 Device Simulator'
           procname: 'CPU_1'
        isbigendian: 0
             family: 320
          subfamily: 103
          revfamily: 11
         processortype: 'simulator'
         revsilicon: 0
            timeout: 10
    
  5. Verify that the processor is running by entering

    runstatus = isrunning(cc)
    

    MATLAB software responds, indicating that the processor is stopped, as follows:

    runstatus =
    
         0
    
  6. At last, verify that the processor supports RTDX communications by entering

    usesrtdx = isrtdxcapable(cc)
    usesrtdx =
    
         1
    

Loading Files into CCS

You have established the connection to a processor and board. Using three methods you learned about the hardware, whether it was running, its type, and whether CCS IDE was visible. Next, the processor needs something to do.

In this part of the tutorial, you load the executable code for the processor CPU in CCS IDE. Embedded IDE Link CC includes a CCS project file. Through the next tasks in the tutorial, you locate the tutorial project file and load it into CCS IDE. The open method directs CCS to load a project file or workspace file.

After you have executable code running on your processor, you can exchange data blocks with it. Exchanging data is the purpose of the objects provided by Embedded IDE Link CC software.

  1. To load the appropriate project file to your processor, enter the following command at the MATLAB software prompt. getdemoproject is a specialized function for loading Embedded IDE Link CC demo files. It is not supported as a standard Embedded IDE Link CC function.

    demopjt = 
    
            isLibProj: 0
      TemplateProject: 'C:\Temp\LinkForCCSDemos_v3.2\template\c6x\c67x.pjt'
              DemoDir: 'C:\Temp\LinkForCCSDemos_v3.2\ccstutorial\c6x\c67x'
          ProjectFile: 'C:\Temp\LinkForCCSDemos_v3.2\ccstutorial\c6x\c67x\ccstut.pjt'
          ProgramFile: 'C:\Temp\LinkForCCSDemos_v3.2\ccstutorial\c6x\c67x\ccstut.out'
              SrcFile: {2x1 cell}
              LibFile: ''
              CmdFile: {'$matlabroot\matlab\toolbox\ccslink\ccsdemos\shared\c6x\c6x.cmd'}
              HdrFile: ''
            BuildOpts: [1x1 struct]
        ProjectAction: 'rebuildProg'
          RebuildDemo: 1
    
    demopjt.ProjectFile
    
    ans =
    
    C:\Temp\LinkForCCSDemos_v3.2\ccstutorial\c6x\c67x\ccstut.pjt
    
    demoPjt.DemoDir
    
    ans =
    
    C:\Temp\LinkForCCSDemos_v3.2\ccstutorial\c6x\c67x
    

    Your paths may be different if you use a different processor. Note where the software stored the demo files on your machine. In general, Embedded IDE Link CC software stores the demo project files in

    LinkforCCS_vproduct_version

    Embedded IDE Link CC creates this directory in a location where you have write permission. There are two locations where Embedded IDE Link CC software tries to create the demo directory, in the following order:

    1. In a temporary directory on the C drive, such as C:\temp\.

    2. If Embedded IDE Link CC software cannot use the temp directory, you see a dialog box that asks you to select a location to store the demos.

  2. Next, build the processor executable file in CCS IDE. Select Project > Build from the menu bar in CCS IDE.

    You may get an error related to one or more missing .lib files. If you installed CCS IDE in a directory other than the default installation directory, browse in your installation directory to find the missing file or files. Refer to the path in the error message as an indicator of where to find the missing files.

  3. Enter load(cc,'projectname.out') to load the processor execution file, where projectname is the tutorial you chose, such as ccstut_67x.

  4. You have a loaded program file and associated symbol table. To determine the memory address of the global symbol ddat, enter the following command at the prompt:

    ddata = address(cc,'ddat')
    ddata =
    
      1.0e+009 *
    
        2.1475         0
    

    Your values for ddata may be different depending on your processor.

  5. To convert ddata to a hexadecimal string that contains the memory address and memory page, enter the following command at the prompt:

    dec2hex(ddata)

    MATLAB software displays the following response, where the memory page is 0x00000000 and the address is 0x80000010.

    ans =
    
    80000010
    00000000
    

Working with Projects and Data

After you load the processor code, you can use Embedded IDE Link CC functions to examine and modify data values in the processor.

When you look at the source file listing in the CCS IDE Project view window, there should be a file named ccstut.c. Embedded IDE Link CC ships this file with the tutorial and includes it in the project. ccstut.c has two global data arrays — ddat and idat — that you declare and initialize in the source code. You use the functions read and write to access these processor memory arrays from MATLAB software.

Embedded IDE Link CC provides three functions to control processor execution — run, halt, and restart.

To demonstrate these commands, use CCS IDE to add a breakpoint to line 64 of cctut.c. Line 64 is

printf("Embedded IDE Link CC: Tutorial - Memory Modified by Matlab!\n");

For information about adding breakpoints to a file, refer to your Code Composer Studio User's Guide from Texas Instruments. Then proceed with the tutorial:

  1. To demonstrate the new functions, try the following functions.

    halt(cc)                 % Halt the processor.
    restart(cc)              % Reset the PC to start of program.
    run(cc,'runtohalt',30);  % Wait for program execution to stop at 
                             % breakpoint (timeout = 30 seconds).
    

    When you switch to viewing CCS IDE, you see that your program stopped at the breakpoint you inserted on line 64, and the program printed the following messages in the CCS IDE Stdout tab. Nothing prints in the MATLAB command window:

    Embedded IDE Link CC: Tutorial - Initialized Memory
    Double Data array = 16.3 -2.13 5.1 11.8
    Integer Data array = -1-508-647-7000 (call me anytime!)
    
  2. Before you restart your program (currently stopped at line 64), change some values in memory. Perform one of the following procedures based on your processor.

    C5xxx processor family — Enter the following functions to demonstrate the read and write functions.

    1. Enter ddatv = read(cc,address(cc,'ddat'),'double',4).

      MATLAB software responds with

      ddatv =

         16.3000   -2.1300    5.1000   11.8000
      
    2. Enter idatv = read(cc,address(cc,'idat'),'int16',4).

      Now MATLAB software responds

      idatv =

      -1 508 647 7000

      If you used 8-bit integers (int8), the returned values would be incorrect.

      idatv=read(cc,address(cc,'idat'),'int8',4)

      idatv =

      1 0 -4 1

    3. You can change the values stored in ddat by entering write(cc,address(cc,'ddat'),double([pi 12.3 exp(-1)...
      sin(pi/4)]))

      The double argument directs MATLAB software to write the values to the processor as double-precision data.

    4. To change idat, enter

      write(cc,address(cc,'idat'),int32([1:4]))

      Here you write the data to the processor as 32-bit integers (convenient for representing phone numbers, for example).

    5. Start the program running again by entering the following command:

      run(cc,'runtohalt',30);

      The Stdout tab in CCS IDE reveals that ddat and idat contain new values. Next, read those new values back into MATLAB software.

    6. Enter ddatv = read(cc,address(cc,'ddat'),'double',4).

      ddatv =

      3.1416 12.3000 0.3679 0.7071

      ddatv contains the values you wrote in step c.

    7. Verify that the change to idatv occurred by entering the following command at the prompt:

      idatv = read(cc,address(cc,'idat'),'int16',4)

      MATLAB software returns the new values for idatv.

      idatv =

      1 2 3 4

    8. Use restart to reset the program counter for your program to the beginning. Enter the following command at the prompt:

      restart(cc);

    C6xxx processor family — Enter the following commands to demonstrate the read and write functions.

    1. Enter ddatv = read(cc,address(cc,'ddat'),'double',4).

      MATLAB software responds with

      ddatv =

         16.3000   -2.1300    5.1000   11.8000
      
    2. Enter idatv = read(cc,address(cc,'idat'),'int16',4).

      MATLAB software responds

      idatv =

      -1 508 647 7000

      If you used 8-bit integers (int8), the returned values would be incorrect.

      idatv=read(cc,address(cc,'idat'),'int8',4)

      idatv =

      1 0 -4 1

    3. Change the values stored in ddat by entering write(cc,address(cc,'ddat'),double([pi 12.3 exp(-1)...
      sin(pi/4)]))

      The double argument directs MATLAB software to write the values to the processor as double-precision data.

    4. To change idat, enter the following command:

      write(cc,address(cc,'idat'),int32([1:4]))

      In this command, you write the data to the processor as 32-bit integers (convenient for representing phone numbers, for example).

    5. Next, start the program running again by entering the following command:

      run(cc,'runtohalt',30);

      The Stdout tab in CCS IDE reveals that ddat and idat contain new values. Read those new values back into MATLAB software.

    6. Enter ddatv = read(cc,address(cc,'ddat'),'double',4).

      ddatv =

      3.1416 12.3000 0.3679 0.7071

      Verify that ddatv contains the values you wrote in step c.

    7. Verify that the change to idatv occurred by entering the following command:

      idatv = read(cc,address(cc,'idat'),'int32',4)

      MATLAB software returns the new values for idatv.

      idatv =

      1 2 3 4

    8. Use restart to reset the program counter for your program to the beginning. Enter the following command at the prompt:

      restart(cc);

  3. Embedded IDE Link CC offers more functions for reading and writing data to your processor. These functions let you read and write data to the processor registers: regread and regwrite. They let you change variable values on the processor in real time. The functions behave slightly differently depending on your processor. Select the appropriate procedure for your processor to demonstrate regread and regwrite.

    C5xxx processor family — Most registers are memory-mapped and available using read and write. However, the PC register is not memory mapped. To access this register, use the special functions — regread and regwrite. The following commands demonstrate how to use these functions to read and write to the PC register.

    1. To read the value stored in register PC, enter the following command at the prompt to indicate to MATLAB software the data type to read. The input string binary indicates that the PC register contains a value stored as an unsigned binary integer.

      cc.regread('PC','binary')

      MATLAB software displays

      ans =

      33824

    2. To write a new value to the PC register, enter the following command. This time, binary as an input argument tells MATLAB software to write the value to the processor as an unsigned binary integer. Notice that you used hex2dec to convert the hexadecimal string to decimal.

      cc.regwrite('PC',hex2dec('100'),'binary')

    3. Verify that the PC register contains the value you wrote.

      cc.regread('PC','binary')

    C6xxx processor familyregread and regwrite let you access the processor registers directly. Enter the following commands to get data into and out of the A0 and B2 registers on your processor.

    1. To retrieve the value in register A0 and store it in a variable in your MATLAB workspace. Enter the following command:

      treg = cc.regread('A0','2scomp');

      treg contains the two's complement representation of the value in A0.

    2. To retrieve the value in register B2 as an unsigned binary integer, enter the following command:

      cc.regread('B2','binary');

    3. Next, enter the following command to use regwrite to put the value in treg into register A2.

      cc.regwrite('A2',treg,'2scomp');

      CCS IDE reports that A0, B2, and A2 have the values you expect. Select View > CPU Registers > Core Registers from the CCS IDE menu bar to see a listing of the processor registers.

Working with Embedded Objects

Direct access to the memory on your processor DSP, as provided by the links in Embedded IDE Link CC, can be a powerful tool for developing and troubleshooting your digital signal processing applications. But for programming in C, it might be more valuable to work with memory and data in ways that are consistent with the C variables embedded in your programs.

Embedded IDE Link CC implements this access and manipulation capability by using MATLAB software objects (called embedded objects in this guide) that access and represent variables and data embedded in your project. Various methods that compose Embedded IDE Link CC, such as createobj, convert, and write, help you create the embedded objects you use to work with your data in DSP memory and registers, and let you manipulate the data in MATLAB software and in your code.

The following tutorial sections introduce some of the access and manipulation methods and use them with objects and data.

Method list generates information for you about an embedded variable in the symbol table. An even more useful function is createobj that creates a MATLAB software object that represents a C variable in the symbol table in CCS. Working with the object that createobj returns, you can read the entire contents of a variable, or one or more elements of the variable when the variable is an array or structure.

From the beginning of this tutorial you have used the link object cc with all of the functions. cc represents the path to communicate with a particular processor in CCS. For the remainder of this tutorial you work with a variety of functions that use, not the link object cc, but other objects, such as numeric or structure objects, that represent embedded objects in CCS. These new functions use the object names as the first input argument to the function (the way you used cc). For example, when you create the object cvar in step 4 that follows, cvar represents the embedded variable idat.

To begin, restart the program and use list to get some information about a variable (an embedded object) in CCS.

Using list

  1. To restart the program in CCS, enter the following command:

    restart(cc)
    

    This resets the program counter to the beginning of your program.

  2. To move the program counter (PC) to the beginning of main, which you should do before rerunning your program, enter the following commands at the prompt:

    goto(cc,'main')
    run(cc,'main')
    

    Moving the PC to main ensures that the program initializes the embedded C variables.

  3. Next, to get information about a variable in your program, use list with two input options — 'variable' which defines the type of information to return, and 'idat' which identifies the symbol itself. Enter the following command:

    idatlist = list(cc,'variable','idat')

    idat is a global variable; the input keyword variable identifies it as one. Other keywords for list include project, globalvar, function, and type. Refer to list for more information about these options.

    In your MATLAB software workspace and window, you see a new structure named idatlist. If you use the MATLAB Workspace browser, double-click idatlist in the browser to see idatlist.

  4. Instead of using list to get information about idat, create an object that represents idat in your MATLAB workspace by entering the following command:

    cvar = createobj(cc,'idat')
    

    createobj returns the numeric object cvar.

    cvar=createobj(cc,'idat')
    
    NUMERIC Object stored in memory: 
      Symbol name             : idat
      Address                 : [ 44316 0]
      Data type               : short
      Word size               : 16 bits
      Address units per value : 2 au
      Representation          : signed
      Size                    : [ 4 ]
      Total address units     : 8 au
      Array ordering          : row-major
      Endianness              : little
    

    You use cvar, with the numeric object properties and functions, to access and manipulate the embedded variable idat, both in your MATLAB workspace and in CCS if you write your changes back to CCS from your workspace.

Using read and write

  1. Try the following methods to read and write cvar. Notice the way the return values change as you change the function syntax. Notice also that write actually changes the data in memory on the processor, as you see from what comes back to MATLAB after the third read operation.

    1. Enter read(cvar) at the prompt.

      This syntax returns all of the embedded array cvar to your MATLAB workspace.

      ans =

                 1         508         647        7000
      
    2. Next, enter read(cvar,2) at the prompt.

      This returns only the second element of cvar508.

    3. Enter write(cvar,4,7001) at the prompt.

      This syntax uses write to change the value stored in the fourth element of cvar to 7001.

    4. Next, enter write(cvar,1,'FFFF') to write a new value to cvar.

      This syntax changes the first element of cvar to -1, which is the decimal equivalent of 0xFFFF. When you enter FFFF as a string enclosed in single quotation marks, write converts the string to its decimal equivalent and stores that value at the processor location in memory.

    5. Enter read(cvar) at the prompt to see the values in cvar.

    6. Enter the following command to read the embedded array cvar to verify your changes to the first and fourth elements:

      read(cvar,[1 size(cvar)])

Using cast, convert, and size

read took the raw values of idat stored in processor memory and converted them to equivalent MATLAB software numeric values. How read converts idat elements to numeric values is controlled by the properties of the object cvar that resulted from using createobj to create it.

When you created cvar, the object that accesses the embedded variable idat, createobj assigned appropriate default property values to the properties of cvar for your processor DSP architecture and for the C representation of variable idat.

It may help you develop your program if you change the default conversion properties. Several of the object properties, such as endianness, arrayorder, and size respond to changes made using function set. To make more complex changes, use functions like cast and convert that adjust multiple object property values simultaneously.

In step 6 of this tutorial, you have the opportunity to use cast, convert, and size to modify cvar by changing property values. Unlike read and write, cast, convert, and size (and set mentioned earlier) do not affect the information stored on the processor; they only change the properties of the object in MATLAB software. Unless you write your changes back to your processor, the changes you make in MATLAB software stay in MATLAB software.

  1. To demonstrate changing the properties of cvar using cast, convert, and size, enter the following commands at the prompt. Use read to view the changes each command makes to cvar.

    1. set(cvar,'size',[2])

      idat gets resized to only the first two elements in the array.

    2. read(cvar)

      ans =

      -1 508

      Returns only two values, not the full data set you saw in step 5a.

    3. uintcvar = cast(cvar,'unsigned short')

      uintcvar is a new object, a copy of cvar (and thus idat), but with the datatype property value of unsigned short instead of double. The actual values are not different — only the interpretation. Where cvar interprets the values in idat as doubles, uintcvar interprets the values in idat as unsigned integers with 16 bits each. When you use the object to read idat, the returned values from idat are interpreted differently.

    4. read(uintcvar)

    5. convert(cvar,'unsigned short')

      In contrast to cast, convert does not make a copy of cvar; it changes the datatype property of cvar to be unsigned short.

      NUMERIC Object stored in memory:

      Symbol name : idat

      Address : [ 44316 0]

      Data type : unsigned short

      Word size : 16 bits

      Address units per value : 2 au

      Representation : unsigned

      Size : [ 2 ]

      Total address units : 4 au

      Array ordering : row-major

      Endianness : little

    6. read(cvar)

      ans =

      65535 508

      One of the first things you did in these examples was change the size of cvar to 2. You should see that reflected in the returned values. The values returned by cvar after you change the datatype property should match the values returned by uintcvar because the objects have the same properties.

      The first value of idat is no longer -1, although you changed the value in step 5d. You changed the datatype to unsigned short for cvar, so the first element of idat that you set to -1 is now shown as the unsigned equivalent 65535.

Using getmember

You have worked with fairly simple data in memory on your processor. Functions in Embedded IDE Link CC enable you to manipulate more complex data like strings, structures, bitfields, enumerated data types, and pointers in a very similar way.

The next tutorial examples demonstrate common functions for manipulating structures, strings, and enumerated data types on your processor. Of most importance is the method getmember which extracts a single specified field from a structure on your processor as an object in MATLAB software.

To continue the tutorial, enter the commands shown in the following steps.

  1. cvar = createobj(cc,'myStruct')

    You create a new object cvar, to replace the existing cvar, that represents an embedded structure named myStruct on your processor. One of the defined structures in the tutorial program is myStruct.

    STRUCTURE Object stored in memory: 
      Symbol name             : myStruct
      Address                 : [ 44288 0]
      Address units per value : 28 au
      Size                    : [ 1 ]
      Total Address Units     : 28 au
      Array ordering          : row-major 
      Members                 : 'iy', 'iz'
    
  2. read(cvar)

    ans = 
    
        iy: [2x3 double]
        iz: 'MatlabLink'
    

    Here is the definition of myStruct from ccstut.c in CCS.

    struct TAG_myStruct {
    	int iy[2][3];
    	myEnum iz;
    } myStruct = { {{1,2,3},{4,-5,6}}, MatlabLink}
    
  3. write(cvar,'iz','Simulink')

    This write syntax updates the field iz in myStruct with the enumerated name Simulink. If you look into ccstut.c, you see that iz is an enumerated datatype.

  4. cfield = getmember(cvar,'iz')

    cfield, the object returned by getmember, represents the embedded variable iz in the project. Here is what cfield looks like in property form.

    ENUM Object stored in memory: 
      Symbol name             : iz
      Address                 : [ 44312 0]
      Word size               : 32 bits
      Address units per value : 4 au
      Representation          : signed
      Size                    : [ 1 ]
      Total address units     : 4 au
      Array ordering          : row-major
      Endianness              : little
      Labels & values         : MATLAB=0, Simulink=1, SignalToolbox=2, 
    MatlabLink=3, EmbeddedprocessorC6x=4
    
  5. write(cfield,4)

  6. read(cvar)

    ans = 
    
        iy: [2x3 double]
        iz: 'EmbeddedprocessorC6x'
    

    The command write(cfield,4) replaced the string MatlabLink with the fourth value EmbeddedprocessorC6x. That is an example of writing to an embedded variable by value.

  7. cstring = createobj(cc,'myString')

    createobj returns the object cstring that represents a C structure embedded in the project. When you omit the closing semicolon on the command, MATLAB software displays the object properties.

    STRING Object stored in memory: 
      Symbol name             : myString
      Address                 : [ 44360 0]
      Word size               : 8 bits
      Address units per value : 1 au
      Representation          : signed
      Size                    : [ 29 ]
      Total address units     : 29 au
      Array ordering          : row-major
      Endianness              : little
      Char conversion type    : ASCII
    

    The properties provide details about cstring.

  8. read(cstring)

    MATLAB software displays the contents of cstring

    ans =
    
    Treat me like an ASCII String 
    
  9. write(cstring,7,'ME')

    This command changes the seventh element of MyString to ME. When you reread cstring, me should be replaced by ME.

  10. read(cstring)

    ans =
    
    Treat ME like an ASCII String 
    
  11. write(cstring,1,127)

    write changes the contents of the first element of MyString to the ASCII character 127 — a nonprinting character.

  12. readnumeric(cstring)

    Using readnumeric with a string object input argument returns the numeric equivalent of the characters in MyString, as shown in the following program listing:

    ans =
    
      Columns 1 through 12 
    
       127   114   101    97   116    32    77    69    32   108   105   107
    
      Columns 13 through 24 
    
       101    32    97   110    32    65    78    83    73    32    83   116
    
      Columns 25 through 29 
    
       114   105   110   103     0

Closing the Links or Cleaning Up CCS IDE

Objects that you create in Embedded IDE Link CC software have COM handles to CCS. Until you delete these handles, the CCS process (cc_app.exe in the Microsoft Windows Task Manager) remains in memory. Closing MATLAB software removes these COM handles automatically, but there may be times when it helps to delete the handles manually, without quitting the application.

Use clear to remove objects from your MATLAB software workspace and to delete handles they contain. clear all deletes everything in your workspace. To retain your MATLAB software data while deleting objects and handles, use clear objname. This applies both to ticcs objects your create with ticcs and other object you create with createobj. To remove the objects created during the tutorial, the tutorial program executes the following command at the prompt:

clear cvar cfield uintcvar

This tutorial also closes the project in CCS with the following command:

close(cc,projfile,'project')

To delete your link to CCS, enter clear cc at the prompt.

Your development tutorial using Code Composer Studio IDE is done.

During the tutorial you

  1. Selected your processor.

  2. Created and queried links to CCS IDE to get information about the link and the processor.

  3. Used MATLAB software to load files into CCS IDE, and used MATLAB software to run that file.

  4. Worked with your CCS IDE project from MATLAB software by reading and writing data to your processor, and changing the data from MATLAB software.

  5. Created and used the embedded objects to manipulate data in a C-like way.

  6. Closed the links you opened to CCS IDE.

  


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