OSDN Git Service

The event timestamp as function of frequency
authorViorel Suman <viorel.suman@intel.com>
Thu, 18 Sep 2014 13:08:42 +0000 (16:08 +0300)
committerViorel Suman <viorel.suman@intel.com>
Wed, 24 Sep 2014 13:39:12 +0000 (16:39 +0300)
The patch guards the sensor event timestamp
as function of frequency in order to fix the
"EventGapVerification" and "FrequencyVerification"
from the new L-Dessert SingleSensorTests CTS test
case. It also introduces the CONTINUOUS_DRIVER quirk
used to enforce the continuous driver mode.

Issue: GMINL-544
Change-Id: I5b6accd1c7fa84e3eaeeb48c77fe86bc824781b3
Signed-off-by: Viorel Suman <viorel.suman@intel.com>
common.h
control.c
description.c
description.h

index fcc2025..1e5958f 100644 (file)
--- a/common.h
+++ b/common.h
@@ -27,7 +27,7 @@
 
 #define PROP_BASE      "ro.iio.%s.%s" /* Note: PROPERTY_KEY_MAX is small */
 
-#define MAX_EVENTS 1000        /* 1000 hz */
+#define MAX_EVENTS 800         /* 800 hz */
 #define MAX_TYPE_SPEC_LEN 32   /* Channel type spec len; ex: "le:u10/16>>0" */
 #define MAX_SENSOR_REPORT_SIZE 32      /* Sensor report buffer size */
 
index cfb272c..9e2ffb7 100644 (file)
--- a/control.c
+++ b/control.c
@@ -40,7 +40,6 @@ static pthread_mutex_t thread_release_mutex   [MAX_SENSORS];
  *  */
 #define THREAD_REPORT_TAG_BASE 0x00010000
 
-
 static int enable_buffer(int dev_num, int enabled)
 {
        char sysfs_path[PATH_MAX];
@@ -500,6 +499,9 @@ int sensor_activate(int s, int enabled)
        int dev_num = sensor_info[s].dev_num;
        int is_poll_sensor = !sensor_info[s].num_channels;
 
+       /* Prepare the report timestamp field for the first event, see set_report_ts method */
+       sensor_info[s].report_ts = 0;
+
        /* If we want to activate gyro calibrated and gyro uncalibrated is activated
         * Deactivate gyro uncalibrated - Uncalibrated releases handler
         * Activate gyro calibrated     - Calibrated has handler
@@ -663,6 +665,7 @@ static void enable_motion_trigger (int dev_num)
                if (sensor_info[s].dev_num == dev_num &&
                    sensor_info[s].enable_count &&
                    sensor_info[s].num_channels &&
+                   !(sensor_info[s].quirks & QUIRK_CONTINUOUS_DRIVER) &&
                    sensor_info[s].selected_trigger !=
                        sensor_info[s].motion_trigger_name)
                                candidate[candidate_count++] = s;
@@ -682,6 +685,18 @@ static void enable_motion_trigger (int dev_num)
        enable_buffer(dev_num, 1);
 }
 
+void set_report_ts(int s, int64_t ts)
+{
+       int64_t maxTs, period;
+
+       if (sensor_info[s].report_ts && sensor_info[s].sampling_rate) {
+               period = (int64_t) (1000000000LL / sensor_info[s].sampling_rate);
+               maxTs = sensor_info[s].report_ts + period;
+               sensor_info[s].report_ts = (ts < maxTs ? ts : maxTs);
+       } else {
+               sensor_info[s].report_ts = ts;
+       }
+}
 
 static int integrate_device_report(int dev_num)
 {
@@ -744,7 +759,7 @@ static int integrate_device_report(int dev_num)
                        ALOGV("Sensor %d report available (%d bytes)\n", s,
                              sr_offset);
 
-                       sensor_info[s].report_ts = ts;
+                       set_report_ts(s, ts);
                        sensor_info[s].report_pending = 1;
                        sensor_info[s].report_initialized = 1;
                }
@@ -859,7 +874,7 @@ static void synthetize_duplicate_samples (void)
 
                if (target_ts <= current_ts) {
                        /* Mark the sensor for event generation */
-                       sensor_info[s].report_ts = current_ts;
+                       set_report_ts(s, current_ts);
                        sensor_info[s].report_pending = 1;
                }
        }
@@ -879,7 +894,7 @@ static void integrate_thread_report (uint32_t tag)
                   expected_len);
 
        if (len == expected_len) {
-               sensor_info[s].report_ts = get_timestamp();
+               set_report_ts(s, get_timestamp());
                sensor_info[s].report_pending = 1;
        }
 }
@@ -945,6 +960,9 @@ int sensor_poll(struct sensors_event_t* data, int count)
 
 return_available_sensor_reports:
 
+       /* Synthetize duplicate samples if needed */
+       synthetize_duplicate_samples();
+
        returned_events = 0;
 
        /* Check our sensor collection for available reports */
@@ -1003,9 +1021,6 @@ await_event:
                goto await_event;
        }
 
-       /* Synthetize duplicate samples if needed */
-       synthetize_duplicate_samples();
-
        ALOGV("%d fds signalled\n", nfds);
 
        /* For each of the signalled sources */
index 1d2927e..2fa1e13 100644 (file)
@@ -262,7 +262,11 @@ uint32_t sensor_get_quirks (int s)
                if (strstr(quirks_buf, "init-rate"))
                        sensor_info[s].quirks |= QUIRK_INITIAL_RATE;
 
-               if (strstr(quirks_buf, "terse"))
+               if (strstr(quirks_buf, "continuous")) {
+                       sensor_info[s].quirks |= QUIRK_CONTINUOUS_DRIVER;
+               }
+
+               if (strstr(quirks_buf, "terse") && !(sensor_info[s].quirks & QUIRK_CONTINUOUS_DRIVER))
                        sensor_info[s].quirks |= QUIRK_TERSE_DRIVER;
 
                if (strstr(quirks_buf, "noisy"))
index a398b81..718539c 100644 (file)
@@ -12,6 +12,7 @@
 #define QUIRK_FIELD_ORDERING   0x04  /* Do field remapping for this sensor   */
 #define QUIRK_TERSE_DRIVER     0x08  /* Force duplicate events generation    */
 #define QUIRK_NOISY            0x10  /* High noise level on readings         */
+#define QUIRK_CONTINUOUS_DRIVER        0x20  /* Force the continuous driver mode     */
 
 char*  sensor_get_name         (int handle);
 char*  sensor_get_vendor       (int handle);