I am trying to develop packages for c28_float targets which will do mathematical intensive computations. The modules therein will need to use functions like sin() and sqrt(). Before working with RTSC, I had been using the c28 FPU fastRTS library (http://read.pudn.com/downloads136/doc/582720/C28x_FPU_FastRTS_v10.pdf) and I would like to keep using it as a provider of these functions, which will now be used inside a RTSC Module. How do I build a Module so it uses this library?

Thanks for your advice.]]>

var Mod = xdc.useModule('pkg.YourMod'); Mod.fastRtsPath = "c:\tidcs\c28\C28x_FPU_fastRTS\v100";

Then, you can add the function getSects() to the file package.xs, which is located in your package that contains the module. The function getSects() returns the name of the template file, which will be evaluated and the result of the evaluation will be added to the generated linker command file. The generated linker command line comes before the standard runtime library, so by adding the fast RTS library to the linker command file, you'll achieve the required effect.

Since package.xs is a package level file, its functions will be invoked whenever the package is loaded. Therefore, you need to invoke the template only if the module that needs fast RTS is actually used:

function getSects() { if (this.YourMod.$used) { return ("link.xdt"); } return (null); }

The next step is to add the actual template file file link.xdt to the package (you can choose some other name, but it's important that the name of the file and the reference to it in getSects() match). The content of link.xdt is:

%var lib = xdc.module("pkg.YourMod").fastRtsPath + "/<library name>"; -l"`lib`"

Notice backquotes on the second line.

There are some other ways to include fastRTS, so if there are some issues with this approach, please let me know, and depending on these issues, we can come up with a different solution.]]>

I've defined a simple package with a simple module as follows:

/* * ======== sch/math/package.xdc ======== */ /*! Collection of math functions */ package sch.math { module Math; };

/* * ======== sch/math/package.bld ======== */ var Build = xdc.useModule('xdc.bld.BuildEnvironment'); var Pkg = xdc.useModule('xdc.bld.PackageContents'); for each (var targ in Build.targets) { Pkg.addLibrary("lib/" + Pkg.name, targ).addObjects(["Math.c"]); }

/* * ======== sch/math/package.xs ======== */ function getSects() { if (this.Math.$used) { return ("link.xdt"); } return (null); }

File link.xdt:

%var lib = xdc.module("pkg.Math").fastRtsPath + "/lib/rts2800_fpu32_fast_supplement.lib"; -l"`lib`"

Math.xdc

/* * ======== sch/math/Math ======== */ /*! Collection of math functions */ module Math { config String fastRtsPath = "C:/TI/controlSUITE/libs/math/FPUfastRTS/V100"; /*! Absolute value */ Float abs(Float number); /*! Square root */ Float sqrt(Float number); }; }

/* * ======== sch/math/Math.c ======== */ #include "package/internal/Math.xdc.h" #include <math.h> Float Math_abs(Float number) { return (number>0?number:-number); } Float Math_sqrt(Float number) { return sqrt(number); }

However, when I build the package I get a strange warning message:

G:\myRepository\sch\math>xdc all making package.mak (because of package.bld) ... generating interfaces for package sch.math (because package/package.xdc.inc is o lder than package.xdc) ... translating Math cl28FP package/package_sch.math.c ... cl28FP Math.c ... "Math.c", line 16: warning: function declared implicitly archiving package/lib/lib/sch.math/package/package_sch.math.o28FP package/lib/li b/sch.math/Math.o28FP into lib/sch.math.a28FP ... all files complete.

(line 16 refers to the

return sqrt(number);

And when I try to use Math_sqrt in an external application, it returns 0. The exact thing happens if I do not try to include the fastRTS library at all.

Is there something missing? What can I do?

Thanks for your help.]]>

/* * ======== config.bld ======== */ var Build = xdc.useModule('xdc.bld.BuildEnvironment'); var C28_float = xdc.useModule('ti.targets.C28_float'); /* modify to match %c6xtools% */ C28_float.rootDir = "C:/TI/ccsv4/tools/compiler/c2000"; //C28_float.platform = 'ti.platforms.sim64Pxx'; Build.targets = [C28_float];

I renamed the function to mySqrt, and the result is the same.

I think I made a mistake in file link.xdt and left "pkg" instead of the actual name of the package. Now this file contains:

