原文地址:http://alphamailpost.blog.163.com/blog/static/20111808120127261018264/
1.TI XDC工具入门简介
http://www.usr.cc/thread-52028-1-3.html
2.XDC工具使用示例
http://www.usr.cc/thread-52037-1-2.html
3.codec engine代码阅读四---CE_DIR/examples/ti/sdo/ce/examles/codecs/videnc_copy
http://alphamailpost.blog.163.com/blog/static/20111808120127219241667/
4.XDC工具手册(在xdc安装目录下的docs文件夹里也有,这个是在线网页)
http://rtsc.eclipse.org/docs-tip/XDCtools_User%27s_Guide
1.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.xdc
Package.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样本代码:
- + expand sourceview plaincopy to clipboardprint?
- var MVArm9 = xdc.useModule("gnu.targets.MVArm9");
- MVArm9.rootDir = "/opt/DVS357/mv_pro_4.0/montavista/pro/devkit/arm/v5t_le";
- MVArm9.lnkOpts.suffix = "-lpthread " + MVArm9.lnkOpts.suffix;
- var Linux86=xdc.useModule("gnu.targets.Linux86");
- Linux86.rootDir = "/usr";
- Linux86.lnkOpts.suffix = "-lpthread " + Linux86.lnkOpts.suffix;
- Build.targets = [ Linux86,MVArm9,];
- var MVArm9 = xdc.useModule("gnu.targets.MVArm9");
- MVArm9.rootDir = "/opt/DVS357/mv_pro_4.0/montavista/pro/devkit/arm/v5t_le";
- MVArm9.lnkOpts.suffix = "-lpthread " + MVArm9.lnkOpts.suffix;
- var Linux86=xdc.useModule("gnu.targets.Linux86");
- Linux86.rootDir = "/usr";
- Linux86.lnkOpts.suffix = "-lpthread " + Linux86.lnkOpts.suffix;
- Build.targets = [ Linux86,MVArm9,];
- view plaincopy to clipboardprint?
- #! /bin/sh
- # import install paths
- # putting the first period before the shell invokation keeps the changes
- # to environment variables set here. Otherwise, changes to environment
- # are only within the context of the executed script
-
- ./setpaths.sh
- # Define search paths for included packages
- export XDCPATH="$CE_INSTALL_DIR/packages"
- # Define options for execution
- export XDCBUILDCFG=$(pwd)"/config.bld
- # Execute xdc command to make all packages
-
- /opt/DVS357/dvevm_1_20/xdc_2_94/xdc $@ -P *
- #! /bin/sh
- # import install paths
- # putting the first period before the shell invokation keeps the changes
- # to environment variables set here. Otherwise, changes to environment
- # are only within the context of the executed script
- ./setpaths.sh
- # Define search paths for included packages
- export XDCPATH="$CE_INSTALL_DIR/packages"
- # Define options for execution
- export XDCBUILDCFG=$(pwd)"/config.bld
- # Execute xdc command to make all packages
- /opt/DVS357/dvevm_1_20/xdc_2_94/xdc $@ -P *
- #!/bin/sh
-
- export DVEVM_INSTALL_DIR="/opt/DVS357/dvevm_1_20/"
- export BIOS_INSTALL_DIR=$DVEVM_INSTALL_DIR/bios_5_31_01
- export CG_INSTALL_DIR=$DVEVM_INSTALL_DIR/cg6x_6_0_14
- export CMEM_INSTALL_DIR=$DVEVM_INSTALL_DIR/cmem_1_02
- export CE_INSTALL_DIR=$DVEVM_INSTALL_DIR/codec_engine_1_10_01
- export CS_INSTALL_DIR=$DVEVM_INSTALL_DIR/codec_servers_1_23
- export DSPLINK_INSTALL_DIR=$DVEVM_INSTALL_DIR/dsplink_1_30_08_02
- export FMWK_INSTALL_DIR=$DVEVM_INSTALL_DIR/framework_components_1_10_04
- export XDAIS_INSTALL_DIR=$DVEVM_INSTALL_DIR/xdais_5_10
- export XDC_INSTALL_DIR=$DVEVM_INSTALL_DIR/xdc_2_94
-
- export PATH=$XDC_INSTALL_DIR:$PATH
- #!/bin/sh
- export DVEVM_INSTALL_DIR="/opt/DVS357/dvevm_1_20/"
- export BIOS_INSTALL_DIR=$DVEVM_INSTALL_DIR/bios_5_31_01
- export CG_INSTALL_DIR=$DVEVM_INSTALL_DIR/cg6x_6_0_14
- export CMEM_INSTALL_DIR=$DVEVM_INSTALL_DIR/cmem_1_02
- export CE_INSTALL_DIR=$DVEVM_INSTALL_DIR/codec_engine_1_10_01
- export CS_INSTALL_DIR=$DVEVM_INSTALL_DIR/codec_servers_1_23
- export DSPLINK_INSTALL_DIR=$DVEVM_INSTALL_DIR/dsplink_1_30_08_02
- export FMWK_INSTALL_DIR=$DVEVM_INSTALL_DIR/framework_components_1_10_04
- export XDAIS_INSTALL_DIR=$DVEVM_INSTALL_DIR/xdais_5_10
- export XDC_INSTALL_DIR=$DVEVM_INSTALL_DIR/xdc_2_94
- export PATH=$XDC_INSTALL_DIR:$PATH
- + expand sourceview plaincopy to clipboardprint?
- var targs = [MVArm9, Linux86];
- var profiles = ["debug", "release"];
- // Define the base name for the executable(s) built
- var basename = "app";
- // The following code uses the java.io.File.list() method to generate an array
- // of all files in the current directory ('.') and then sorts out .c files
- var sources = java.io.File('.').list();
- var csources = [];
- for (var i = 0; i < sources.length; i++){
- if(String(sources[i]).match(/.*\.c$/))
- csources.push(sources[i]);
- }
-
- // The build phase cycles through the arrays of build targets and profiles
- // and adds an executable for each combination
-
- for (var i = 0; i < targs.length; i++) {
- for(var j = 0; j < profiles.length; j++){
- Pkg.addExecutable( basename + "_" + profiles[j], targs[i],
- targs[i].platform, {
- cfgScript: null,
- profile: profiles[j],
- }
- ).addObjects( csources );
- }
- }
- var targs = [MVArm9, Linux86];
- var profiles = ["debug", "release"];
- // Define the base name for the executable(s) built
- var basename = "app";
- // The following code uses the java.io.File.list() method to generate an array
- // of all files in the current directory ('.') and then sorts out .c files
- var sources = java.io.File('.').list();
- var csources = [];
- for (var i = 0; i < sources.length; i++){
- if(String(sources[i]).match(/.*\.c$/))
- csources.push(sources[i]);
- }
- // The build phase cycles through the arrays of build targets and profiles
- // and adds an executable for each combination
- for (var i = 0; i < targs.length; i++) {
- for(var j = 0; j < profiles.length; j++){
- Pkg.addExecutable( basename + "_" + profiles[j], targs[i],
- targs[i].platform, {
- cfgScript: null,
- profile: profiles[j],
- }
- ).addObjects( csources );
- }
- }
在xdc工具的文档里,有一个chm文件,我们跟着这个文件做一些简单的利用xdc的程序编译.
j@j-desktop:/home/pheobe/davinci/xdctools_3_10_05_61/docs$ ls
docs.zip README.txt tilogo.gif xdctools.chm
icons relnotes_archive titagline.gif
RTSC programming-->Primers-->RTSC Primers-->what we'll cover下面我们从lesson0开始做,为方便你找到这个文件,下面的 网址上是一个截图,标示了目录层次.
但是发现chm上的示例代码下载不下来,于是解压了docs.zip,lessen0的所在是:
xdctools_3_10_05_61/docs/docs/rtscpedia/RTSC_Module_Primer/RTSC_Module_Primer__Lesson_0.html
下载代码:我在我的home文件夹下新建了一个test文件夹,然后复制了lesson0所涉及到的文件:Mod-primer-examples.zip然后解压,
- j@j-desktop:~/test$ cd examples/
- j@j-desktop:~/test/examples$ ls
- acme common.mak lesson1 lesson3 lesson5
- bravo config.bld lesson2 lesson4 lesson6
- j@j-desktop:~/test/examples$ echo $PATH
- /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
- j@j-desktop:~/test/examples$ export PATH=$PATH:/home/pheobe/davinci/xdctools_3_10_05_61/
- j@j-desktop:~/test/examples$ echo $PATH
- /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/pheobe/davinci/xdctools_3_10_05_61/
- j@j-desktop:~/test/examples$ export XDCPATH=/home/pheobe/test/examples/j@j-desktop:~/test/examples$ echo $XDCPATH
- /home/pheobe/test/examples/
- j@j-desktop:~/test/examples$ xs xdc.tools.path -p /home/pheobe/test/examples/;/home/pheobe/davinci/xdctools_3_10_05_61/packages;
然后是告诉XDC你的编译器所在的路径,我手头也没有板子,就是直接编译与我的电脑用了,所以我的编译器是gcc:
- j@j-desktop:~/test/examples$ cat common.mak
## -------- common makefile -------- ##
## -------- host-specific paths -------- ##
## MODIFY THESE PATHS PER YOUR INSTALLATION
## WINDOWS HOST -- SURROUND THESE PATHS WITH "" "" IF THEY CONTAIN SPACES
XDCROOT = /home/pheobe/davinci/xdctools_3_10_05_61
C6XTOOLS = /home/pheobe/davinci/cg6x_6_0_21_1
## -------- remove command -------- ##
## LINUX HOSTS -- REPLACE $(XDCROOT)/bin/rm WITH rm
RMCMD = rm
## --------build tools -------- ##
CONFIGURO = $(XDCROOT)/xs xdc.tools.configuro
LOADER = $(XDCROOT)/xs xdc.tools.loader
CC = $(C6XTOOLS)/bin/cl6x -q
## -------- build parameters -------- ##
CONFIG = cfgsite
TARGET = ti.targets.C64P
PLATFORM = ti.platforms.sim64Pxx
PROGNAME = prog
## -------- all-rule -------- ##
all : $(PROGNAME).out
## -------- config-rule -------- ##
$(CONFIG)/linker.cmd $(CONFIG)/compiler.opt : $(PROGNAME).cfg
$(CONFIGURO) -c $(C6XTOOLS) -t $(TARGET) -p $(PLATFORM) -o $(CONFIG) $(PROGNAME).cfg
## -------- compile-rule -------- ##
$(PROGNAME).obj : $(PROGNAME).c $(CONFIG)/compiler.opt
$(CC) -@$(CONFIG)/compiler.opt -c $(PROGNAME).c
## -------- link-rule -------- ##
$(PROGNAME).out : $(PROGNAME).obj $(CONFIG)/linker.cmd
$(CC) -z -c $^ -o $(PROGNAME).out -l $(C6XTOOLS)/lib/rts64plus.lib
## -------- test-rule -------- ##
test : $(PROGNAME).out
$(LOADER) $(PROGNAME).out
## -------- clean-rule -------- ##
clean :
rm -rf $(CONFIG) *.obj *.out
config.bld编辑之后为:
- j@j-desktop:~/test/examples$ cat config.bld
- /*
- * ======== config.bld ========
- */
- var Build = xdc.useModule('xdc.bld.BuildEnvironment');
- var C64P = xdc.useModule('ti.targets.C64P');
- var GCC = xdc.useModule('gnu.targets.Mingw');
- C64P.rootDir = /home/pheobe/davinci/cg6x_6_0_21_1; /* modify to match %c6xtools% */
- C64P.platform = 'ti.platforms.sim64Pxx';
- GCC.rootDir = /usr/bin; /* modify to match %gcctools% */
- Build.targets = [C64P, GCC];
- j@j-desktop:~/test/examples$ cd lesson1
- j@j-desktop:~/test/examples/lesson1$ ls
- makefile prog.c prog.cfg
- j@j-desktop:~/test/examples/lesson1$ cat prog.c
- /*
- * ======== lesson1/prog.c ========
- */
- #include <xdc/runtime/System.h>
- int main()
- {
- System_printf("Hello World\n");
- return 0;
- }
- j@j-desktop:~/test/examples/lesson1$ cat prog.cfg
- /*
- * ======== lesson1/prog.cfg ========
- */
- var System = xdc.useModule('xdc.runtime.System');
这个元程序,说整个程序要使用一个完整名字为xdc.runtime.System的RTSC模块.简单的说,一个RTSC模块定义了一个客户与实现提供者之间编程边界,它包括:
1)一组特定的常量,类型和函数.
2)上面的这些东西的实现只有在提供者才可见,而对客户是隐藏的.
每个模块必须存在一个包中,包在这里即是一个物理的概念也是一个逻辑的概念.
比如在这个例子中xdc.runtime.System这个模块包含于一个逻辑上的xdc.runtime包里,同时也存在于一个xdc/runtime文件夹下.
与它同级的还有Memory,Error,Startup等.System里包含了一组函数printf, atexit, abort等,这些函数与C标准库中的函数同名,功能也差不多,但却有自己的实现.
这于这方面的概念不多说了,与java是类似的,一句话,你也可以这样调用printf而不用include .h文件: xdc_runtime_System_printf
说某一个程序都有一个main入口点,比如说System也有,xdc.useModule(System),会启动程序的生命进程,也就是说会调用到它的main函数.
有一个规则,就是这个元程序的useModule要映像include语句,意思是prog.c中有一个include,prog.cfg就要useModule那个模块.
除了这个元程序,还有一个 xdc脚本XDCscript,用来配置程序的,这个脚本是javascript的一个超集,但是没有会把它称为javascript.
配置RTSC程序:
元程序是服务于预编译阶段的,也就是编译和链接prog.c之前的.我们需要一个configuro程序来执行这个配置过程,configuro会把 prog.cfg做为输入,输出两个文件,compiler.opt和linker.cmd,这两个文件一个做为编译器的输入,一个做为链接器的输入,来 控制整个编译链接的流程.
除了这个prog.cfg文件外,configuro的输入还要有一个target和一个platform,这两个东西是在XDCscript中的. target指定的是核心级信息,所以编译器知道芯片是什么指令级,用什么编译器,它指导程序的编译.
platform指定的是芯片级信息,有外设之类的信息,指导链接器进行链接.
好了,可以 编译运行程序了:
文件夹里有一个makefile:
- j@j-desktop:~/test/examples/lesson1$ cat makefile
- ## -------- lesson1/makefile -------- ##
- -include ../common.mak
我们只要make all就可以编译了:
- j@j-desktop:~/test/examples/lesson1$ make all
- /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.configuro -c /home/pheobe/davinci/cg6x_6_0_21_1 -t ti.targets.C64P -p ti.platforms.sim64Pxx -o cfgsite prog.cfg
- making package.mak (because of package.bld) ...
- generating interfaces for package cfgsite (because package/package.xdc.inc is older than package.xdc) ...
- configuring prog.x64P from package/cfg/prog_x64P.cfg ...
- cl64P package/cfg/prog_x64P.c ...
- /home/pheobe/davinci/cg6x_6_0_21_1/bin/cl6x -q -@cfgsite/compiler.opt -c prog.c
- /home/pheobe/davinci/cg6x_6_0_21_1/bin/cl6x -q -z -c prog.obj cfgsite/linker.cmd -o prog.out -l /home/pheobe/davinci/cg6x_6_0_21_1/lib/rts64plus.lib
- j@j-desktop:~/test/examples/lesson1$ ls
- cfgsite makefile prog.c prog.cfg prog.obj prog.out
从makefile我们知道,make究竟做什么都在common.mak中指定的,我们来看all选项:
- all : $(PROGNAME).out
- ## -------- config-rule -------- ##
- $(CONFIG)/linker.cmd $(CONFIG)/compiler.opt : $(PROGNAME).cfg
- $(CONFIGURO) -c $(C6XTOOLS) -t $(TARGET) -p $(PLATFORM) -o $(CONFIG) $(PROGNAME).cfg
- ## -------- compile-rule -------- ##
- $(PROGNAME).obj : $(PROGNAME).c $(CONFIG)/compiler.opt
- $(CC) -@$(CONFIG)/compiler.opt -c $(PROGNAME).c
- ## -------- link-rule -------- ##
- $(PROGNAME).out : $(PROGNAME).obj $(CONFIG)/linker.cmd
- $(CC) -z -c $^ -o $(PROGNAME).out -l $(C6XTOOLS)/lib/rts64plus.lib
- all : prog.out
- ## -------- config-rule -------- ##
- cfgsite/linker.cmd cfgsite/compiler.opt : prog.cfg
- /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.configuro -c /home/pheobe/davinci/cg6x_6_0_21_1 -t ti.targets.C64P -p ti.platforms.sim64Pxx -o cfgsite prog.cfg
j@j-desktop:~/test/examples/lesson1$ /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.configuro -c /home/pheobe/davinci/cg6x_6_0_21_1 -t ti.targets.C64P -p ti.platforms.sim64Pxx -o cfgsite prog.cfgmaking package.mak (because of package.bld) ...generating interfaces for package cfgsite (because package/package.xdc.inc is older than package.xdc) ...configuring prog.x64P from package/cfg/prog_x64P.cfg ...cl64P package/cfg/prog_x64P.c ...j@j-desktop:~/test/examples/lesson1$ lscfgsite makefile prog.c prog.cfgj@j-desktop:~/test/examples/lesson1$ ls cfgsitecompiler.opt custom.mak package package.mak package.xsconfig.bld linker.cmd package.bld package.xdc
然后编译:
- j@j-desktop:~/test/examples/lesson1$ /home/pheobe/davinci/cg6x_6_0_21_1/bin/cl6x -q -@cfgsite/compiler.opt -c prog.c
- j@j-desktop:~/test/examples/lesson1$ ls
- cfgsite makefile prog.c prog.cfg prog.obj
然后是链接:
- j@j-desktop:~/test/examples/lesson1$ /home/pheobe/davinci/cg6x_6_0_21_1/bin/cl6x -q -z -c prog.obj cfgsite/linker.cmd -o prog.out -l /home/pheobe/davinci/cg6x_6_0_21_1/lib/rts64plus.lib
- j@j-desktop:~/test/examples/lesson1$ ls
- cfgsite makefile prog.c prog.cfg prog.obj prog.out
编译选项为:
- j@j-desktop:~/test/examples/lesson1$ cat cfgsite/compiler.opt
- -mv64p -I"/home/pheobe/test/examples" -I"/home/pheobe/davinci/xdctools_3_10_05_61/packages" -I"/home/j/test/examples/lesson1/cfgsite/.." -I/home/pheobe/davinci/cg6x_6_0_21_1/include -Dxdc_target_types__="ti/targets/std.h" -Dxdc_target_name__=C64P -Dxdc_cfg__header__="/home/j/test/examples/lesson1/cfgsite/package/cfg/prog_x64P.h"
- j@j-desktop:~/test/examples/lesson1$ cat cfgsite/linker.cmd
- /*
- * Do not modify this file; it is automatically generated from the template
- * linkcmd.xdt in the ti.targets package and will be overwritten.
- */
- /*
- * put '"'s around paths because, without this, the linker
- * considers '-' as minus operator, not a file name character.
- */
- -l"/home/j/test/examples/lesson1/cfgsite/package/cfg/prog_x64P.o64P"
- -l"/home/pheobe/davinci/xdctools_3_10_05_61/packages/ti/targets/rts6000/lib/ti.targets.rts6000.a64P"
- -l"/home/pheobe/davinci/xdctools_3_10_05_61/packages/ti/targets/rts6000/lib/boot.a64P"
- --args 0x200
- -heap 0x1000
- -stack 0x1000
- MEMORY
- {
- IRAM (RWX) : org = 0x800000, len = 0x200000
- DDR : org = 0x80000000, len = 0x10000000
- }
- /*
- * Linker command file contributions from all loaded packages:
- */
- /* Content from xdc (null): */
- /* Content from xdc.corevers (null): */
- /* Content from xdc.services.global (null): */
- /* Content from xdc.shelf (null): */
- /* Content from xdc.services.spec (null): */
- /* Content from xdc.services.intern.xsr (null): */
- /* Content from xdc.services.intern.gen (null): */
- /* Content from xdc.services.intern.cmd (null): */
- /* Content from ti.catalog.c6000 (null): */
- /* Content from xdc.platform (null): */
- /* Content from xdc.cfg (null): */
- /* Content from ti.platforms.sim64Pxx (null): */
- /* Content from xdc.runtime (null): */
- /* Content from ti.targets.rts6000 (null): */
- /* Content from cfgsite (null): */
- /*
- * symbolic aliases for static instance objects
- */
- _xdc_runtime_Startup__EXECFXN__C = 1;
- _xdc_runtime_Startup__RESETFXN__C = 1;
- SECTIONS
- {
- .text: load >> DDR
- .switch: load >> DDR
- .stack: load > DDR
- .args: load > DDR align = 0x4 , fill = 0 { _argsize = 0x200; }
- xdc.noload: load >> DDR, type = NOLOAD
- .sysmem: load > DDR
- .far: load >> DDR
- .data: load >> DDR
- .cinit: load > DDR
- .bss: load > DDR
- .const: load >> DDR
- .pinit: load > DDR
- .cio: load >> DDR
- }
二楼这里从第二课开始看起:
它的文档所在位置为: xdctools_3_10_05_61/docs/docs/rtscpedia/RTSC_Module_Primer/RTSC_Module_Primer__Lesson_2.html这一节主要是讲Bench模块,上一节我们己经讲了System模块。
Bench模块全名为
#include
<acme/utils/Bench.h>或acme.utils.Bench.
我们看看代码为:
- j@j-desktop:~/test/examples/lesson2$ cat prog.c
- /*
- * ======== lesson2/prog.c ========
- */
- #include <acme/utils/Bench.h>
- #include <xdc/runtime/System.h>
- int main()
- {
- Bench_begin("System_printf timing");
- System_printf("Hello World\n");
- Bench_end();
- return 0;
- }
- j@j-desktop:~/test/examples/lesson2$ cat prog.cfg
- /*
- * ======== lesson2/prog.cfg ========
- */
- var Bench = xdc.useModule('acme.utils.Bench');
- var System = xdc.useModule('xdc.runtime.System');
- Bench.enableFlag = true;
Bench模块可以用来测试,下面的代码Bench_begin表时开始测试,传入参数是一个字符串,但是这个字符串并不立刻输出,而是等Bench_end时才输出,并且最后还打印出从begin到end所经历的时间。
- j@j-desktop:~/test/examples/lesson2$ make all
- /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.configuro -c /home/pheobe/davinci/cg6x_6_0_21_1 -t ti.targets.C64P -p ti.platforms.sim64Pxx -o cfgsite prog.cfg
- making package.mak (because of package.bld) ...
- generating interfaces for package cfgsite (because package/package.xdc.inc is older than package.xdc) ...
- configuring prog.x64P from package/cfg/prog_x64P.cfg ...
- js: "/home/pheobe/davinci/xdctools_3_10_05_61/packages/xdc/xdc.tci", line 299: xdc.services.global.XDCException: xdc.PACKAGE_NOT_FOUND: can't locate the package 'acme.utils' along the path: '/home/pheobe/davinci/xdctools_3_10_05_61/packages;..;'. Ensure that the package path is set correctly.
- "/home/j/test/examples/lesson2/prog.cfg", line 5
- "./package/cfg/prog_x64P.cfg", line 762
- "./package/cfg/prog_x64P.cfg", line 717
- gmake: *** [package/cfg/prog_x64P.c] Error 1
- js: "/home/pheobe/davinci/xdctools_3_10_05_61/packages/xdc/tools/Cmdr.xs", line 40: Error: xdc.tools.configuro: configuration failed due to earlier errors (status = 2); 'linker.cmd' deleted.
- make: *** [cfgsite/compiler.opt] Error 1
PACKAGE_NOT_FOUND: can't locate the package 'acme.utils' along the path: '/home/pheobe/davinci/xdctools_3_10_05_61/packages;..;'. Ensure that the package path is set correctly.
- xs xdc.tools.path -pxs: command not found
哦,这是因为昨天做上一课时export PATH=$PATH:/home/pheobe/davinci/xdctools_3_10_05_61/这一步把$PATH加下到环境变量中只是临时的,关机重启就没了,现在我们把它加在.bashrc中:
- gedit ~/.bashrc
- j@j-desktop:~/test/examples/lesson2$ source ~/.bashrc
- j@j-desktop:~/test/examples/lesson2$ xs xdc.tools.path -p
- /home/pheobe/davinci/xdctools_3_10_05_61/packages;
- gedit ~/.bashrc
- j@j-desktop:~/test/examples/lesson2$ make clean
- rm -rf cfgsite *.obj *.out
- j@j-desktop:~/test/examples/lesson2$ make all
- /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.configuro -c /home/pheobe/davinci/cg6x_6_0_21_1 -t ti.targets.C64P -p ti.platforms.sim64Pxx -o cfgsite prog.cfg
- making package.mak (because of package.bld) ...
- generating interfaces for package cfgsite (because package/package.xdc.inc is older than package.xdc) ...
- configuring prog.x64P from package/cfg/prog_x64P.cfg ...
- cl64P package/cfg/prog_x64P.c ...
- /home/pheobe/davinci/cg6x_6_0_21_1/bin/cl6x -q -@cfgsite/compiler.opt -c prog.c
- /home/pheobe/davinci/cg6x_6_0_21_1/bin/cl6x -q -z -c prog.obj cfgsite/linker.cmd -o prog.out -l /home/pheobe/davinci/cg6x_6_0_21_1/lib/rts64plus.lib
- j@j-desktop:~/test/examples/lesson2$ make test
- /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.loader prog.out
- Hello World
- System_printf timing [2159]
下面进入第三课,实例对象:
xdctools_3_10_05_61/docs/docs/rtscpedia/RTSC_Module_Primer/RTSC_Module_Primer__Lesson_3.html
这里又是一个新模块: bravo.math.RandGenRandGen 管理的是一个产生随机数序列的实例对象。实际的创建需要一组单独的参数。RandGen_create分配并初始化一个实例对象。它接收一个参数,类型为 RandGen_Params rgParams;它有一组默认值,你可以根据需要修改它的单个域,如:
- rgParams.range = 15;
- rgParams.seed = 3;
RandGen_next获得下一个随机数。
- j@j-desktop:~/test/examples/lesson3$ make all
- /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.configuro -c /home/pheobe/davinci/cg6x_6_0_21_1 -t ti.targets.C64P -p ti.platforms.sim64Pxx -o cfgsite prog.cfg
- making package.mak (because of package.bld) ...
- generating interfaces for package cfgsite (because package/package.xdc.inc is older than package.xdc) ...
- configuring prog.x64P from package/cfg/prog_x64P.cfg ...
- cl64P package/cfg/prog_x64P.c ...
- /home/pheobe/davinci/cg6x_6_0_21_1/bin/cl6x -q -@cfgsite/compiler.opt -c prog.c
- /home/pheobe/davinci/cg6x_6_0_21_1/bin/cl6x -q -z -c prog.obj cfgsite/linker.cmd -o prog.out -l /home/pheobe/davinci/cg6x_6_0_21_1/lib/rts64plus.lib
- j@j-desktop:~/test/examples/lesson3$ make test
- /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.loader prog.out
- 6 7 10 1 12 8 10 14 1 15
- j@j-desktop:~/test/examples/lesson3$ make test
- /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.loader prog.out
- 6 7 10 1 12 8 10 14 1 15
- j@j-desktop:~/test/examples/lesson3$ cat prog.c
- /*
- * ======== lesson3/prog.c ========
- */
- #include <bravo/math/RandGen.h>
- #include <xdc/runtime/System.h>
- #define COUNT 10
- Int main()
- {
- RandGen_Handle rgInst;
- RandGen_Params rgParams;
- Int i;
- RandGen_Params_init(&rgParams);
- rgParams.range = 150;
- rgParams.seed = 8;
- rgInst = RandGen_create(&rgParams, NULL);
- for (i = 0; i < COUNT; i++) {
- System_printf("%d ", RandGen_next(rgInst));
- }
- System_printf("\n");
- return 0;
- }
- j@j-desktop:~/test/examples/lesson3$ make clean
- rm -rf cfgsite *.obj *.out
- j@j-desktop:~/test/examples/lesson3$ make all
- /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.configuro -c /home/pheobe/davinci/cg6x_6_0_21_1 -t ti.targets.C64P -p ti.platforms.sim64Pxx -o cfgsite prog.cfg
- making package.mak (because of package.bld) ...
- generating interfaces for package cfgsite (because package/package.xdc.inc is older than package.xdc) ...
- configuring prog.x64P from package/cfg/prog_x64P.cfg ...
- cl64P package/cfg/prog_x64P.c ...
- /home/pheobe/davinci/cg6x_6_0_21_1/bin/cl6x -q -@cfgsite/compiler.opt -c prog.c
- /home/pheobe/davinci/cg6x_6_0_21_1/bin/cl6x -q -z -c prog.obj cfgsite/linker.cmd -o prog.out -l /home/pheobe/davinci/cg6x_6_0_21_1/lib/rts64plus.lib
- j@j-desktop:~/test/examples/lesson3$ make test
- /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.loader prog.out
- 29 1 53 10 27 133 95 32 114 81
进入lesson4:
xdctools_3_10_05_61/docs/docs/rtscpedia/RTSC_Module_Primer/RTSC_Module_Primer__Lesson_4.html
依旧是楼上的那个模块,这里主要讲静态实例,实例的销毁。
先执行程序:
- j@j-desktop:~/test/examples/lesson3$ cd ../lesson4
- j@j-desktop:~/test/examples/lesson4$ make all
- /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.configuro -c /home/pheobe/davinci/cg6x_6_0_21_1 -t ti.targets.C64P -p ti.platforms.sim64Pxx -o cfgsite prog.cfg
- making package.mak (because of package.bld) ...
- generating interfaces for package cfgsite (because package/package.xdc.inc is older than package.xdc) ...
- configuring prog.x64P from package/cfg/prog_x64P.cfg ...
- cl64P package/cfg/prog_x64P.c ...
- /home/pheobe/davinci/cg6x_6_0_21_1/bin/cl6x -q -@cfgsite/compiler.opt -c prog.c
- /home/pheobe/davinci/cg6x_6_0_21_1/bin/cl6x -q -z -c prog.obj cfgsite/linker.cmd -o prog.out -l /home/pheobe/davinci/cg6x_6_0_21_1/lib/rts64plus.lib
- j@j-desktop:~/test/examples/lesson4$ make test
- /home/pheobe/davinci/xdctools_3_10_05_61/xs xdc.tools.loader prog.out
- dynamically-created instance:
- 6 7 10 1 12 8 10 14 1 15
- dynamically-constructed instance:
- 13 2 1 22 12 5 10 19 17 12
- statically-created instance:
- 12 5 3 11 11 19 5 1 15 0
- j@j-desktop:~/test/examples/lesson4$ cat prog.c
- /*
- * ======== lesson4/prog.c ========
- */
- #include <bravo/math/RandGen.h>
- #include <xdc/runtime/System.h>
- #include <xdc/cfg/global.h>
- #define COUNT 10
- Void printNums(RandGen_Handle rgInst, String label)
- {
- Int i;
- System_printf("%s:\n\t", label);
- for (i = 0; i < COUNT; i++) {
- System_printf("%d ", RandGen_next(rgInst));
- }
- System_printf("\n\n");
- }
- Int main()
- {
- RandGen_Handle rgInstHandle;
- RandGen_Struct rgInstStruct;
- RandGen_Params rgParams;
- RandGen_Params_init(&rgParams);
- rgParams.range = 15;
- rgParams.seed = 3;
- rgInstHandle = RandGen_create(&rgParams, NULL);
- rgParams.range = 25;
- rgParams.seed = 2;
- RandGen_construct(&rgInstStruct, &rgParams);
- printNums(rgInstHandle, "dynamically-created instance");
- printNums(RandGen_handle(&rgInstStruct), "dynamically-constructed instance");
- printNums(rgInstStatic, "statically-created instance");
- RandGen_delete(&rgInstHandle);
- RandGen_destruct(&rgInstStruct);
- return 0;
- }
代码很容易看,有三个对象,
动态创建对象的方法:
- RandGen_Handle rgInstHandle;
- rgInstHandle = RandGen_create(&rgParams, NULL);
- RandGen_Struct rgInstStruct;
- RandGen_construct(&rgInstStruct, &rgParams);
- RandGen_handle(&rgInstStruct)//最后这里是从struct获得handle
- printNums(rgInstStatic, "statically-created instance");
它是在prog.cfg里声明的:
- j@j-desktop:~/test/examples/lesson4$ cat prog.cfg
- /*
- * ======== lesson4/prog.cfg ========
- */
- var Program = xdc.useModule('xdc.cfg.Program');
- var RandGen = xdc.useModule('bravo.math.RandGen');
- var System = xdc.useModule('xdc.runtime.System');
- Program.global["rgInstStatic"] = RandGen.create({range: 20, seed: 4});
- Program.global["rgInstStatic"] = RandGen.create({range: 20, seed: 4});
第五课,lesson5:
xdctools_3_10_05_61/docs/docs/rtscpedia/RTSC_Module_Primer/RTSC_Module_Primer__Lesson_5.html
终于说到包了,这与 codec engine是很相关的了。
这里我们要创建一个非常简单的包,这个包里没有模块,只是为了介绍一些概念。
我们的examples文件夹己经被包含在XDCPATH目录下了,所以如果我们想建一个包,名字叫lesson5,我们就在examples目录下建一个目录叫做lesson5,这体现了XDC中包结构的物理,逻辑两个层次的对应。
要 声明lesson5下面是一个包,它下面就要有丙个文件,一个是package.xdc,另一个就是package.bld.前者声明这个包的名字,后者描述了这个的创建方法。
- j@j-desktop:~/test/examples/lesson5$ ls
- package package.bld package.mak package.xdc prog.c prog.cfg
在 package.xdc中,可以这样声明一个包:
- j@j-desktop:~/test/examples/lesson5$ cat package.xdc
- /*
- * ======== lesson5/package.xdc ========
- */
- /*! Our first package [RTSC Module Primer] */
- package lesson5 {
- /* module declarations normally go here */
- };
去掉无用的注释,其实就是:
- package lesson5{};
这有点像C语言的给构体,然而却不是,它是用 XDCspec语言来写的。这里我们应该得到一个结论,examples下的Lesson5文件夹,对应一个包称为lessen5,但同样的文件夹lesson4却不是一个包,因为它下面没有package.xdc。]
另一个文件是package.bld,它是用 XDCscript写的。它的功能与makefile差不多。也用于控制程序的编译流程。
另外,lesson0中的config.bld也是XDCscript写的。config.bld通常放在XDCPATH指定的各个目录下,
- for each (var targ in Build.targets) {
- Pkg.addExecutable("prog", targ, targ.platform).addObjects(["prog.c"]);
- }
Package模块有很多函数,其中addExecutabe执行了添加构建模块所谓的所有信息。"prog"是可执行文件的名字也是.cfg文件的名 字。targ是编译的目标,targ.platform是目标所在的平台,target有一个platform属性,它有默认值,可以在 config.bld中配置。addexecutable根据不同的target返回一个不同类型XDCscript类型,不同的XDCscript调用 的addObject自然也就一样。addObject函数枚举需要进行编译的文件。我们看一下config.bld中的内容,更有助于理解:
- j@j-desktop:~/test/examples/lesson5$ cat ../config.bld
- /*
- * ======== config.bld ========
- */
- var Build = xdc.useModule('xdc.bld.BuildEnvironment');
- var C64P = xdc.useModule('ti.targets.C64P');
- var GCC = xdc.useModule('gnu.targets.Mingw');
- C64P.rootDir = /home/pheobe/davinci/cg6x_6_0_21_1; /* modify to match %c6xtools% */
- C64P.platform = 'ti.platforms.sim64Pxx';
- GCC.rootDir = /usr/bin; /* modify to match %gcctools% */
- Build.targets = [C64P, GCC];
C64P的platform域被指定为'ti.platforms.sim64Pxx,GCC则使用默认的。
现在一切都明了了,可以进行编译了:
xdc工具集中有两个最常用的命令,其他的基本用不到:
xs和xdc.其中xs己经用过了,它是用于启动xdcscript写的代码的。而xdc基本等价于make,用于package.bld之类的XDCscript写的代码的。
常用的xdc命令是xdc clean和xdc all,前者清楚上次编译出来的东西,后者按照package.bld编译全部。
嗯,编译时发现config.bld配置错了,examples目录下的,应为:
- /*
- * ======== config.bld ========
- */
- var Build = xdc.useModule('xdc.bld.BuildEnvironment');
- var C64P = xdc.useModule('ti.targets.C64P');
- var GCC = xdc.useModule('gnu.targets.Linux86');
- C64P.rootDir ='/home/pheobe/davinci/cg6x_6_0_21_1'; /* modify to match %c6xtools% */
- C64P.platform = 'ti.platforms.sim64Pxx';
- GCC.rootDir ='/usr'; /* modify to match %gcctools% */
- Build.targets = [C64P, GCC];
下面编译:
- j@j-desktop:~/test/examples/lesson5$ xdc clean
- j@j-desktop:~/test/examples/lesson5$ xdc all
- making package.mak (because of package.bld) ...
- generating interfaces for package lesson5 (because package/package.xdc.inc is older than package.xdc) ...
- configuring prog.x64P from package/cfg/prog_x64P.cfg ...
- cl64P prog.c ...
- cl64P package/cfg/prog_x64P.c ...
- lnk64P prog.x64P ...
- configuring prog.x86U from package/cfg/prog_x86U.cfg ...
- cl86U prog.c ...
- cl86U package/cfg/prog_x86U.c ...
- lnk86U prog.x86U ...
- all files complete.
- j@j-desktop:~/test/examples/lesson5$ xdc test
- running prog.x64P ...
- Hello World
- running prog.x86U ...
- Hello World
第五课搞定了。
第六课:
上一节课我们讲到了包,但是我们的包里并没有什么东西,这一节课我们讲的叫模块,并且会涉及到XDC编程中的一个常用技巧,即把C语言中的常量写成可配置的模块参数。
我们的模块名字叫做Talker,它在文件夹lesson6里面,也在包lesson6里面,lesson6里面有一个文件package.xdc来描述这个模块,但这里面只是给了一个声明,但并没有说明这个模块的详细属性,详细的属性写在Talker.xdc里面。
- j@j-desktop:~/test/examples/lesson5$ cd ../lesson6
- j@j-desktop:~/test/examples/lesson6$ cat package.xdc
- /*
- * ======== lesson6/package.xdc ========
- */
- /*! Contains our first module [RTSC Module Primer] */
- package lesson6 {
- module Talker;
- };
- j@j-desktop:~/test/examples/lesson6$ cat prog.c
- /*
- * ======== lesson6/prog.c ========
- */
- #include <lesson6/Talker.h>
- Int main()
- {
- Talker_print();
- return 0;
- }
- j@j-desktop:~/test/examples/lesson6$ cat prog.cfg
- /*
- * ======== lesson6/prog.cfg ========
- */
- var Talker = xdc.useModule('lesson6.Talker');
- Talker.text = "Goodnight Moon";
- Talker.count = 3;
现在我们可以看Talker.xdc了,这个文件定义了Talker模块的详细属性。它是由XDCspec,一种与C差不多的语言写的。我们注意到 prog.c中include了lesson6/Talker.h,这个文件是不用手写的,XDC会自动根据Talker.xdc生成talker.h.
- j@j-desktop:~/test/examples/lesson6$ xdc clean
- j@j-desktop:~/test/examples/lesson6$ ls
- lib package.xdc prog.cfg Talker.xdc
- package.bld prog.c Talker.c Talker.xs
- j@j-desktop:~/test/examples/lesson6$ cat Talker.xdc
- /*
- * ======== lesson6/Talker.xdc ========
- */
- /*! Our first module */
- module Talker {
- /*! What to say */
- config String text = "Hello World";
- /*! How many times */
- config Int count = 1;
- /*! Say it */
- Void print();
- }
Talker.xdc仅是模块的声明,其实现部分写在Talker.c中。
- j@j-desktop:~/test/examples/lesson6$ cat Talker.c
- /*
- * ======== lesson6/Talker.c ========
- */
- #include <xdc/runtime/System.h>
- #include "package/internal/Talker.xdc.h"
- Void Talker_print()
- {
- Int i;
- for (i = 0; i < Talker_count; i++) {
- System_printf("%s\n", Talker_text);
- }
- }
对应prog.c和jprog.cfg,Talker.c也有一个Talker.xs文件:
- j@j-desktop:~/test/examples/lesson6$ cat Talker.xs
- /*
- * ======== lesson6/Talker.xs ========
- */
- function module$use()
- {
- xdc.useModule('xdc.runtime.System');
- }
这里的function module$use()表明函数体的内容是某个外部函数调用useModule(lesson6.Talker)时返回的语句。
我们看prog.cfg里有一句:
- j@j-desktop:~/test/examples/lesson6$ cat prog.cfg
- /*
- * ======== lesson6/prog.cfg ========
- */
- var Talker = xdc.useModule('lesson6.Talker');
- Talker.text = "Goodnight Moon";
- Talker.count = 3;
最终是xdc.useModule('lesson6.Talker')对应prog.c中的#include <lesson6/Talker.h>,而xdc.useModule('xdc.runtime.System')对应的是 Talker.c中的#include <xdc/runtime/System.h>。
另外还有一个函数module$validate可以用来验证某个条件是否成立,不成立最终可能停止编译。
下面可以编译了:
- j@j-desktop:~/test/examples/lesson6$ xdc all,64P
- generating interfaces for package lesson6 (because package/package.xdc.inc is older than package.xdc) ...
- translating Talker
- cl64P Talker.c ...
- cl64P package/package_lesson6.c ...
- archiving package/lib/lib/lesson6/Talker.o64P package/lib/lib/lesson6/package/package_lesson6.o64P into lib/lesson6.a64P ...
- configuring prog.x64P from package/cfg/prog_x64P.cfg ...
- cl64P prog.c ...
- cl64P package/cfg/prog_x64P.c ...
- lnk64P prog.x64P ...
- j@j-desktop:~/test/examples/lesson6$ xdc test,64P
- running prog.x64P ...
- Goodnight Moon
- Goodnight Moon
- Goodnight Moon
前:
- j@j-desktop:~/test/examples/lesson6$ xdc clean
- j@j-desktop:~/test/examples/lesson6$ ls
- lib package.xdc prog.cfg Talker.xdc
- package.bld prog.c Talker.c Talker.xs
- j@j-desktop:~/test/examples/lesson6$ ls
- lib package.bld package.xdc prog.cfg Talker.c Talker.xdc
- package package.mak prog.c prog.x64P Talker.h Talker.xs
- j@j-desktop:~/test/examples/lesson6$ ls package
- build.cfg internal lesson6.sch package.defs.h package.xdc.dep
- cfg lesson6.ccs lib package.doc.xml package.xdc.inc
- external lesson6.pjt package.bld.xml package_lesson6.c rel
- j@j-desktop:~/test/examples/lesson6$ ls package/internal/
- Talker.xdc.h
- j@j-desktop:~/test/examples/lesson6$ cat Talker.h |grep text
- String Talker_text;
- typedef xdc_String CT__lesson6_Talker_text;
- __extern __FAR__ const CT__lesson6_Talker_text lesson6_Talker_text__C;
- #define lesson6_Talker_text (lesson6_Talker_text__C)
- #define Talker_text lesson6_Talker_text
我试了下去掉config,但是编译不通过了,呵呵。
好,第六课结束。
这个文章实际上是为读示例代码服务的,下面转而进入读代码系统的第四篇: codec engine代码阅读四---CE_DIR/examples/ti/sdo/ce/examles/codecs/videnc_copy(http://alphamailpost.blog.163.com/blog/static/20111808120127219241667/)
稍微总结了一下几个文件之间的关系,有不对的地方还请楼主改正:
prog.cfg中的var Talker = xdc.useModule('lesson6.Talker');对应prog.c中的#include <lesson6/Talker.h>
package.xdc:用来描述模块,一般只进行声明,
package lesson6 {
module Talker;
};
块的详细描述在Talker.xdc中,进行了函数的声明,常量的声明和初始化。
/*! Our first module */
module Talker {
/*! What to say */
config String text = "Hello World"; //这里的config相当于#define
/*! How many times */
config Int count = 1;
/*! Say it */
Void print();
}
函数的实现在Talker.c中
#include <xdc/runtime/System.h>
#include "package/internal/Talker.xdc.h"(内部声明文件,可能有也可能在编译阶段生成,这种内部头文件必须写在所有其他头文件之后)
Void Talker_print()
{
Int i;
for (i = 0; i < Talker_count; i++) {
System_printf("%s\n", Talker_text);
}
}
Talker.c文件也有一个对应的文件Talker.xs。跟prog.c和prog.cfg的对应关系是一样的,只是Talker.xs中没有加Talker.c中包含的内部头文件
function module$use() //表明函数体的内容是某个外部函数调用useModule(lesson6.Talker)时返回的语句 ,这句没明白啥意思。
{
xdc.useModule('xdc.runtime.System');
}