Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » DSDP - Real-Time Software Components (RTSC) » Math functions for c28_float target
Math functions for c28_float target [message #720576] Tue, 30 August 2011 21:14 Go to next message
linkinsebas is currently offline linkinsebasFriend
Messages: 22
Registered: April 2011
Junior Member
Hi everyone.

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.
Re: Math functions for c28_float target [message #720672 is a reply to message #720576] Wed, 31 August 2011 04:06 Go to previous messageGo to next message
Sasha Slijepcevic is currently offline Sasha SlijepcevicFriend
Messages: 115
Registered: July 2009
Senior Member
First, you'll need a config parameter in your module that can be used in a config script to specify the path to the FPU fastRTS library. Let's call the parameter fastRtsPath. A config script would set it as follows:
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.
Re: Math functions for c28_float target [message #720687 is a reply to message #720672] Wed, 31 August 2011 04:33 Go to previous messageGo to next message
linkinsebas is currently offline linkinsebasFriend
Messages: 22
Registered: April 2011
Junior Member
Sasha:

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);
line of Math.c)

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.
Re: Math functions for c28_float target [message #720688 is a reply to message #720687] Wed, 31 August 2011 04:38 Go to previous messageGo to next message
linkinsebas is currently offline linkinsebasFriend
Messages: 22
Registered: April 2011
Junior Member
I forgot to include the contents of the following file:

/*
 *  ======== 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];
Re: Math functions for c28_float target [message #721034 is a reply to message #720688] Wed, 31 August 2011 18:18 Go to previous messageGo to next message
Sasha Slijepcevic is currently offline Sasha SlijepcevicFriend
Messages: 115
Registered: July 2009
Senior Member
Can you try renaming sqrt from the module Math to something like mySqrt or similar, just to check if the function name being the same in Math.xdc and in math.h is the source of the problem?
Also, in the directory where you are building the external application, look into the subdirectory package/cfg and find the file with the extension .xdl. Check the content of that file to see if the template generated the whole path to the fast RTS library.
Re: Math functions for c28_float target [message #721114 is a reply to message #721034] Wed, 31 August 2011 22:48 Go to previous messageGo to next message
linkinsebas is currently offline linkinsebasFriend
Messages: 22
Registered: April 2011
Junior Member
Sasha:

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.
Re: Math functions for c28_float target [message #721438 is a reply to message #721114] Thu, 01 September 2011 18:57 Go to previous messageGo to next message
linkinsebas is currently offline linkinsebasFriend
Messages: 22
Registered: April 2011
Junior Member
I have been digging some more into the problem.

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.

[Updated on: Thu, 01 September 2011 22:42]

Report message to a moderator

Re: Math functions for c28_float target [message #721495 is a reply to message #721438] Thu, 01 September 2011 22:42 Go to previous messageGo to next message
linkinsebas is currently offline linkinsebasFriend
Messages: 22
Registered: April 2011
Junior Member
Sasha:

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.

[Updated on: Fri, 02 September 2011 21:17]

Report message to a moderator

Re: Math functions for c28_float target [message #723482 is a reply to message #721495] Thu, 08 September 2011 16:26 Go to previous messageGo to next message
linkinsebas is currently offline linkinsebasFriend
Messages: 22
Registered: April 2011
Junior Member
Any ideas about why this happens?
Re: Math functions for c28_float target [message #741927 is a reply to message #721495] Thu, 20 October 2011 02:51 Go to previous message
Sasha Slijepcevic is currently offline Sasha SlijepcevicFriend
Messages: 115
Registered: July 2009
Senior Member
I can't tell why the prototype cannot be found. Can you build your sch.math package with the verbose output turned on:
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.
Previous Topic:Recipe for abstract instances
Next Topic:Module that uses c28x's peripherals
Goto Forum:
  


Current Time: Thu Mar 28 18:57:11 GMT 2024

Powered by FUDForum. Page generated in 0.03751 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top