paparazzi-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Paparazzi-devel] arm7 C double precision math


From: Adam Spence
Subject: Re: [Paparazzi-devel] arm7 C double precision math
Date: Wed, 7 Oct 2009 14:17:50 +0100

Hey Mark,

Even thought it is not supported in hardware the compiler will perform the multiplication in software. This just means that it takes more clock cycles to perform the calculation.

Adam


2009/10/7 <address@hidden>
I understand that the LPC2148's MAC supports integer and long integer multiplication in hardware (see page 23 of http://www.cecs.csulb.edu/~brewer/347/lpc-ARM-book_srn.pdf). I doesn't appear to support double precision multiplication in hardware. hope this helps. Cheers, Mark


From: paparazzi-devel-bounces+mark.griffin=itu.int@nongnu.org [mailto:paparazzi-devel-bounces+mark.griffin=itu.int@nongnu.org] On Behalf Of Adam Spence
Sent: Wednesday, 7 October 2009 9:59 AM
To: address@hidden
Subject: Re: [Paparazzi-devel] arm7 C double precision math

My initial feeling would be endian but you say you have tested this with float? The only other thing I can think of is the reversal of the 4 bytes. As floats are 32 bits on the platform I am assuming the memory access is also 32 bits. A double is normally 64 bits (not sure on the Arm7tdmi) but as the memory access is 32 bits (again I am making an assumption) it could be that you need to reverse the first 4 bytes with the last 4.

Again without any first had experience of the platform and without knowing what is attached at the other end it is a bit of a stab in the dark.

It would load the processor up more but the alternative not to have to worry about this would be to send the number in Ascii and then convert this back to a number. Like I say though this will cause more processing and may not be desirable. This would make the solution platform independent as you would not have to worry about memory architectures. 

Adam

2009/10/7 miles <address@hidden>
Hi All,

I am running into an issue where it looks like the tiny2.11 (arm7tdmi) board can store double precision floating point numbers, but does not perform arithmetic (addition, multiplication) correctly.  Has anyone seen this, and/or resolved this before?

As a test, I have been trying to send a byte array of length 8 representing a double precision number over serial (via USB) to the Autopilot, use memcpy to copy that buffer to a variable of type double, and then do some simple addition, and send the result back over serial.  Below is the Autopilot code I am using.  Note that all of this works as expected for "float" variables, but seems to break for "double" variables! 

#include "std.h"
#include "init_hw.h"
#include "sys_time.h"
#include "led.h"
#include "usb_serial.h"

static inline void main_init( void );
static inline void main_periodic_task( void );

int main( void ) {
  main_init();
  while(1) {
    if (sys_time_periodic())
      main_periodic_task();
  }
  return 0;
}

static inline void main_init( void ) {
  hw_init();
  sys_time_init();
  led_init();
  VCOM_init();
  enableIRQ();
}

static inline void main_periodic_task( void ) {
  LED_TOGGLE(1);
 
  unsigned char buf[8];
  unsigned char buf2[8];
  double x;
  int c = 0;
  int c2 = 0;

  // read 8 bytes from serial (over USB)
  while (c < 8) {
    if (VCOM_check_available()) {
      buf[c] = VCOM_getchar();
      c++;
    }
  }
 
  // deserialize byte array to float:
  memcpy(&x, buf, 8);
  // modify float
  x = x + 1.0;
  // serialize float to byte array for sending
  memcpy(buf2, &x, 8);

  c2 = 0;
  while (c2 < 8) {
    VCOM_putchar(buf2[c2]);
    c2++;
  }
 
}

--
Miles Johnson

_______________________________________________
Paparazzi-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/paparazzi-devel



_______________________________________________
Paparazzi-devel mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/paparazzi-devel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]