一、TI xDC工具入门简介
转载来自于TI XDC工具入门简介
1.XDC(Express DSP Component)是TI提供的一个命令行工具,它可以生成并使用实时软件组件包,它包括一系列工具,这些工具可以允许你将你的C语言代码组织成类似于java的包管理方式,具有面向对象的特性,因为它还有一个名字,叫做eXpanDed C.
2.以上两图说明了XDC的工作方式:通过相关文件设定操作指令,读入源码、库文件以及已经存在的组件包最终生成可执行文件。3.Package------XDC工作的基本单元。包括有:源码、库文件以及元数据;元数据这包含有该包的版本信息和依赖信息,以及模块(Module)信息。4.XDC使用方法:
5.XDC需要的文件:config.bld package.bld package.xdcPackage.xdc -------------描述该包的名称,版本信息,依赖文件,模块信息等
Config.bld --------------描述XDC要使用的编译工具的相关信息,如不同CPU所使用的编译工具目录,每种编译工具的编译选项,连接选项等基本信息;
Package.bld -------------------描述对于该包需要生成的平台,profile(debug,release)。通过Javascript脚本添加源码到生成执行文件的信息中。Package.mak-------------------由XDC生成的文件,用于最终编译可执行文件。6.XDC工作流程:
7.使用XDC所需的文件:源码、package.bld、package.xdc、config.bld。同时需要通过shell脚本将DVEVM的安装位置导出为环境变量。各代码如下:Config.bld样本代码:
1 + expand sourceview plaincopy to clipboardprint?
2 var MVArm9 = xdc.useModule(
"gnu.targets.MVArm9");
3 MVArm9.rootDir =
"/opt/DVS357/mv_pro_4.0/montavista/pro/devkit/arm/v5t_le";
4 MVArm9.lnkOpts.suffix =
"-lpthread " +
MVArm9.lnkOpts.suffix;
5 var Linux86=xdc.useModule(
"gnu.targets.Linux86");
6 Linux86.rootDir =
"/usr";
7 Linux86.lnkOpts.suffix =
"-lpthread " +
Linux86.lnkOpts.suffix;
8 Build.targets =
[ Linux86,MVArm9,];
9 var MVArm9 = xdc.useModule(
"gnu.targets.MVArm9");
10 MVArm9.rootDir =
"/opt/DVS357/mv_pro_4.0/montavista/pro/devkit/arm/v5t_le";
11 MVArm9.lnkOpts.suffix =
"-lpthread " +
MVArm9.lnkOpts.suffix;
12 var Linux86=xdc.useModule(
"gnu.targets.Linux86");
13 Linux86.rootDir =
"/usr";
14 Linux86.lnkOpts.suffix =
"-lpthread " +
Linux86.lnkOpts.suffix;
15 Build.targets = [ Linux86,MVArm9,];
Runxdc.sh样本代码:
1 view plaincopy to clipboardprint?
2 #! /bin/
sh
3 # import install paths
4 # putting the first period before the shell invokation keeps the changes
5 # to environment variables
set here. Otherwise, changes to environment
6 # are only within the context of the executed script
7
8 ./
setpaths.sh
9 # Define search paths
for included packages
10 export XDCPATH=
"$CE_INSTALL_DIR/packages"
11 # Define options
for execution
12 export XDCBUILDCFG=$(pwd)
"/config.bld
13 # Execute xdc command to make all packages
14
15 /opt/DVS357/dvevm_1_20/xdc_2_94/xdc $@ -P *
16 #! /bin/
sh
17 # import install paths
18 # putting the first period before the shell invokation keeps the changes
19 # to environment variables
set here. Otherwise, changes to environment
20 # are only within the context of the executed script
21 ./
setpaths.sh
22 # Define search paths
for included packages
23 export XDCPATH=
"$CE_INSTALL_DIR/packages"
24 # Define options
for execution
25 export XDCBUILDCFG=$(pwd)
"/config.bld
26 # Execute xdc command to make all packages
27 /opt/DVS357/dvevm_1_20/xdc_2_94/xdc $@ -P *
Setpaths.sh样本代码:
1 #!/bin/
sh
2
3 export DVEVM_INSTALL_DIR=
"/opt/DVS357/dvevm_1_20/"
4 export BIOS_INSTALL_DIR=$DVEVM_INSTALL_DIR/
bios_5_31_01
5 export CG_INSTALL_DIR=$DVEVM_INSTALL_DIR/
cg6x_6_0_14
6 export CMEM_INSTALL_DIR=$DVEVM_INSTALL_DIR/
cmem_1_02
7 export CE_INSTALL_DIR=$DVEVM_INSTALL_DIR/
codec_engine_1_10_01
8 export CS_INSTALL_DIR=$DVEVM_INSTALL_DIR/
codec_servers_1_23
9 export DSPLINK_INSTALL_DIR=$DVEVM_INSTALL_DIR/
dsplink_1_30_08_02
10 export FMWK_INSTALL_DIR=$DVEVM_INSTALL_DIR/
framework_components_1_10_04
11 export XDAIS_INSTALL_DIR=$DVEVM_INSTALL_DIR/
xdais_5_10
12 export XDC_INSTALL_DIR=$DVEVM_INSTALL_DIR/
xdc_2_94
13
14 export PATH=
$XDC_INSTALL_DIR:$PATH
15 #!/bin/
sh
16 export DVEVM_INSTALL_DIR=
"/opt/DVS357/dvevm_1_20/"
17 export BIOS_INSTALL_DIR=$DVEVM_INSTALL_DIR/
bios_5_31_01
18 export CG_INSTALL_DIR=$DVEVM_INSTALL_DIR/
cg6x_6_0_14
19 export CMEM_INSTALL_DIR=$DVEVM_INSTALL_DIR/
cmem_1_02
20 export CE_INSTALL_DIR=$DVEVM_INSTALL_DIR/
codec_engine_1_10_01
21 export CS_INSTALL_DIR=$DVEVM_INSTALL_DIR/
codec_servers_1_23
22 export DSPLINK_INSTALL_DIR=$DVEVM_INSTALL_DIR/
dsplink_1_30_08_02
23 export FMWK_INSTALL_DIR=$DVEVM_INSTALL_DIR/
framework_components_1_10_04
24 export XDAIS_INSTALL_DIR=$DVEVM_INSTALL_DIR/
xdais_5_10
25 export XDC_INSTALL_DIR=$DVEVM_INSTALL_DIR/
xdc_2_94
26 export PATH=$XDC_INSTALL_DIR:$PATH
package.bld样本代码:
1 + expand sourceview plaincopy to clipboardprint?
2 var targs =
[MVArm9, Linux86];
3 var profiles = [
"debug",
"release"];
4 // Define the base name for the executable(s) built
5 var basename =
"app";
6 // The following code uses the java.io.File.list() method to generate an array
7 // of all files in the current directory ('.') and then sorts out .c files
8 var sources = java.io.File(
'.').list();
9 var csources =
[];
10 for (
var i =
0; i < sources.length; i++
){
11 if(String(sources[i]).match(/.*.c$/
))
12 csources.push(sources[i]);
13 }
14
15 // The build phase cycles through the arrays of build targets and profiles
16 // and adds an executable for each combination
17
18 for (
var i =
0; i < targs.length; i++
) {
19 for(
var j =
0; j < profiles.length; j++
){
20 Pkg.addExecutable( basename +
"_" +
profiles[j], targs[i],
21 targs[i].platform, {
22 cfgScript:
null,
23 profile: profiles[j],
24 }
25 ).addObjects( csources );
26 }
27 }
28 var targs =
[MVArm9, Linux86];
29 var profiles = [
"debug",
"release"];
30 // Define the base name for the executable(s) built
31 var basename =
"app";
32 // The following code uses the java.io.File.list() method to generate an array
33 // of all files in the current directory ('.') and then sorts out .c files
34 var sources = java.io.File(
'.').list();
35 var csources =
[];
36 for (
var i =
0; i < sources.length; i++
){
37 if(String(sources[i]).match(/.*.c$/
))
38 csources.push(sources[i]);
39 }
40 // The build phase cycles through the arrays of build targets and profiles
41 // and adds an executable for each combination
42 for (
var i =
0; i < targs.length; i++
) {
43 for(
var j =
0; j < profiles.length; j++
){
44 Pkg.addExecutable( basename +
"_" +
profiles[j], targs[i],
45 targs[i].platform, {
46 cfgScript:
null,
47 profile: profiles[j],
48 }
49 ).addObjects( csources );
50 }
51 }
重点来了:
内容很长,点击跳转到原文
接着上文的进度继续
lesson 7
实现在第二课看到的 Bench模块
1)指定模块
根据RTSC惯例,可以在Bench.xdc源文件中找到acme.utils.Bench模块的说明书。
acme/utils/package.xdc
1 /*! Collection of utility modules */
2 package acme.utils {
3 module Bench;
4 };
acme/utils/Bench.xdc
1 /*! Benchmark timing support */
2 @ModuleStartup
3 module Bench {
4
5 /*! Enable/disable benchmark functions */
6 config Bool enableFlag =
true;
7
8 /*! Start the benchmark */
9 Void begin(String msg);
10
11 /*! End the benchmark and print the current time */
12 Void end();
13
14 internal:
15
16 struct Module_State {
17 String beginMsg;
/* current begin() message */
18 Int beginClock;
/* begin() start time */
19 Int overhead;
/* timing overhead factor */
20 };
21 }
通常,任何出现在XDCspec internal 关键字后的声明,不管是内容、类型、配置或者是函数,通常会支持这个模块的私有实现的一些方面。因此,客户端不应该在它们自己的模块或程序中使用这些内部的特性。在Bench 模块里,它的内部实现使用了私有变量来保留状态信息,在模块的公有函数Bench_begin和Bench_end之间。
2)实现这个模块(目标域)
acme.utils.Bench的实现部分在Bench.c中,包含主体三个函数。
acme/utils/Bench.c
1 #include
2 #include
3 #include "package/internal/Bench.xdc.h"
4
5 #include
6
7 Int Bench_Module_startup(Int state)
8 {
9 Bench_begin(NULL);
10 Bench_end(); /* first-time calibration benchmark */
11
12 return Startup_DONE;
13 }
14
15 Void Bench_begin(String msg)
16 {
17 if (Bench_enableFlag) {
18 module->beginClock = clock();
19 module->beginMsg = msg;
20 }
21 }
22
23 Void Bench_end()
24 {
25 if (Bench_enableFlag) {
26 Int elapsed = clock() - module->beginClock; /* elapsed time between now and last begin() */
27 if (module->beginMsg == NULL) { /* first-time calibration call */
28 module->overhead = elapsed; /* retain elapsed time for later correction */
29 }
30 else { /* correct elapsed time and print result */
31 elapsed -= module->overhead;
32 System_printf("%s [%d]
", module->beginMsg, elapsed);
33 }
34 }
35 }
3)实现模块(meta-domain)
acme/utils/Bench.xs
1 function module$use()
2 {
3 xdc.useModule('xdc.runtime.Startup');
4 xdc.useModule('xdc.runtime.System');
5 }
6
7 function module$static$init(obj)
8 {
9 obj.beginMsg = null;
10 obj.beginClock = 0;
11 obj.overhead = 0;
12 }
4)创建包
与第六课不同,acme.utils包没有包含任何可执行程序。
acme/utils/package.bld
var Build = xdc.useModule('xdc.bld.BuildEnvironment