OSDN Git Service

Implement batch and flush functions
authorAdriana Reus <adriana.reus@intel.com>
Thu, 25 Sep 2014 11:42:49 +0000 (14:42 +0300)
committerAdriana Reus <adriana.reus@intel.com>
Mon, 6 Oct 2014 12:35:09 +0000 (15:35 +0300)
We need these so that we can upgrade the HAL.
Even if we don't have batch yet, the 1_3 API is requiring them.

Change-Id: I47da935b38bf1b051e3b5a18951d8f4724a82e31
Signed-off-by: Adriana Reus <adriana.reus@intel.com>
common.h
control.c
control.h
entry.c
enumeration.c

index 76d26dd..59b5748 100644 (file)
--- a/common.h
+++ b/common.h
@@ -151,6 +151,11 @@ struct sensor_info_t
        int report_pending;
 
        /*
+        * This flag is set if we have a meta data event pending
+        */
+       volatile int meta_data_pending;
+
+       /*
         * Timestamp closely matching the date of sampling, preferably retrieved
         * from a iio channel alongside sample data. Value zero indicates that
         * we couldn't get such a closely correlated timestamp, and that one
index 7d942fd..b119007 100644 (file)
--- a/control.c
+++ b/control.c
@@ -32,6 +32,7 @@ static int active_poll_sensors; /* Number of enabled poll-mode sensors */
 static pthread_cond_t  thread_release_cond     [MAX_SENSORS];
 static pthread_mutex_t thread_release_mutex    [MAX_SENSORS];
 
+
 /*
  * We associate tags to each of our poll set entries. These tags have the
  * following values:
@@ -1029,7 +1030,7 @@ return_available_sensor_reports:
        returned_events = 0;
 
        /* Check our sensor collection for available reports */
-       for (s=0; s<sensor_count && returned_events < count; s++)
+       for (s=0; s<sensor_count && returned_events < count; s++) {
                if (sensor_info[s].report_pending) {
                        event_count = 0;
                        /* Lower flag */
@@ -1069,7 +1070,19 @@ return_available_sensor_reports:
                         * value for a 'on change' sensor, silently drop it.
                         */
                }
-
+               while (sensor_info[s].meta_data_pending) {
+                       /* See sensors.h on these */
+                       data[returned_events].version = META_DATA_VERSION;
+                       data[returned_events].sensor = 0;
+                       data[returned_events].type = SENSOR_TYPE_META_DATA;
+                       data[returned_events].reserved0 = 0;
+                       data[returned_events].timestamp = 0;
+                       data[returned_events].meta_data.sensor = s;
+                       data[returned_events].meta_data.what = META_DATA_FLUSH_COMPLETE;
+                       returned_events++;
+                       sensor_info[s].meta_data_pending--;
+               }
+       }
        if (returned_events)
                return returned_events;
 
@@ -1263,6 +1276,16 @@ int sensor_set_delay(int s, int64_t ns)
        return 0;
 }
 
+int sensor_flush (int s)
+{
+       /* If one shot or not enabled return -EINVAL */
+       if (sensor_desc[s].flags & SENSOR_FLAG_ONE_SHOT_MODE ||
+               sensor_info[s].enable_count == 0)
+               return -EINVAL;
+
+       sensor_info[s].meta_data_pending++;
+       return 0;
+}
 
 int allocate_control_data (void)
 {
index f9a9921..d1bfa41 100644 (file)
--- a/control.h
+++ b/control.h
@@ -7,7 +7,8 @@
 
 int    sensor_activate         (int handle, int enabled);
 int    sensor_set_delay        (int handle, int64_t ns);
-int    sensor_poll             (sensors_event_t* data, int count);
+int    sensor_poll     (sensors_event_t* data, int count);
+int sensor_flush       (int handle);
 
 int    allocate_control_data   (void);
 void   delete_control_data     (void);
diff --git a/entry.c b/entry.c
index df449db..fdf2390 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -58,7 +58,18 @@ static int poll(struct sensors_poll_device_t* dev, sensors_event_t* data,
        return sensor_poll(data, count);
 }
 
+static int batch (struct sensors_poll_device_1* dev,
+            int sensor_handle, int flags, int64_t sampling_period_ns,
+            int64_t max_report_latency_ns)
+{
+       return set_delay ((struct sensors_poll_device_t*)dev,
+               sensor_handle, sampling_period_ns);
+}
 
+static int flush(struct sensors_poll_device_1* dev, int handle)
+{
+       return sensor_flush (handle);
+}
 static int close_module(hw_device_t *device)
 {
        if (init_count == 0)
@@ -79,7 +90,7 @@ static int close_module(hw_device_t *device)
 static int initialize_module(const struct hw_module_t *module, const char *id,
                                struct hw_device_t** device)
 {
-       static struct sensors_poll_device_t poll_device;
+       static struct sensors_poll_device_1 poll_device;
 
        if (strcmp(id, SENSORS_HARDWARE_POLL))
                 return -EINVAL;
@@ -92,6 +103,8 @@ static int initialize_module(const struct hw_module_t *module, const char *id,
        poll_device.activate            = activate;
        poll_device.setDelay            = set_delay;
        poll_device.poll                = poll;
+       poll_device.batch               = batch;
+       poll_device.flush               = flush;
 
        *device = &poll_device.common;
 
index eda8845..c4d6321 100644 (file)
@@ -385,6 +385,8 @@ static void add_sensor (int dev_num, int catalog_index, int use_polling)
        sensor_info[s].thread_data_fd[1]  = -1;
        sensor_info[s].acquisition_thread = -1;
 
+       sensor_info[s].meta_data_pending = 0;
+
        /* Check if we have a special ordering property on this sensor */
        if (sensor_get_order(s, sensor_info[s].order))
                sensor_info[s].quirks |= QUIRK_FIELD_ORDERING;