ts-7000
[Top] [All Lists]

[ts-7000] Re: transferring floating point data from PC to TS7300

To:
Subject: [ts-7000] Re: transferring floating point data from PC to TS7300
From: "Oguz Dilmac" <>
Date: Mon, 19 Feb 2007 16:58:07 -0000
Thank you all for your replies.

I checked the floating point variable's bytes with William's example
code. They have exactly the same patterns!!!. Both my PC and ARM has
displayed the same hex numbers as William's message.

So I can see that my problem wasn't about floating point
representation formats.

I saw that when I pass data from the user program via a FIFO, floating
point data some how damaged. Then we started to go deeper, and see
that even an assignment from an int to float is not performed OK in a
periodic task.

I'm using RTAI for realtime kernel modules. Task waits its period with
rt_task_wait_period().

Another strange thing, that I noticed, is if the task is not periodic
and wait only with rt_sleep() than these operations are performed OK.
rt_task_use_fpu function doesn't help either.

I couldn't make floating point examples from RTAI either. 

Any idea?

Best regards,
Oguz.



--- In  "William C. Landolina" <> 
wrote:
>
> As Yan said, it's not guaranteed to be portable, but it is very
> practical to directly move floats back and forth between a PC and an
> embedded system.
> 
> The good news is that nowadays most systems use IEEE standard floating
> point representation.  I routinely move floats from PCs to AVR and ARM
> embedded systems without translation.
> 
> Using the following code (compiled under MS Visual Studio 2005 as a
> WIN32 Console application) and on a TS-7200 NetBSD 3.0/GCC I get
> identical results:
> 
>   Int:  44 33 22 11
>   1.5:  00 00 c0 3f
>   3.3:  33 33 53 40
>   10.0: 00 00 20 41
> 
> This says to me that the systems use the same floating point formats and
> endian-ness.
> 
> As for alignment, the Microsoft C Compiler has pragmas that allow
> practically any structure packing.  At the worst, you might end up
> putting pad bytes into a structure on one side or the other.  In C and
> C++ there are almost always some way to control structure packing -
> historically it was common to define a structure to actually match the
> register layout of arbitrary hardware devices which often had
> "unfriendly" layouts.
> 
> In any case, when you are unsure of structure packing or layout, get
> creative and print out the memory contents and see what you actually
> have.  There is nothing "magic" in a float, it's a pile of bits like
> anything else.
> 
> Enjoy,
> Bill Landolina
> 
> 
> 
> ------------ sample detective program ---------------
> 
> // FloatInfo.cpp : Defines the entry point for the console application.
> //
> 
> #include "stdafx.h"
> 
> struct interop
> {
>       int i;
>       float x;
>       float y;
>       float z;
> };
> 
> void print4(char *tag, void *p)
> {
>       unsigned char *cp = (unsigned char *) p;
>       printf("%s: %02x %02x %02x %02x\n",
>               tag, cp[0], cp[1], cp[2], cp[3]);
> }
> int _tmain(int argc, _TCHAR* argv[]) // I changed this to main() etc on
> ARM/GCC
> {
>       interop s;
> 
>       s.i = 0x11223344;
>       s.x = (float) 1.5;
>       s.y = (float) 3.3;
>       s.z = (float) 10;
> 
>       print4("Int:  ", &s.i);
>       print4("1.5:  ", &s.x);
>       print4("3.3:  ", &s.y);
>       print4("10.0: ", &s.z);
> 
>       getchar();
> 
> 
>       return 0;
> }
> 
> 
> -----Original Message-----
> From:   On Behalf
> Of Yan Seiner
> Sent: Sunday, February 18, 2007 10:47 AM
> To: 
> Subject: [ts-7000] Re: transferring floating point data from PC to
> TS7300
> 
> --- In  "Oguz Dilmac" <odilmac@> wrote:
> >
> > Hi all,
> > 
> > I'm trying to pass some data from my pc to ts7300 via Ethernet.
> > It seems floating point formats of EP9302 and PC are different from
> > each other.
> > 
> > In my program, I have a struct with both floating point and integer
> > variables. I simply send this data to ethernet from PC. On the arm
> > side, a user program gets the data from socket and put it to a FIFO to
> > pass to a kernel module. Then I print them with rt_printk.
> > 
> > When I dmesg, Integer parts are OK. But float parts are garbage.
> > 
> 
> I looked at doing this.  I even had a discussion of this on either the
> gcc list or the general C list; I forget.
> 
> The gist of the issue is this:
> 
> While in theory you could get it to work, in practice it is
> unmaintainable.
> 
> Structs are created by the compiler, and as such, the various byte
> padding schemes and memory alignment schemes can vary from compiler to
> compiler, between compiler versions, and possibly even between
> compiler runs, so there's no guarantee that it will work even on the
> same hardware platform.
> 
> Now throw in the problem of endiannes, and the different float
> formats, and the fact that on some architectures ints are 2 bytes, on
> some 4 bytes, and if you're really using off-the-wall stuff, 36 bits.
> 
> In other words, it cannot be done.
> 
> I ended up normalizing everything into 2 byte big-endian ints, and
> writing routines that pack and unpack the data.  (See PHP's
> pack/unpack functions.)
> 
> Look into the modbus spec for a truly portable (but not easy to
> implement) way to transfer data between arbitrary architectures.
> 
> --Yan
> 
> 
> 
>  
> Yahoo! Groups Links
>




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU