C28x Creating a Static Library from Modular Code

From Texas Instruments Wiki
Jump to: navigation, search

Introduction

This wiki will show you how to create, with the help of an example, a static library in CCS4 from modular source code that can then be reused in other projects

Folder Structure

We have taken the pid_reg3 source and header file from an old version of the Digital Motor Control (DMlibrary and created a new library from it. We used the following directory structure( see Table and Figure below)

TABLE 1 Directory Structure for the PID library
Directory Description Directory Structure for the PID library
<base> Base install directory. For this example it is C:\TI\controlSUITE\libs\DMC\PID\v100
<base>\doc Documentation including the revision history from the previous release.
<base>\lib The built library
<base>\include Include files for the library functions. These include function prototypes and structure definitions.
<base>\source Source files for the library. This also includes a Code Composer Studio project that can be used to re-build the library if required.
<base>\example_ccsv4 Example projects for the library functions. This includes example projects that show how to call library functions in Code Composer Studio project.


Once the directory structure is in place we copied over pid_reg3.c(from the old library) into the source folder and its associated header files,pid_reg3.h and dmctype.h into the include folder.


Creating the Library in CCSv4

Creating the project in CCSv4


Start up CCS with the workspace in the source folder

C:\TI\controlSUITE\libs\DMC\PID\v100\source

and start a new project

Creating a new CCS project


Continue through the successive pop-up menus until you reach the following popup screen. Select the output type to be aStatic Library
Setting the Output to a Static Library


Create a macros.ini file with the following contents and place it in the project folder, INSTALLROOT_TO_PID = ../../


We use these macros to create relative paths to point to source files included in project, header files, command linker files and such. We try to avoid full pathnames when creating projects. The ../ tells CCS to go up one level in the folder structure.So now that we are in the project folder, ../../ tells CCS to go up 2 folders to v100.


The effect is essentially,
INSTALLROOT_TO_PID = C:\TI\controlSUITE\libs\DMC\PID\v100

We will show you how to use these macros in the coming section



Once you have created the macros.ini file, delete the project and re-import into the workspace. The reason for doing this is that the macros.ini file is only read when the project is first imported. The workspace should look like this




Where does the macro point to




Workspace


Build Settings

Go to the Build properties for the project and under Tool Settings -> C2000 Compiler -> Include Options add the following path to the list of search paths,${INSTALLROOT_TO_PID}/include



Under Runtime Model Options, select the large memory model and the unified memory option. If you will be using floaring point or CLA support, select the appropriate boxes

NOTE: If you build your library without fpu32 support and then decide to use it in a floating point device, you will need to recompile with floating point support. We usually add fpu32 as a suffix to the library to distinguish it from its fixed point counterpart, e.g C28x_DMC_PID_fpu32.lib


Finally go to the Build Settings tab and edit the artifact name as follows, ${INSTALLROOT_TO_PID}/lib/C28x_DMC_PID

C28x CreatingModularLibs Figrure6.JPG










This way you don’t have to manually copy the .lib output into the lib folder and if the version number of the project changes it will automatically adjust as we are using relative paths instead of full path names.

Finally, compile the project. The built library(.lib) file should be in the lib folder

C28x CreatingModularLibs Figrure7.JPG









Using the Library


In order to use this library in another project, say the HVACI_Scalar project in the High Voltage development kit, you would first add the following macro to the macros.ini file in the HVACI_Scalar project folder,



INSTALLROOT_TO_PID = ../../../libs/DMC/PID




This tells CCS to go up 3 folders to the root folder and then down 3 to the PID folder as shown in the figure on the righ.



The effect is to haveINSTALLROOT_TO_PID = C:\TI\controlSUITE\libs\DMC\PID\



Using a macro to point to the library folder


Go to the project’s build propeties, Tool Settings -> C2000 linker -> File Search Path and add C28x_DMC_PID.lib as an included library and where to find it in the search path

as ${INSTALLROOT_TO_PID}/v100/libs


All that’s left is to include the header file pid_reg3.h in the project header file, HVACI_Scalar.h. Now you will be able to use the functions defined in pid_reg3 in your code


File Search Path for the project