summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2014-10-28 17:52:52 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-11-11 23:07:05 +0000
commit72da63a5f378d56b00696872f3f28f40436f637e (patch)
tree535ee77166d4544988fd042ad2cbeaea5154c312
parent1a38df1105020b7fc82e9a2ec100de8d29ca6c04 (diff)
downloadchrome-ec-72da63a5f378d56b00696872f3f28f40436f637e.tar.gz
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 <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/226414 Reviewed-by: Alec Berg <alecaberg@chromium.org> Reviewed-by: Sheng-liang Song <ssl@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/229170 Reviewed-by: Mohammed Habibulla <moch@chromium.org> Commit-Queue: Mohammed Habibulla <moch@chromium.org> Tested-by: Mohammed Habibulla <moch@chromium.org>
-rw-r--r--chip/host/config_chip.h2
-rw-r--r--common/math_util.c2
-rw-r--r--include/math_util.h8
-rw-r--r--test/math_util.c6
4 files changed, 17 insertions, 1 deletions
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 <math.h>
#include <stdio.h>
+#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);