Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform

TargetLink Application Note
Generating TargetLink
Code and ASAP2 Files for
an Arbitrary Platform
Example for the Fujitsu MB91F467D Microcontroller
with SOFTUNE C/C++ Compiler
Version 1.0
April 2009
TargetLink Application Note
How to Contact dSPACE
Mail:
Tel.:
Fax:
E-mail:
Web:
dSPACE GmbH
Technologiepark 25
33100 Paderborn
Germany
++49 5251 1638-0
++49 5251 66529
info@dspace.de
http://www.dspace.com
How to Contact dSPACE Support
There are different ways to contact dSPACE Support:
• Visit our Web site at http://www.dspace.com/goto?support
• Send an e-mail or phone:
• TargetLink Technical Support:
support.tl@dspace.de
+49 5251 1638-700
• Use the dSPACE Support Wizard:
• On your dSPACE DVD at \Diag\Tools\dSPACESupportWizard.exe
• Via Start – Programs – dSPACE Tools (after installation of the dSPACE software)
• At http://www.dspace.com/goto?supportwizard
You can always find the latest version of the dSPACE Support Wizard here.
dSPACE recommends that you use the dSPACE Support Wizard to contact dSPACE Support.
Software Updates and Patches
dSPACE strongly recommends that you download and install the most recent patches for your current
dSPACE installation. Visit http://www.dspace.com/goto?support for software updates and patches.
Important Notice
This document contains proprietary information that is protected by copyright. All rights are reserved.
Neither the documentation nor software may be copied, photocopied, reproduced, translated, or reduced
to any electronic medium or machine-readable form, in whole or in part, without the prior written consent
of dSPACE GmbH.
© Copyright 1998 - 2009 by:
dSPACE GmbH
Technologiepark 25
33100 Paderborn
Germany
AutomationDesk, CalDesk, ConfigurationDesk, ControlDesk, SystemDesk and TargetLink are registered
trademarks of dSPACE GmbH in the United States or other countries, or both. Other brand names or
product names are trademarks or registered trademarks of their respective companies or organizations.
This publication and the contents hereof are subject to change without notice. dSPACE GmbH makes no
warranty of any kind with regard to this publication, including but not limited to the implied warranties of
merchantability or fitness for a particular purpose. dSPACE GmbH shall not be liable for errors contained
herein or direct, indirect, special, incidental, or consequential damages in connection with the furnishing,
performance, or use of this publication.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
2
TargetLink Application Note
Contents
1
INTRODUCTION............................................................................................................................... 4
2
WHY SOME PLATFORM-SPECIFIC SETTINGS ARE NECESSARY ............................................ 5
3 SETTING UP TARGETLINK FOR CODE AND ASAP2 FILE GENERATION FOR A SPECIFIC
PLATFORM............................................................................................................................................. 7
3.1 PLATFORM-SPECIFIC TARGETCONFIG.XML FILE FOR CODE AND ASAP2 FILE GENERATION ............. 7
3.2 PLATFORM-SPECIFIC HEADER-FILES FOR FIXED-POINT LIBRARY FUNCTIONS/MACROS .................. 10
3.2.1 Creation of the tllimits.h Header-File.................................................................................. 10
3.2.2 Creation of the tl_types.h Header-File ............................................................................... 12
3.3 SPECIFYING A NEW PLATFORM FOR CODE GENERATION ............................................................... 12
4
GENERATING PRODUCTION CODE AND ASAP2 FILES FOR THE PLATFORM .................... 14
4.1
4.2
4.3
GENERATING PRODUCTION CODE FOR THE NEW PLATFORM ......................................................... 14
GENERATING AN ASAP2 FILE FOR THE NEW PLATFORM ............................................................... 15
NOTES ON INTEGRATING TARGETLINK CODE FILES IN THE ECU BUILD PROCESS........................... 18
5
SUMMARY OF REQUIRED STEPS............................................................................................... 21
6
REFERENCES................................................................................................................................ 22
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
3
TargetLink Application Note
1 Introduction
TargetLink
®
is
the
production
code
generator
from
dSPACE,
designed
to
implement
®
Simulink /Stateflow /TargetLink models as highly efficient production code ready for deployment on an electronic
control unit (ECU).
This application note will show how to generate and deploy TargetLink code for platforms, i.e. processor/compiler
combinations, for which TargetLink provides no special support. Although platform-independent ANSI-C code is
generated by TargetLink, there are a few configurations which have to be set for the individual platform. These
steps will be demonstrated, taking the Fujitsu MB91F467D microcontroller with SOFTUNE C/C++ compiler as a
concrete example. Both the Fujitsu MB91F467D microcontroller and the SOFTUNE C/C++ compiler are
products of FUJITSU MICROELECTRONICS. For platforms directly supported by TargetLink, either as a Target
Simulation Module (TSM) or a Target Optimization Module (TOM), the described steps are not necessary
because the TargetLink installation already contains the required files with the proper settings.
The instructions given in this application note are valid for TargetLink 2.0 and subsequent versions at the time of
writing.
Please note that dSPACE makes no warranty of any kind with regard to this publication, including but not limited
to the described settings for using the Fujitsu MB91F467D microcontroller / SOFTUNE C/C++ compiler in
conjunction with TargetLink.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
4
TargetLink Application Note
2 Why Some Platform-Specific Settings Are
Necessary
Because TargetLink models themselves are entirely platform-independent, they can be used to generate code
and ASAP2 files for practically any platform. However, to adapt the code and ASAP2 file generation process to a
specific platform, you must provide some platform-specific files and settings. They are required especially for the
following reasons:
•
TargetLink uses platform-independent base types like Int16, Int8, UInt32 etc. in the generated code (see
the code fragment in Figure 2). These base types have to be mapped onto ANSI-C built-in types like int,
short, char etc. according to the targeted C compiler. This mapping of TargetLink base types onto ANSI-C
built-in types is platform-dependent and has to be specified in a target configuration file called
TargetConfig.xml.
•
For multirate/multitasking code generation in TargetLink, you need to specify whether read/write access for
TargetLink base types like Int16, Int32 etc. is atomic for a specific platform or not. A read/write operation
is atomic and hence data integrity is automatically maintained if no preemption can occur during the
operation. If data access to a base type is not atomic, TargetLink has to undertake protection measures to
ensure that the integrity of the base type is maintained whenever a signal of that base type is read or written
to. TargetLink provides various protection measures to do that, for instance a call to disable all interrupts
during a read/write operation for a variable. See Figure 1 top for a simple multitasking model and the code
fragment in Figure 2. Information regarding the atomicity for individual data types is also specified in
TargetConfig.xml.
•
TargetLink is shipped with a collection of efficient fixed-point library functions and macros to implement fixedpoint arithmetic, e.g. a fixed-point square root function (see Figure 1 bottom and the code fragment in Figure
2). Some parts of the library’s implementation depend on the byte order of the platform (little endian vs. big
endian), alignment (are the data types aligned along bytes, words or double words?) as well as on the
numerical limits of individual data types. These settings are specified in the header files tllimits.h and
tl_types.h. The files are required for compiling functions and macros of TargetLink’s fixed-point library DSFxp.
•
ASAP2 files used for accessing calibration and measurement variables on an ECU contain platformdependent information like byte order or the alignment of individual data types in the ECU memory. To
properly access these variables with calibration and measurement tools like CalDesk you must specify
properties in the TargetConfig.xml file to ensure proper ASAP2 file generation by TargetLink.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
5
TargetLink Application Note
Figure 1: Top: Multitasking model fragment with two tasks (Task_A and Task_B) that exchange a signal whose
read/write access needs to be protected against undesired preemption. The platform-dependent atomicity of the
signal’s data type determines whether the generated code requires protection mechanisms or not. Bottom:
Task_A contains a square root block implemented by one of TargetLink’s fixed-point library functions, see Figure
2.
Figure 2: Code generated for Task_A of Figure 1. The code contains platform-independent TargetLink base
types like Int32 which need to be mapped onto ANSI-C built-in types like long, int etc. Moreover, protection
mechanisms (SuspendAllInterrupts() and ResumeAllInterrupts()) against preemption are applied
since it is assumed that data access to an Int32 data type is not atomic in the example above. The code for
Task_A also contains the call of a TargetLink fixed-point function (C_I32SQRTI32) to calculate the square root
of a signal. The function is part of TargetLink’s fixed-point library DSFxp, which also requires some platformspecific settings for proper compilation.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
6
TargetLink Application Note
3 Setting Up TargetLink for Code and ASAP2
File Generation for a Specific Platform
Adapting the code and ASAP2 file generation process to an individual platform entails the following steps:
•
Provide a TargetConfig.xml file to specify platform-dependent information regarding TargetLink’s base
types. This enables TargetLink to properly generate code as well as ASAP2 files.
•
Provide tllimits.h and tl_types.h files to ensure proper compilation of TargetLink’s fixed-point library
functions, see [1]. This is necessary because TargetLink’s fixed-point library contains a number of
preprocessor macros as well as data types that must be defined properly for the individual platform.
•
Adapt the tl_global_options.m file to make the new code generation target available from the TargetLink
Main Dialog.
These steps will be described in the following subsections. A Fujitsu MB91F467D microcontroller with SOFTUNE
C/C++ compiler [3] will be taken as a concrete example of a specific platform.
3.1 Platform-Specific TargetConfig.xml File for Code and
ASAP2 File Generation
To generate code and ASAP2 files for a specific platform that is not intrinsically supported by TargetLink, you
must create a TargetConfig.xml file for that platform. The file serves to specify information regarding the mapping
of TargetLink´s base types like Int16, UInt8 etc. onto ANSI-C built-in types like int, short etc. This file must
also contain information on the alignment, the byte order, and the atomicity of individual data types. Optionally, it
is also possible to specify address qualifiers like far, near etc. The content of the file is used for code generation
as well as ASAP2 file generation.
In order to create the TargetConfig.xml file, it is strongly recommended to start with the template file provided
under %TL_Root%\Matlab\Tl\SrcFiles\Generic\TargetConfigTemplate.xml. This template contains descriptions
for the required XML elements as well as the permitted values. The template file should be copied to a separate
directory created for the new platform (described in a subsequent section), renamed TargetConfig.xml and
modified according to the platform-specific properties (see below). As an alternative to starting with the template
file, you could also use one of the existing TargetConfig.xml files provided under %TL_Root%\Matlab\Tl\SrcFiles
that closely resembles your new platform as a starting point.
For each TargetLink base type like Int16, UInt8 etc. listed in the template, you have to specify the platformspecific elements described in Table 1. In general, you need to look up the required settings in the respective
compiler/microcontroller manual. In addition to the elements listed in Table 1, you can also specify properties for
the default floating-point type for your platform in TargetConfig.xml, see Table 2, which generally leads to more
efficient code.
Figure 3 shows an excerpt from the SOFTUNE C/C++ compiler manual providing information regarding C data
types on that platform while Figure 4 shows an excerpt from the accordingly specified TargetConfig.xml file.
Obviously, 16-bit data types are represented by short or unsigned short ANSI-C data types. Access to them is
atomic, the byte order is “big endian” and they are aligned along words (2 bytes). This information comes from the
manual of the SOFTUNE C/C++ compiler. Examples of TargetConfig.xml files for platforms that are intrinsically
supported by TargetLink can be found under %TL_Root%\Matlab\Tl\SrcFiles\.
The TargetConfig.xml file can also be used to specify address qualifiers like near, far etc. for those platforms
where they exist. 16 bit targets often use such qualifiers to mark objects that are placed at a memory location with
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
7
TargetLink Application Note
an address of more than 16 bits. In TargetLink, such address qualifiers can be set in the Data Dictionary, e.g. at
the TypePrefix property of a Variable Class. Using such a Variable Class will then tell TargetLink to prefix variable
declaration/definitions with this type prefix. Moreover, TargetLink will use inheritance of type prefixes e.g. for
generating pointers to such variables in the production code. Because of this inheritance mechanism, TargetLink
must know the address qualifier keywords. To specify those keywords, the TargetConfig.xml file provides the
AddressQualifiers DDObject XML element with the following child elements:
<ddObj name="Far" Kind="GenericObject">
<ddProperty Name="Description"
Type = "String">Data that is accessed with the far addressing
scheme</ddProperty>
<ddProperty Name="PrefixString" Type = "String">@far</ddProperty>
</ddObj>
Use one set of elements as above to specify the name, Description, and PrefixString for each such qualifier. For
details, please see the template file or the TargetConfig.xml file for the C16x platform and modify it according to
your needs. Consult the compiler/CPU manual and also your ECU build environment and its settings for that
purpose.
Elements
Permissible Values
Description
Description
Arbitrary string
A description of the base type
NumberOfBits
(1), 8, 16, 32, 64
Bit length of the base type’s implementation; for Int8 the value
must be set to 8; for Int16 it must be set to 16.
CodedType
ANSI C data type like int,
ANSI-C built-in type that represents the base type
char, etc.
Min / Max
Integer number
Numeric limits for the base type
Alignment
OneByte, TwoBytes,
Alignment of the base type in memory. Auto only has relevance
FourBytes, EightBytes,
for structs on specific platforms
SixteenBytes, Auto
ByteOrder
MSB_FIRST
MSB_LAST
MSW_FIRST_MSB_LAST
MSW_LAST_MSB_FIRST
Specifies how integer values are stored as bytes in memory:
Most Significant Byte First (“big endian”)
Most Significant Byte Last (“little endian”)
Most Significant Word First / Byte Last
Most Significant Word Last / Byte First
AtomicAccess
on, off
Read/Write of the base type is an atomic instruction (‘on’) or not
(‘off’)
Table 1: Required XML elements along with the permissible values for the TargetConfig.xml file. The ByteOrder
and the Alignment elements are required for ASAP2 file generation. Please consult the template file for further
assistance.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
8
TargetLink Application Note
Element
Permissible Values
Description
MathLibFloatType
Float32,
Float64
Floating-point type used for some calls to the
floating-point library; helps to avoid superfluous
typecasts, e.g. if library is only 32bit float based
AuxFloatType
Float32,
Float64
Floating-point type used to create auxiliary
variables not explicitly specified in the model
Table 2: Properties regarding the generation of floating-point typecasts and variables.
Figure 3: Excerpt from the SOFTUNE C/C++ compiler manual showing sizes as well as alignment of ANSI-C
built-in types.
Figure 4: Excerpt from the TargetConfig.xml file for the MB91F467D microcontroller / SOFTUNE C/C++ compiler.
It shows the mapping of the TargetLink base types Int16 and UInt16 onto ANSI-C built-in types for the
SOFTUNE C/C++ compiler, along with the byte order and the alignment for these data types. The file also
specifies the access to Int16 and UInt16 data types as atomic and hence free from potential undesired
preemption.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
9
TargetLink Application Note
During code generation, TargetLink creates a file called tl_basetypes.h, which contains the mapping of
TargetLink base types onto ANSI-C built-in types. This is based on the information provided in TargetConfig.xml.
For the Fujitsu MB91F467D microcontroller, the generated tl_basetypes.h file is as shown in Figure 5.
#ifndef _TL_BASETYPES_H_
#define _TL_BASETYPES_H_
typedef unsigned char Bool; /* boolean basetype */
typedef float Float32; /* 32 bit floating-point basetype */
typedef double Float64; /* 64 bit floating-point basetype */
typedef signed short int Int16; /* 16 bit signed integer basetype */
typedef signed long int Int32; /* 32 bit signed integer basetype */
typedef signed char Int8; /* 8 bit signed integer basetype */
typedef unsigned short int UInt16; /* 16 bit unsigned integer basetype */
typedef unsigned long int UInt32; /* 32 bit unsigned integer basetype */
typedef unsigned char UInt8; /* 8 bit unsigned integer basetype */
typedef void Void; /* void basetype */
#endif/*_TL_BASETYPES_H_ */
Figure 5: Excerpt from tl_basetypes.h created during code generation for the Fujitsu MB91F467D
microcontroller/SOFTUNE C/C++ compiler. It shows the mapping of TargetLink base types onto ANSI-C built-in
types.
3.2 Platform-Specific Header-Files for Fixed-Point Library
Functions/Macros
For certain fixed-point operations like square root calculation, 64-bit arithmetic, etc. TargetLink provides an
efficient fixed-point library called DSFxp. To properly compile TargetLink code containing fixed-point library
functions/macros or to compile the entire fixed-point library separately to generate a lib-file, you must create or
adapt the following two header-files for the individual processor/compiler combination:
•
tllimits.h
•
tl_types.h
3.2.1 Creation of the tllimits.h Header-File
The file tllimits.h is required in order to compile individual functions/macros from the fixed-point library. Hence, if a
certain TargetLink model requires the call of a fixed-point function/macro or if a separate lib file should be created
for the entire fixed-point library, it is necessary to create a proper tllimits.h file for the individual platform. tllimits.h
is included in the dsfxp.h header file of the fixed-point library which itself is included in TargetLink generated code,
whenever functions/macros from the fixed-point library are used. tllimits.h has to contain a few preprocessor
directives for alignment, byte order and min/max values for individual base types as described in Table 3.
As a starting point to create the platform-specific tllimits.h file, it is a good strategy to use one of the existing
tllimits.h provided under %TL_Root%\Matlab\Tl\SrcFiles as a starting point. Choose the tllimits.h file of a platform
that closely resembles your own, copy the tllimits.h file to a separate directory (described in a subsequent section)
and modify it according to the requirements of your platform. In general, the necessary specifications for the
preprocessor directives in tllimits.h need to be looked up in the processor/compiler manual or in the header files
provided by the compiler vendor.
An excerpt from a tllimits.h file for the Fujitsu MB91F467D microcontroller/SOFTUNE C/C++ compiler is shown in
Figure 6. The macros FUJITSU and COMP_SOFTUNE are arbitrary and not required. However they can be used
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
10
TargetLink Application Note
for platform-dependent compilation of TargetLink Custom Code blocks. The respective custom code fragments
then simply have to be enclosed in the proper preprocessor directives.
Preprocessor Defines
Permissible
Description
Values
LITTLE_ENDIAN
BIG_ENDIAN
You must define the byte order of a word in
memory either as LITTLE_ENDIAN or
or
BIG_ENDIAN in accordance with the respective
platform. An improper setting can lead to faulty
library code.
ALIGN
1 or 2 or 4
The ALIGN directive must be set to the
maximum alignment of all primitive non-floating
point data types on that platform, see Figure 3.
On a 16-bit processor, it is typically 2; on a 32bit processor, it is typically 4.
<Type>Max
<Type>Min
Numeric integer
Min and max values for TargetLink’s base types
value
on the individual platform.
Table 3: Required preprocessor defines in tllimits.h.
#ifndef __tllimits_h__
#define __tllimits_h__
#define
#define
#define
#define
BIG_ENDIAN
ALIGN 4
FUJITSU
COMP_SOFTUNE
#define
#define
#define
#define
#define
#define
INT8MAX
INT8MIN
INT16MAX
INT16MIN
INT32MAX
INT32MIN
127
(-INT8MAX -1)
32767
(-INT16MAX -1)
2147483647L
(-INT32MAX -1L)
#define
#define
#define
#define
#define
#define
UINT8MAX
UINT8MIN
UINT16MAX
UINT16MIN
UINT32MAX
UINT32MIN
255
0
65535
0
4294967295L
0
#define
#define
#define
#define
FLOAT32MAX
FLOAT32MIN
FLOAT64MAX
FLOAT64MIN
3.402823466E+38F
-3.402823466E+38F
1.7976931348623157E+308
-1.7976931348623157E+308
#endif
Figure 6: Excerpt from the tllimits.h file for the Fujitsu MB91F467D microcontroller/SOFTUNE C/C++ compiler. In
general, the compiler vendor provides a limits.h file from which the required limits can be easily extracted.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
11
TargetLink Application Note
3.2.2 Creation of the tl_types.h Header-File
A platform-specific tl_types.h file must only be provided by the user if he wants to create a lib-file for TargetLink’s
fixed-point library in a separate build process. If you compile TargetLink-generated code though, you do not have
to provide a tl_types.h file because TargetLink creates one on its own, based on the specifications in
TargetConfig.xml. The files of TargetLink’s fixed-point library contain include directives for tl_types.h, which is why
the file must be provided for the library build. tl_types.h has to contain typedef statements to define the mapping
between TargetLink base types like Int16 or UInt32 (they are used in the fixed-point library) and ANSI-C
built-in types like int, long etc.
As a starting point to create the tl_types.h, it is a good strategy to use one of the existing tl_types.h provided
under %TL_Root%\Matlab\Tl\SrcFiles as a starting point. Choose the tl_types.h file of a platform that closely
resembles your own and copy the tl_types.h file to a separate directory used for the build of the fixed-point library.
Modify tl_types.h according to the mapping between TargetLink base types and ANSI-C types as specified in the
TargetConfig.xml file for your platform. For the MB91F467D / SOFTUNE C/C++ compiler platform, the proper
tl_types.h file for the library build should look like this:
#ifndef _TL_TYPES_H_
#define _TL_TYPES_H_
typedef
typedef
typedef
typedef
typedef
typedef
typedef
typedef
typedef
typedef
typedef
void
void
signed char
unsigned char
signed short int
unsigned short int
signed long int
unsigned long int
float
double
unsigned char
ErrorType;
Void;
Int8;
UInt8;
Int16;
UInt16;
Int32;
UInt32;
Float32;
Float64;
Bool;
#endif
Again, please note that the creation of tl_types.h is necessary only if you want to build the TargetLink fixed-point
library separately to create a lib-file. Otherwise, TargetLink generates a tl_types.h file on its own during code
generation anyway.
3.3 Specifying a New Platform for Code Generation
After the platform-specific files TargetConfig.xml and tllimits.h have been created properly, you need to add a new
code generation target to the TargetLink options. For this purpose, the newly created files TargetConfig.xml and
tllimits.h are stored in a subdirectory of %TL_Root%\Matlab\Tl\SrcFiles, see Figure 7. Please note that the userprovided tl_types.h file (see previous section) is used only if you want TargetLink’s DSFxp library to be compiled
in a separate build process, not to generate code or ASAP2 files.
To inform TargetLink of the new code generation target, you must modify the configuration file
%TL_Root%\Matlab\Tl\config\tl_global_options.m, which is part of the regular TargetLink installation, by inserting
a few lines of M-code. For the Fujitsu MB91F467D/SOFTUNE C/C++ platform, adjustments are displayed in
Figure 8. Additional code generation targets can be inserted accordingly. The changes take effect immediately
after a new initialization of TargetLink, i.e. after the matlabrc file has been executed or MATLAB has been
restarted.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
12
TargetLink Application Note
Figure 7: Storing the TargetConfig.xml and the tllimits.h file for the Fujitsu MB91F467D
microcontroller/SOFTUNE C/C++ compiler to support a new code generation target for TargetLink. The names of
the subdirectories below %TL_Root%\Matlab\Tl\SrcFiles are arbitrary, but should reflect microcontroller/compiler
names for clarity.
Figure 8: Excerpt from the tl_global_options.m file which has been edited to support code generation for the
Fujitsu MB91F467D microcontroller/SOFTUNE C/C++ compiler. codeopt(i).name specifies the name of the
target to be selected in the TargetLink Main Dialog upon code generation. The name is arbitrary but should be
indicative of the processor/compiler combination. codeopt(i).targetDir specifies the directory that contains
the TargetConfig.xml file, see Figure 7. The other options always have to be set to ‘Generic‘ and ‘’ (empty) for
newly defined code generation targets.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
13
TargetLink Application Note
4 Generating Production Code and ASAP2
Files for the Platform
4.1 Generating Production Code for the New Platform
After you have provided the platform-specific files and specified the new code generation target, you can now
generate code for the new platform (in this example, the Fujitsu MB91F467D microcontroller/SOFTUNE C/C++
compiler). To do so, simply select the proper platform in the code generation options of the TargetLink Main
Dialog, see Figure 9. This makes code generation for the newly defined target available at the click of a button.
TargetLink generates all code files into the current MATLAB directory or in a subdirectory of it. Please note that in
order to build the final ECU executable, it is usually necessary to include TargetLink’s fixed-point library files in the
build process. This is described in a subsequent section.
Figure 9: Setting the Fujitsu MB91F467D microcontroller/SOFTUNE C/C++ compiler as code generation target in
the TargetLink Main Dialog. By clicking on the Generate Code button, code is generated specifically for the
desired platform, taking the information in TargetConfig.xml into account.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
14
TargetLink Application Note
4.2 Generating an ASAP2 File for the New Platform
To generate an ASAP2 file, you must first generate code for your platform as described in the previous section.
As a consequence, TargetLink automatically creates
•
A new node in the Subsystems area of the Data Dictionary which contains information on all variables
created during the code generation run. This node will be the primary source for a subsequent ASAP2 file
generation process.
•
A new Application node in the Data Dictionary which will be subsequently extended with platform specifics
which are also required for ASAP2 file generation
Before ASAP2 files can be generated, it is necessary to extend the Application node with an additional build node
object using the Manage Build tool from the Tools menu of the Data Dictionary Manager, see Figure 10. The
Manage Build tool is used to copy platform-specific information characterizing the platform from TargetConfig.xml
into a Build node object so that it is available for a subsequent ASAP2 file generation, see Figure 11.
Using the Manage Build tool, you have to specify
•
The Application node under which the new Build node is to be created. Select the Application node created
by TargetLink during the code generation run for your platform.
•
The name for a Build node object to be created below the Application node. The name is arbitrary and the
Manage Build tool creates the node from scratch if it does not yet exist.
•
A Target Info file which is relevant only if ASAP2 files with variable addresses are generated. This is possible
only for those platforms that are intrinsically supported by TargetLink (Target Simulation Module), not for
arbitrary platforms. Hence, you should simply select the Target Info file which is normally used for the host
PC under %TL_Root%\MATLAB\tl\SimFiles\HostPC\LCC\target_info.m.
•
The TargetConfig.xml file which you have created for your platform.
•
No Linker Map file is to be specified since parsing a Linker Map file to extract variable addresses is only
supported for those platforms which are part of TargetLink’s Target Simulation Module.
Upon execution of the Manage Build tool, a new Build node object is created and platform specifics from
TargetConfig.xml are copied to the Build node, see Figure 12. This information is required for the subsequent
ASAP2 file generation.
The generation of the ASAP2 file is now carried out as usual, for instance by using the ASAP2 (a2l) file export
dialog of the Data Dictionary Manager, see Figure 13. Particularly the following objects need to be selected:
•
The Subsystem node as a source for the ASAP2 file export. The node was created upon code generation
and contains all the information regarding the generated variables.
•
The Build node which has been created using the Manage Build Tool. The Build node contains the platformspecific information.
The other properties are selected as usual. The ASAP2 (a2l) file is generated into the current MATLAB directory.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
15
TargetLink Application Note
Figure 10: During a successful code generation run, TargetLink creates a new node in the Subsystems area
(called “Multirate_Controller” here) and an Application node (called “multirate” here). Before ASAP2 file
generation, it is now necessary to extend the “multirate” Application node with an underlying Build node object.
This should be done using the Manage Build tool.
Figure 11: Using the Manage Build tool to extend the “multirate” Application node with a Build node called
Build_Fujitsu containing the platform-specific settings in TargetConfig.xml.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
16
TargetLink Application Note
Figure 12: The Manage Build tool has created a new Build node (called Build_Fujitsu here).
Figure 13: ASAP2 file generation using the export dialog of the Data Dictionary Manager.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
17
TargetLink Application Note
Please note that the ASAP2 file created by TargetLink does not contain variable addresses unless the platform is
among those directly supported by TargetLink’s TSM (Target Simulation Module), as including the variable
addresses in the ASAP2 file would require reading address information from a Linker Map file, as produced by the
software build process. Since such linker Map files are platform-specific, TargetLink supports address generation
only for its natively supported platforms included in the Target Simulation Module. Hence, the ASAP2 file that
TargetLink generates for an arbitrary microcontroller, e.g. a Fujitsu MB91F467D, does not contain variable
addresses. However, many calibration tools support a subsequent update of ASAP2 files with actual variable
addresses.
Instead of using dialogs of the Data Dictionary Manager to generate ASAP2 files, it is also possible to generate an
ASAP2 file via M-API using the dsdd_export_a2l_file command, see [2].
4.3 Notes on Integrating TargetLink Code Files in the ECU
Build Process
In order to integrate the generated source files into the ECU build process, it is recommended to use TargetLink’s
File export tool, which is available from the Tools tab of the TargetLink Main Dialog, see Figure 14 and Figure 15.
The tool not only copies the generated code files and make file fragments to a separate directory but also collects
the source files of TargetLink’s fixed point library and copies them into a subdirectory, see Figure 16. Please note
that TargetLink’s fixed-point library source files or a dsfxp.lib file and its header files are usually required to build
the final ECU application.
Figure 14: The File export tool in the TargetLink Main Dialog (or the equivalent M command) should be used to
export the required code files for the ECU build process, including the files from the fixed-point library.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
18
TargetLink Application Note
Figure 15: The target processor/compiler combination must be selected in the File export tool so that the proper,
platform-specific tllimits.h file can be exported.
Figure 16: The File Export tool copies all files required for the ECU build process to a specified directory. The
structure of the directory with include and lib subdirectories is fixed. Please note that TargetLink copies its fixedpoint library functions to the lib subdirectory. The include subdirectory contains general header files as well as the
platform-specific tllimits.h file, which are also required for the build process. The _tools subdirectory contains
some M-files to regenerate an ASAP2 file, which is however only intended for platforms that are intrinsically
supported by TargetLink and not for arbitrary platforms.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
19
TargetLink Application Note
Please note that TargetLink generates and exports a make file fragment to simplify the build process for
TargetLink code. Moreover, the lib subdirectory of the export directory, see Figure 16, contains a make file
fragment called Src_DSFxp.mk. It can be used to generate a lib-file for TargetLink’s fixed-point library for the
specific platform in a separate build process.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
20
TargetLink Application Note
5 Summary of Required Steps
Generating code and an ASAP2 file for an arbitrary platform:
1.
Create a directory %dSPACE_ROOT%\MATLAB\tl\SrcFiles\<uC_type>\<compiler>.
2.
Copy %dSPACE_ROOT%\MATLAB\tl\SrcFiles\Generic\TargetConfigTemplate.xml or a similar file used as a
template to the above directory and rename it TargetConfig.xml.
3.
Change the contents of TargetConfig.xml as described in this document.
4.
Copy %dSPACE_ROOT%\MATLAB\tl\SrcFiles\i86\LCC\tllimits.h or a similar tllimits.h file of a different
platform to the above directory.
5.
Change the contents of tllimits.h as described in this document.
6.
Modify the file %TL_Root%\Matlab\Tl\config\tl_global_options.m as described in this document.
7.
Select the new target for code generation in the TargetLink Main Dialog and generate code.
8.
Use the Manage Build tool to create a Build node for your platform and export an ASAP2 file as described in
this document.
For building a lib-file for TargetLink’s fixed point library:
1.
Copy %dSAPCE_ROOT%\MATLAB\tl\SrcFiles\i86\LCC\include\tl_types.h or a similar tl_types.h file to a
directory that is used for the library build process
2.
Modify the contents of tl_types.h as described in this document.
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
21
TargetLink Application Note
6 References
[1]
TargetLink
2.0
/
3.0
Documentation,
dSPACE
GmbH,
2004
-
2009,
e.g.
TargetLink
File
Reference > Files > Static Files > SrcFiles > Target- and Compiler-Specific SrcFiles
[2]
TargetLink 2.0 / 3.0 Documentation, dSPACE GmbH, 2004 - 2009, e.g. dSPACE Data Dictionary
Interfaces > dSPACE Data Dictionary ASAM-MCD 2MC Import and Export > Exporting ASAMMCD 2MC Files
[3]
Fujitsu Semiconductor Controller Model FR Family, SOFTUNE C/C++ Compiler Manual for V6,
rd
July 2006, 3 Edition
Generating TargetLink Code and ASAP2 Files for an Arbitrary Platform
22