%var lib = xdc.module("sch.math.Math").fastRtsPath + "/lib/rts2800_fpu32_fast_supplement.lib"; -l"`lib`"

However, the problem is still present.

In folder Debug\configPkg\package\cfg in the project folder (I am using ccsv4 for the client application) I find main_p28FP.xdl and main_p28FP_x.xdl. Both of them contain the following pair of lines:

/* Content from sch.math (link.xdt): */ -l"C:/TI/controlSUITE/libs/math/FPUfastRTS/V100/lib/rts2800_fpu32_fast_supplement.lib"

Also, I've noticed by using the "assembly step into" button that Math_mySqrt actually leads to sqrt from the fastRTS library, but for some reason the result is still 0. Maybe the argument is not being well copied.

Thanks for your help.]]>

If I use the following client application:

#include <xdc/std.h> #include <xdc/runtime/Types.h> #include <sch/math/Math.h> #include <math.h> #define mf_abs(x) (x>0?x:-x) float fast_sqrt(float number) { return sqrt(number); } // ======== main ======== Void main() { int i; float x_abs=-2.75; float y_abs_mf, y_abs_Math; float x_sqrt=0.5; float y_sqrt_fast, y_sqrt_Math; y_abs_mf=mf_abs(x_abs); y_abs_Math=Math_abs(x_abs); y_sqrt_fast=fast_sqrt(x_sqrt); y_sqrt_Math=Math_mySqrt(x_sqrt); return 0; }

I get y_sqrt_fast=0.707107 as expected but y_sqrt_Math=0. If I use the assembly step into feature of ccsv4, I see that fast_sqrt is compiled into:

.text, __text, fast_sqrt: 0x009000: FE02 ADDB SP, #2 0x009001: E2030042 MOV32 *-SP[2], R0H 0x009003: 7640BF5E LCR $C:/ti/controlSUITE/libs/math/FPUfastRTS/V100/source/sqrt_f32.asm:47:68$ 0x009005: FE82 SUBB SP, #2 0x009006: 0006 LRETR

whereas Math_mySqrt is compiled into:

sch_math_Math_mySqrt, sch_math_Math_mySqrt__F: 0x00C389: 7640BF5E LCR $C:/ti/controlSUITE/libs/math/FPUfastRTS/V100/source/sqrt_f32.asm:47:68$ 0x00C38B: 3B01 SETC SXM 0x00C38C: 85A9 MOV ACC, @AL 0x00C38D: BDA90F12 MOV32 *(0:0x0f12), @ACC 0x00C38F: 7700 NOP 0x00C390: 7700 NOP 0x00C391: 7700 NOP 0x00C392: 7700 NOP 0x00C393: E689 .word 0xe689 0x00C394: 0000 ITRAP0 0x00C395: 0006 LRETR

which is a significantly longer code. Despite the fact that both call the same optimized sqrt function, it seems that line 0x00C38D clears the content of register R0H which is supposed to hold the result. I do not know much about C28's assembly so I cannot really tell what is going on, except for some basic stuff.

Also, I found that the "function declared implicitly" warning means that a function doesn't have a prototype and the compiler has to make some assumptions about the values that are being passed/returned. Isn't math.h supposed to define a prototype for sqrt()? I found that if I remove #include <math.h> from Math.c the result is exactly the same.

Any help would be appreciated. Thanks.]]>

I was able to overcome the problem by adding the following line to Math.c (notice that math.h is not included anymore)

//#include <math.h> float sqrt(float number);

However, I don't think this is a definitive solution, but at least I can keep working now. If anyone can come with a better solution, it will be appreciated.

By the way, the file link.xdt you mentioned has to be located in the repository's root directory. What should I do if I want to have many modules from many packages that use the fastRTS library?

UPDATE: For this last issue, I realized that file link.xdc should be referenced inside package.xs using a fully-qualified name

/* * ======== sch/math/package.xs ======== */ function getSects() { if (this.Math.$used) { return ("sch/Math/link.xdt"); } return (null); }

Thanks for your help.]]>

xdc XDCOPTIONS=v all

I would like to see '-I' options added to the command line. If math.h wasn't on the include path, you would get an error, but if there is some invalid math.h somewhere, which doesn't define everything it should, you would have the problem exactly as yours.

]]>