From 4fa7bb14860eb26c114fbec11e4bc96a2267882b Mon Sep 17 00:00:00 2001 From: James Bielman Date: Thu, 10 Jan 2013 11:22:37 -0800 Subject: [PATCH] Add AVR compatibility header for missing math.h definitions. - Define float versions of math functions to the double versions on AVR (eg. #define sinf sin). - These macros appear to be missing in older versions of avr-libs. - Include AP_Math.h rather than math.h to get these definitions. --- libraries/AC_PID/AC_PID.cpp | 2 +- libraries/APM_Control/AP_PitchController.cpp | 2 +- libraries/APM_Control/AP_RollController.cpp | 2 +- libraries/APM_Control/AP_YawController.cpp | 2 +- libraries/APM_PI/APM_PI.cpp | 2 +- libraries/AP_Baro/AP_Baro.cpp | 2 +- libraries/AP_Compass/AP_Compass_HMC5843.cpp | 2 +- libraries/AP_HAL/utility/Print.cpp | 3 +- libraries/AP_HAL_AVR_SITL/sitl_barometer.cpp | 2 + libraries/AP_Math/AP_Math.h | 3 + libraries/AP_Math/AP_Math_AVR_Compat.h | 153 +++++++++++++++++++ libraries/AP_PerfMon/AP_PerfMon.cpp | 4 +- libraries/Filter/DerivativeFilter.cpp | 2 +- 13 files changed, 169 insertions(+), 12 deletions(-) create mode 100644 libraries/AP_Math/AP_Math_AVR_Compat.h diff --git a/libraries/AC_PID/AC_PID.cpp b/libraries/AC_PID/AC_PID.cpp index d3ac81c7cf..9baa3cc14f 100644 --- a/libraries/AC_PID/AC_PID.cpp +++ b/libraries/AC_PID/AC_PID.cpp @@ -3,7 +3,7 @@ /// @file AC_PID.cpp /// @brief Generic PID algorithm -#include +#include #include "AC_PID.h" // Examples for _filter: diff --git a/libraries/APM_Control/AP_PitchController.cpp b/libraries/APM_Control/AP_PitchController.cpp index 966fddb1b3..b6566f2c96 100644 --- a/libraries/APM_Control/AP_PitchController.cpp +++ b/libraries/APM_Control/AP_PitchController.cpp @@ -7,7 +7,7 @@ // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. -#include +#include #include #include #include "AP_PitchController.h" diff --git a/libraries/APM_Control/AP_RollController.cpp b/libraries/APM_Control/AP_RollController.cpp index 64c81ea1fc..3a3ab5bfc2 100644 --- a/libraries/APM_Control/AP_RollController.cpp +++ b/libraries/APM_Control/AP_RollController.cpp @@ -7,7 +7,7 @@ // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. -#include +#include #include #include "AP_RollController.h" diff --git a/libraries/APM_Control/AP_YawController.cpp b/libraries/APM_Control/AP_YawController.cpp index 6a79ca9370..1030487dbd 100644 --- a/libraries/APM_Control/AP_YawController.cpp +++ b/libraries/APM_Control/AP_YawController.cpp @@ -7,7 +7,7 @@ // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. -#include +#include #include #include "AP_YawController.h" diff --git a/libraries/APM_PI/APM_PI.cpp b/libraries/APM_PI/APM_PI.cpp index 044d477edc..3623a615e8 100644 --- a/libraries/APM_PI/APM_PI.cpp +++ b/libraries/APM_PI/APM_PI.cpp @@ -3,7 +3,7 @@ /// @file ACM_PI.cpp /// @brief Generic PI algorithm -#include +#include #include "APM_PI.h" diff --git a/libraries/AP_Baro/AP_Baro.cpp b/libraries/AP_Baro/AP_Baro.cpp index 0bc4e230a6..b0be90a627 100644 --- a/libraries/AP_Baro/AP_Baro.cpp +++ b/libraries/AP_Baro/AP_Baro.cpp @@ -8,7 +8,7 @@ * of the License, or (at your option) any later version. */ -#include +#include #include #include #include diff --git a/libraries/AP_Compass/AP_Compass_HMC5843.cpp b/libraries/AP_Compass/AP_Compass_HMC5843.cpp index f5d7f22a48..cd3761fa97 100644 --- a/libraries/AP_Compass/AP_Compass_HMC5843.cpp +++ b/libraries/AP_Compass/AP_Compass_HMC5843.cpp @@ -14,7 +14,7 @@ */ // AVR LibC Includes -#include +#include #include #include "AP_Compass_HMC5843.h" diff --git a/libraries/AP_HAL/utility/Print.cpp b/libraries/AP_HAL/utility/Print.cpp index 14ed750c63..eb76107483 100644 --- a/libraries/AP_HAL/utility/Print.cpp +++ b/libraries/AP_HAL/utility/Print.cpp @@ -23,9 +23,8 @@ #include #include #include -#include - +#include #include "../AP_HAL_Namespace.h" #include "Print.h" using namespace AP_HAL; diff --git a/libraries/AP_HAL_AVR_SITL/sitl_barometer.cpp b/libraries/AP_HAL_AVR_SITL/sitl_barometer.cpp index 7b7c0f0e71..f693bc3d11 100644 --- a/libraries/AP_HAL_AVR_SITL/sitl_barometer.cpp +++ b/libraries/AP_HAL_AVR_SITL/sitl_barometer.cpp @@ -7,6 +7,8 @@ */ #include +#include + #if CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL #include "AP_HAL_AVR_SITL.h" diff --git a/libraries/AP_Math/AP_Math.h b/libraries/AP_Math/AP_Math.h index 19dcdd5a76..5f8b52d10e 100644 --- a/libraries/AP_Math/AP_Math.h +++ b/libraries/AP_Math/AP_Math.h @@ -8,6 +8,9 @@ #include #include #include +#ifdef __AVR__ +# include +#endif #include #include "rotations.h" #include "vector2.h" diff --git a/libraries/AP_Math/AP_Math_AVR_Compat.h b/libraries/AP_Math/AP_Math_AVR_Compat.h new file mode 100644 index 0000000000..6c6cf5b859 --- /dev/null +++ b/libraries/AP_Math/AP_Math_AVR_Compat.h @@ -0,0 +1,153 @@ +// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*- + +#ifndef AP_MATH_AVR_COMPAT_H +#define AP_MATH_AVR_COMPAT_H + +// This file defines the floating-point version of standard C math +// functions on doubles, if they are not present in avr-libc. + +#ifndef cosf +# define cosf cos +#endif + +#ifndef sinf +# define sinf sin +#endif + +#ifndef tanf +# define tanf tan +#endif + +#ifndef fabsf +# define fabsf fabs +#endif + +#ifndef fmodf +# define fmodf fmod +#endif + +#ifndef sqrtf +# define sqrtf sqrt +#endif + +#ifndef cbrtf +# define cbrtf cbrt +#endif + +#ifndef hypotf +# define hypotf hypot +#endif + +#ifndef squaref +# define squaref square +#endif + +#ifndef floorf +# define floorf floor +#endif + +#ifndef ceilf +# define ceilf ceil +#endif + +#ifndef frexpf +# define frexpf frexp +#endif + +#ifndef ldexpf +# define ldexpf ldexp +#endif + +#ifndef expf +# define expf exp +#endif + +#ifndef coshf +# define coshf cosh +#endif + +#ifndef sinhf +# define sinhf sinh +#endif + +#ifndef tanhf +# define tanhf tanh +#endif + +#ifndef acosf +# define acosf acos +#endif + +#ifndef asinf +# define asinf asin +#endif + +#ifndef atanf +# define atanf atan +#endif + +#ifndef atan2f +# define atan2f atan2 +#endif + +#ifndef logf +# define logf log +#endif + +#ifndef log10f +# define log10f log10 +#endif + +#ifndef powf +# define powf pow +#endif + +#ifndef isnanf +# define isnanf isnan +#endif + +#ifndef isinff +# define isinff isinf +#endif + +#ifndef isfinitef +# define isfinitef isfinite +#endif + +#ifndef copysignf +# define copysignf copysign +#endif + +#ifndef signbitf +# define signbitf signbit +#endif + +#ifndef fdimf +# define fdimf fdim +#endif + +#ifndef fmaf +# define fmaf fma +#endif + +#ifndef fminf +# define fminf fmin +#endif + +#ifndef truncf +# define truncf trunc +#endif + +#ifndef roundf +# define roundf round +#endif + +#ifndef lroundf +# define lroundf lround +#endif + +#ifndef lrintf +# define lrintf lrint +#endif + +#endif // !defined AP_MATH_AVR_COMPAT_H diff --git a/libraries/AP_PerfMon/AP_PerfMon.cpp b/libraries/AP_PerfMon/AP_PerfMon.cpp index deae1d6355..8fb22505fe 100644 --- a/libraries/AP_PerfMon/AP_PerfMon.cpp +++ b/libraries/AP_PerfMon/AP_PerfMon.cpp @@ -1,5 +1,5 @@ -#include +#include #include #include "Arduino.h" #include "AP_PerfMon.h" @@ -216,4 +216,4 @@ void AP_PerfMon::DisplayAndClear(uint32_t display_after_seconds) DisplayResults(); ClearAll(); } -} \ No newline at end of file +} diff --git a/libraries/Filter/DerivativeFilter.cpp b/libraries/Filter/DerivativeFilter.cpp index 34e8e80f92..d7cea8b865 100644 --- a/libraries/Filter/DerivativeFilter.cpp +++ b/libraries/Filter/DerivativeFilter.cpp @@ -11,7 +11,7 @@ /// See http://www.holoborodko.com/pavel/numerical-methods/numerical-derivative/smooth-low-noise-differentiators/ // #include -#include +#include #include #include