From 72da63a5f378d56b00696872f3f28f40436f637e Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Tue, 28 Oct 2014 17:52:52 -0700 Subject: CHERRY-PICK: math: use CONFIG_FPU when using float. ifdef code than needs CONFIG_FPU (acos and friends) BRANCH=ToT BUG=chrome-os-partner:32050 TEST=define CONFIG_FPU on host board and use it. Change-Id: I6bb6c280e6f8af882b52e95c1b01dd26e31d286e Original-Change-Id: I1c4ed16c23450bb4059d26044f4c1fe45b33674e Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/226414 Reviewed-by: Alec Berg Reviewed-by: Sheng-liang Song Reviewed-on: https://chromium-review.googlesource.com/229170 Reviewed-by: Mohammed Habibulla Commit-Queue: Mohammed Habibulla Tested-by: Mohammed Habibulla --- chip/host/config_chip.h | 2 ++ common/math_util.c | 2 ++ include/math_util.h | 8 ++++++++ test/math_util.c | 6 +++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/chip/host/config_chip.h b/chip/host/config_chip.h index db61262ce2..a83fa778cf 100644 --- a/chip/host/config_chip.h +++ b/chip/host/config_chip.h @@ -21,6 +21,8 @@ extern char __host_flash[CONFIG_FLASH_PHYSICAL_SIZE]; #define CONFIG_RAM_BASE 0x0 /* Not supported */ #define CONFIG_RAM_SIZE 0x0 /* Not supported */ +#define CONFIG_FPU + /* Size of one firmware image in flash */ #define CONFIG_FW_IMAGE_SIZE (64 * 1024) diff --git a/common/math_util.c b/common/math_util.c index 83bfc6cdfb..56688283f4 100644 --- a/common/math_util.c +++ b/common/math_util.c @@ -14,6 +14,7 @@ #define COSINE_LUT_INCR_DEG 5 #define COSINE_LUT_SIZE ((180 / COSINE_LUT_INCR_DEG) + 1) +#ifdef CONFIG_FPU /* Lookup table for the value of cosine from 0 degrees to 180 degrees. */ static const float cos_lut[] = { 1.00000, 0.99619, 0.98481, 0.96593, 0.93969, @@ -83,6 +84,7 @@ float cosine_of_angle_diff(const vector_3_t v1, const vector_3_t v2) return (float)dotproduct / (denominator); } +#endif /* * rotate a vector v diff --git a/include/math_util.h b/include/math_util.h index 044c411b23..6ae36a995b 100644 --- a/include/math_util.h +++ b/include/math_util.h @@ -8,7 +8,12 @@ #ifndef __CROS_MATH_UTIL_H #define __CROS_MATH_UTIL_H +#ifdef CONFIG_FPU typedef float matrix_3x3_t[3][3]; +#else +typedef int matrix_3x3_t[3][3]; +#endif + typedef int vector_3_t[3]; @@ -16,6 +21,7 @@ typedef int vector_3_t[3]; #define SQ(x) ((x) * (x)) #define ABS(x) ((x) >= 0 ? (x) : -(x)) +#ifdef CONFIG_FPU /** * Find acos(x) in degrees. Argument is clipped to [-1.0, 1.0]. @@ -36,6 +42,8 @@ float arc_cos(float x); */ float cosine_of_angle_diff(const vector_3_t v1, const vector_3_t v2); +#endif + /** * Rotate vector v by rotation matrix R. * diff --git a/test/math_util.c b/test/math_util.c index 3c5a3fae01..46087e9f33 100644 --- a/test/math_util.c +++ b/test/math_util.c @@ -7,13 +7,17 @@ #include #include +#include "common.h" #include "math_util.h" #include "motion_sense.h" #include "test_util.h" #include "util.h" /*****************************************************************************/ -/* Need to define motion sensor globals just to compile. */ +/* + * Need to define motion sensor globals just to compile. + * We include motion task to force the inclusion of math_util.c + */ struct motion_sensor_t motion_sensors[] = {}; const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors); -- cgit v1.2.1