You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by st...@apache.org on 2016/12/13 05:42:22 UTC

[2/6] incubator-mynewt-core git commit: add sensor API, interim commit. Things are working in simulated mode to register and list sensors.

add sensor API, interim commit.  Things are working in simulated mode to register and list sensors.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/c44ff1f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/c44ff1f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/c44ff1f4

Branch: refs/heads/sensors_branch
Commit: c44ff1f4e218a1c41d771a975a7c6ff9b54ec613
Parents: 397f4a2
Author: Sterling Hughes <st...@apache.org>
Authored: Sat Dec 10 16:47:11 2016 -0800
Committer: Sterling Hughes <st...@apache.org>
Committed: Mon Dec 12 21:42:04 2016 -0800

----------------------------------------------------------------------
 apps/slinky/pkg.yml                            |   1 +
 apps/slinky/src/main.c                         |   9 +
 hw/drivers/sensors/sim/include/sim/sim_accel.h |  50 ++++++
 hw/drivers/sensors/sim/pkg.yml                 |  25 +++
 hw/drivers/sensors/sim/src/generic_accel.c     | 177 ++++++++++++++++++++
 hw/sensor/include/sensor/accel.h               |  48 ++++++
 hw/sensor/include/sensor/sensor.h              |  95 +++++++----
 hw/sensor/pkg.yml                              |   4 -
 hw/sensor/src/sensor.c                         |  52 +++++-
 hw/sensor/src/sensor_priv.h                    |  29 ++++
 hw/sensor/src/sensor_shell.c                   | 114 +++++++++++++
 hw/sensor/syscfg.yml                           |   4 +
 12 files changed, 567 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c44ff1f4/apps/slinky/pkg.yml
----------------------------------------------------------------------
diff --git a/apps/slinky/pkg.yml b/apps/slinky/pkg.yml
index cd63f0a..ab87296 100644
--- a/apps/slinky/pkg.yml
+++ b/apps/slinky/pkg.yml
@@ -27,6 +27,7 @@ pkg.keywords:
 pkg.deps:
     - sys/console/full
     - hw/sensor 
+    - hw/drivers/sensors/sim 
     - test/flash_test
     - mgmt/imgmgr
     - mgmt/newtmgr

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c44ff1f4/apps/slinky/src/main.c
----------------------------------------------------------------------
diff --git a/apps/slinky/src/main.c b/apps/slinky/src/main.c
index 342a901..298696b 100755
--- a/apps/slinky/src/main.c
+++ b/apps/slinky/src/main.c
@@ -29,6 +29,8 @@
 #include <log/log.h>
 #include <stats/stats.h>
 #include <config/config.h>
+#include <sensor/sensor.h>
+#include <sim/sim_accel.h>
 #include "flash_map/flash_map.h"
 #include <hal/hal_system.h>
 #if MYNEWT_VAL(SPLIT_LOADER)
@@ -109,6 +111,8 @@ static struct cbmem cbmem;
 
 static struct os_eventq slinky_evq;
 
+struct sim_accel sim_accel_sensor;
+
 static char *
 test_conf_get(int argc, char **argv, char *buf, int max_len)
 {
@@ -316,6 +320,11 @@ main(int argc, char **argv)
 
     init_tasks();
 
+    sensor_pkg_init();
+
+    os_dev_create((struct os_dev *) &sim_accel_sensor, "simaccel0",
+            OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIMARY, sim_accel_init, NULL);
+
     os_start();
 
     /* os start should never return. If it does, this should be an error */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c44ff1f4/hw/drivers/sensors/sim/include/sim/sim_accel.h
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/sim/include/sim/sim_accel.h b/hw/drivers/sensors/sim/include/sim/sim_accel.h
new file mode 100644
index 0000000..6f0f6a1
--- /dev/null
+++ b/hw/drivers/sensors/sim/include/sim/sim_accel.h
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __SIM_ACCEL_H__
+#define __SIM_ACCEL_H__
+
+#include "os/os.h"
+#include "os/os_dev.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct sim_accel_cfg {
+    uint8_t sac_nr_samples;
+    uint8_t sac_nr_axises;
+    uint16_t sac_sample_itvl;
+};
+
+struct sim_accel {
+    struct os_dev sa_dev;
+    struct sensor sa_sensor;
+    struct sim_accel_cfg sa_cfg;
+    os_time_t sa_last_read_time;
+};
+
+int sim_accel_init(struct os_dev *, void *);
+int sim_accel_config(struct sim_accel *, struct sim_accel_cfg *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SENSOR_SIM_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c44ff1f4/hw/drivers/sensors/sim/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/sim/pkg.yml b/hw/drivers/sensors/sim/pkg.yml
new file mode 100644
index 0000000..f0c3a6e
--- /dev/null
+++ b/hw/drivers/sensors/sim/pkg.yml
@@ -0,0 +1,25 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+pkg.name: hw/drivers/sensors/sim
+pkg.description: Sensor simulated interfaces
+pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c44ff1f4/hw/drivers/sensors/sim/src/generic_accel.c
----------------------------------------------------------------------
diff --git a/hw/drivers/sensors/sim/src/generic_accel.c b/hw/drivers/sensors/sim/src/generic_accel.c
new file mode 100644
index 0000000..164c1e2
--- /dev/null
+++ b/hw/drivers/sensors/sim/src/generic_accel.c
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * resarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+
+#include "defs/error.h"
+
+#include "os/os.h"
+#include "sysinit/sysinit.h"
+
+#include "sensor/sensor.h"
+#include "sensor/accel.h"
+
+#include "sim/sim_accel.h"
+
+/* Exports for the sensor interface.
+ */
+static void *sim_accel_sensor_get_interface(struct sensor *, sensor_type_t);
+static int sim_accel_sensor_read(struct sensor *, sensor_type_t,
+        sensor_data_func_t, void *, uint32_t);
+static int sim_accel_sensor_get_config(struct sensor *, sensor_type_t,
+        struct sensor_cfg *);
+
+static const struct sensor_driver g_sim_accel_sensor_driver = {
+    sim_accel_sensor_get_interface,
+    sim_accel_sensor_read,
+    sim_accel_sensor_get_config
+};
+
+/**
+ * Expects to be called back through os_dev_create().
+ *
+ * @param The device object associated with this accellerometer
+ * @param Argument passed to OS device init, unused
+ *
+ * @return 0 on success, non-zero error on failure.
+ */
+int
+sim_accel_init(struct os_dev *dev, void *arg)
+{
+    struct sim_accel *sa;
+    struct sensor *sensor;
+    int rc;
+
+    sa = (struct sim_accel *) dev;
+
+    sensor = &sa->sa_sensor;
+
+    rc = sensor_init(sensor, dev);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = sensor_set_driver(sensor, SENSOR_TYPE_ACCELEROMETER,
+            (struct sensor_driver *) &g_sim_accel_sensor_driver);
+    if (rc != 0) {
+        goto err;
+    }
+
+    rc = sensor_mgr_register(sensor);
+    if (rc != 0) {
+        goto err;
+    }
+
+    return (0);
+err:
+    return (rc);
+}
+
+int
+sim_accel_config(struct sim_accel *sa, struct sim_accel_cfg *cfg)
+{
+    /* Overwrite the configuration associated with this generic accelleromter. */
+    memcpy(&sa->sa_cfg, cfg, sizeof(*cfg));
+
+    return (0);
+}
+
+static void *
+sim_accel_sensor_get_interface(struct sensor *sensor, sensor_type_t type)
+{
+    return (NULL);
+}
+
+
+static int
+sim_accel_sensor_read(struct sensor *sensor, sensor_type_t type,
+        sensor_data_func_t data_func, void *data_arg, uint32_t timeout)
+{
+    struct sim_accel *sa;
+    struct sensor_accel_data sad;
+    os_time_t now;
+    uint32_t num_samples;
+    int i;
+    int rc;
+
+    if (type != SENSOR_TYPE_ACCELEROMETER) {
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
+    sa = (struct sim_accel *) SENSOR_GET_DEVICE(sensor);
+
+    /* When a sensor is "read", we get the last 'n' samples from the device
+     * and pass them to the sensor data function.  Based on the sample
+     * interval provided to sim_accel_config() and the last time this function
+     * was called, 'n' samples are generated.
+     */
+    now = os_time_get();
+
+    num_samples = (now - sa->sa_last_read_time) / sa->sa_cfg.sac_sample_itvl;
+    num_samples = min(num_samples, sa->sa_cfg.sac_nr_samples);
+
+    /* By default only readings are provided for 1-axis (x), however,
+     * if number of axises is configured, up to 3-axises of data can be
+     * returned.
+     */
+    sad.sad_x = 0;
+    sad.sad_y = SENSOR_ACCEL_DATA_UNUSED;
+    sad.sad_z = SENSOR_ACCEL_DATA_UNUSED;
+
+    if (sa->sa_cfg.sac_nr_axises > 1) {
+        sad.sad_y = 0;
+    }
+    if (sa->sa_cfg.sac_nr_axises > 2) {
+        sad.sad_z = 0;
+    }
+
+    /* Call data function for each of the generated readings. */
+    for (i = 0; i < num_samples; i++) {
+        rc = data_func(sensor, data_arg, &sad);
+        if (rc != 0) {
+            goto err;
+        }
+    }
+
+    return (0);
+err:
+    return (rc);
+}
+
+static int
+sim_accel_sensor_get_config(struct sensor *sensor, sensor_type_t type,
+        struct sensor_cfg *cfg)
+{
+    int rc;
+
+    if (type != SENSOR_TYPE_ACCELEROMETER) {
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
+    cfg->sc_valtype = SENSOR_VALUE_TYPE_MS2_TRIPLET;
+
+    return (0);
+err:
+    return (rc);
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c44ff1f4/hw/sensor/include/sensor/accel.h
----------------------------------------------------------------------
diff --git a/hw/sensor/include/sensor/accel.h b/hw/sensor/include/sensor/accel.h
new file mode 100644
index 0000000..e56871b
--- /dev/null
+++ b/hw/sensor/include/sensor/accel.h
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __SENSOR_ACCEL_H__
+#define __SENSOR_ACCEL_H__
+
+#include "os/os.h"
+#include "os/os_dev.h"
+#include "sensor/sensor.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Data representing a singular read from an accelerometer.
+ */
+struct sensor_accel_data {
+    int32_t sad_x;
+    int32_t sad_y;
+    int32_t sad_z;
+} __attribute__((packed));
+
+/**
+ * Accelerometer data is unused for this field.
+ */
+#define SENSOR_ACCEL_DATA_UNUSED (0xFFFFFFFF)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __SENSOR_ACCEL_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c44ff1f4/hw/sensor/include/sensor/sensor.h
----------------------------------------------------------------------
diff --git a/hw/sensor/include/sensor/sensor.h b/hw/sensor/include/sensor/sensor.h
index a825b51..64ab640 100644
--- a/hw/sensor/include/sensor/sensor.h
+++ b/hw/sensor/include/sensor/sensor.h
@@ -27,6 +27,10 @@
 extern "C" {
 #endif
 
+/* Package init function.  Remove when we have post-kernel init stages.
+ */
+void sensor_pkg_init(void);
+
 
 /* Forward declare sensor structure defined below. */
 struct sensor;
@@ -36,36 +40,32 @@ struct sensor;
  */
 
 typedef enum {
-    /* No sensor type, used for queries */
+ /* No sensor type, used for queries */
     SENSOR_TYPE_NONE                 = 0,
     /* Accelerometer functionality supported */
-    SENSOR_TYPE_ACCELEROMETER       = (1 << 0),
-    /* Ambient temperature supported */
-    SENSOR_TYPE_AMBIENT_TEMPERATURE  = (1 << 1),
-    /* Gravity supported */
-    SENSOR_TYPE_GRAVITY              = (1 << 2),
+    SENSOR_TYPE_ACCELEROMETER        = (1 << 0),
+    /* Magnetic field supported */
+    SENSOR_TYPE_MAGNETIC_FIELD       = (1 << 1),
     /* Gyroscope supported */
-    SENSOR_TYPE_GYROSCOPE            = (1 << 3),
+    SENSOR_TYPE_GYROSCOPE            = (1 << 2),
     /* Light supported */
-    SENSOR_TYPE_LIGHT                = (1 << 4),
-    /* Linear acceleration supported */
-    SENSOR_TYPE_LINEAR_ACCELERATION = (1 << 5),
-    /* Magnetic field supported */
-    SENSOR_TYPE_MAGNETIC_FIELD       = (1 << 6),
-    /* Orientation sensor supported */
-    SENSOR_TYPE_ORIENTATION          = (1 << 7),
+    SENSOR_TYPE_LIGHT                = (1 << 3),
+    /* Temperature supported */
+    SENSOR_TYPE_TEMPERATURE          = (1 << 4),
+    /* Ambient temperature supported */
+    SENSOR_TYPE_AMBIENT_TEMPERATURE  = (1 << 5),
     /* Pressure sensor supported */
-    SENSOR_TYPE_PRESSURE             = (1 << 8),
+    SENSOR_TYPE_PRESSURE             = (1 << 6),
     /* Proximity sensor supported */
-    SENSOR_TYPE_PROXIMITY            = (1 << 9),
+    SENSOR_TYPE_PROXIMITY            = (1 << 7),
     /* Relative humidity supported */
-    SENSOR_TYPE_RELATIVE_HUMIDITY    = (1 << 10),
-    /* Rotation Vector supported */
-    SENSOR_TYPE_ROTATION_VECTOR      = (1 << 11),
-    /* Temperature supported */
-    SENSOR_TYPE_TEMPERATURE          = (1 << 12),
+    SENSOR_TYPE_RELATIVE_HUMIDITY    = (1 << 8),
+    /* Rotation vector (quaternion) supported */
+    SENSOR_TYPE_ROTATION_VECTOR      = (1 << 9),
     /* Altitude Supported */
-    SENSOR_TYPE_ALTITUDE             = (1 << 13),
+    SENSOR_TYPE_ALTITUDE             = (1 << 10),
+    /* Weight Supported */
+    SENSOR_TYPE_WEIGHT               = (1 << 11),
     /* User defined sensor type 1 */
     SENSOR_TYPE_USER_DEFINED_1       = (1 << 26),
     /* User defined sensor type 2 */
@@ -96,6 +96,18 @@ typedef enum {
  * 32-bit floating point
  */
 #define SENSOR_VALUE_TYPE_FLOAT  (2)
+/**
+ * Meters per second squared.
+ *
+ * 32-bit signed integer, with 0xFFFFFFFF reserved for unused.
+ */
+#define SENSOR_VALUE_TYPE_MS2    (3)
+/**
+ * Triplet of meters per second squared.
+ */
+#define SENSOR_VALUE_TYPE_MS2_TRIPLET (4)
+
+
 
 /**
  * Configuration structure, describing a specific sensor type off of
@@ -118,7 +130,7 @@ struct sensor_cfg {
  * @param The argument provided to sensor_read() function.
  * @param A single sensor reading for that sensor listener
  *
- * @return 0 on succes, non-zero error code on failure.
+ * @return 0 on success, non-zero error code on failure.
  */
 typedef int (*sensor_data_func_t)(struct sensor *, void *, void *);
 
@@ -144,8 +156,6 @@ struct sensor_listener {
     SLIST_ENTRY(sensor_listener) sl_next;
 };
 
-struct sensor;
-
 /**
  * Get a more specific interface on this sensor object (e.g. Gyro, Magnometer),
  * which has additional functions for managing the sensor.
@@ -187,12 +197,17 @@ typedef int (*sensor_read_func_t)(struct sensor *, sensor_type_t,
 typedef int (*sensor_get_config_func_t)(struct sensor *, sensor_type_t,
         struct sensor_cfg *);
 
-struct sensor_driver_funcs {
+struct sensor_driver {
     sensor_get_interface_func_t sd_get_interface;
     sensor_read_func_t sd_read;
     sensor_get_config_func_t sd_get_config;
 };
 
+/*
+ * Return the OS device structure corresponding to this sensor
+ */
+#define SENSOR_GET_DEVICE(__s) ((__s)->s_dev)
+
 struct sensor {
     /* The OS device this sensor inherits from, this is typically a sensor specific
      * driver.
@@ -220,7 +235,7 @@ struct sensor {
 
     /* Sensor driver specific functions, created by the device registering the sensor.
      */
-    const struct sensor_driver_funcs s_funcs;
+    struct sensor_driver *s_funcs;
     /* A list of listeners that are registered to receive data off of this sensor
      */
     SLIST_HEAD(, sensor_listener) s_listener_list;
@@ -235,6 +250,25 @@ int sensor_register_listener(struct sensor *, struct sensor_listener *);
 int sensor_read(struct sensor *, sensor_type_t, sensor_data_func_t, void *,
         uint32_t);
 
+/**
+ * Set the driver functions for this sensor, along with the type of sensor
+ * data available for the given sensor.
+ *
+ * @param The sensor to set the driver information for
+ * @param The types of sensor data available for this sensor
+ * @param The driver functions for this sensor
+ *
+ * @return 0 on success, non-zero error code on failure
+ */
+static inline int
+sensor_set_driver(struct sensor *sensor, sensor_type_t type,
+        struct sensor_driver *driver)
+{
+    sensor->s_funcs = driver;
+    sensor->s_types = type;
+
+    return (0);
+}
 
 /**
  * Read the configuration for the sensor type "type," and return the
@@ -250,7 +284,7 @@ static inline int
 sensor_get_config(struct sensor *sensor, sensor_type_t type,
         struct sensor_cfg *cfg)
 {
-    return (sensor->s_funcs.sd_get_config(sensor, type, cfg));
+    return (sensor->s_funcs->sd_get_config(sensor, type, cfg));
 }
 
 /**
@@ -265,7 +299,7 @@ sensor_get_config(struct sensor *sensor, sensor_type_t type,
 static inline void *
 sensor_get_interface(struct sensor *sensor, sensor_type_t type)
 {
-    return (sensor->s_funcs.sd_get_interface(sensor, type));
+    return (sensor->s_funcs->sd_get_interface(sensor, type));
 }
 
 /**
@@ -280,8 +314,11 @@ sensor_get_interface(struct sensor *sensor, sensor_type_t type)
 #define SENSOR_MGR_WAKEUP_TICKS (MYNEWT_VAL(SENSOR_MGR_WAKEUP_RATE) * \
         (OS_TICKS_PER_SEC / 1000))
 
+int sensor_mgr_lock(void);
+void sensor_mgr_unlock(void);
 int sensor_mgr_register(struct sensor *);
 
+
 typedef int (*sensor_mgr_compare_func_t)(struct sensor *, void *);
 struct sensor *sensor_mgr_find_next(sensor_mgr_compare_func_t, void *,
         struct sensor *);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c44ff1f4/hw/sensor/pkg.yml
----------------------------------------------------------------------
diff --git a/hw/sensor/pkg.yml b/hw/sensor/pkg.yml
index 2274252..decf1c9 100644
--- a/hw/sensor/pkg.yml
+++ b/hw/sensor/pkg.yml
@@ -22,8 +22,4 @@ pkg.description: Sensor Interface
 pkg.author: "Apache Mynewt <de...@mynewt.incubator.apache.org>"
 pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
-pkg.req_apis:
-    - SENSOR_HW_IMPL
 
-pkg.init_function: sensor_pkg_init
-pkg.init_stage: 0

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c44ff1f4/hw/sensor/src/sensor.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor.c b/hw/sensor/src/sensor.c
index 95fb9ab..319de12 100644
--- a/hw/sensor/src/sensor.c
+++ b/hw/sensor/src/sensor.c
@@ -26,15 +26,18 @@
 
 #include "sensor/sensor.h"
 
+#include "sensor_priv.h"
+
 struct {
     struct os_mutex mgr_lock;
 
     struct os_callout mgr_wakeup_callout;
+    struct os_eventq *mgr_eventq;
 
     TAILQ_HEAD(, sensor) mgr_sensor_list;
 } sensor_mgr;
 
-static int
+int
 sensor_mgr_lock(void)
 {
     int rc;
@@ -46,7 +49,7 @@ sensor_mgr_lock(void)
     return (rc);
 }
 
-static void
+void
 sensor_mgr_unlock(void)
 {
     (void) os_mutex_release(&sensor_mgr.mgr_lock);
@@ -214,10 +217,10 @@ done:
 static struct os_eventq *
 sensor_mgr_evq_get(void)
 {
-    /* XXX: FIll me in */
-    return (NULL);
-}
+    os_eventq_ensure(&sensor_mgr.mgr_eventq, NULL);
 
+    return (sensor_mgr.mgr_eventq);
+}
 
 static void
 sensor_mgr_init(void)
@@ -235,7 +238,26 @@ sensor_mgr_init(void)
     os_mutex_init(&sensor_mgr.mgr_lock);
 }
 
-
+/**
+ * The sensor manager contains a list of sensors, this function returns
+ * the next sensor in that list, for which compare_func() returns successful
+ * (one).  If prev_cursor is provided, the function starts at that point
+ * in the sensor list.
+ *
+ * @warn This function MUST be locked by sensor_mgr_lock/unlock() if the goal is
+ * to iterate through sensors (as opposed to just finding one.)  As the
+ * "prev_cursor" may be resorted in the sensor list, in between calls.
+ *
+ * @param The comparison function to use against sensors in the list.
+ * @param The argument to provide to that comparison function
+ * @param The previous sensor in the sensor manager list, in case of
+ *        iteration.  If desire is to find first matching sensor, provide a
+ *        NULL value.
+ *
+ * @return A pointer to the first sensor found from prev_cursor, or
+ *         NULL, if none found.
+ *
+ */
 struct sensor *
 sensor_mgr_find_next(sensor_mgr_compare_func_t compare_func, void *arg,
         struct sensor *prev_cursor)
@@ -254,12 +276,15 @@ sensor_mgr_find_next(sensor_mgr_compare_func_t compare_func, void *arg,
     cursor = prev_cursor;
     if (cursor == NULL) {
         cursor = TAILQ_FIRST(&sensor_mgr.mgr_sensor_list);
+    } else {
+        cursor = TAILQ_NEXT(prev_cursor, s_next);
     }
 
     while (cursor != NULL) {
         if (compare_func(cursor, arg)) {
             break;
         }
+        cursor = TAILQ_NEXT(cursor, s_next);
     }
 
     sensor_mgr_unlock();
@@ -269,6 +294,7 @@ done:
 }
 
 
+
 static int
 sensor_mgr_match_bytype(struct sensor *sensor, void *arg)
 {
@@ -276,6 +302,10 @@ sensor_mgr_match_bytype(struct sensor *sensor, void *arg)
 
     type = (sensor_type_t *) arg;
 
+    /* s_types is a bitmask that contains the supported sensor types for this
+     * sensor, and type is the bitmask we're searching for.  Compare the two,
+     * and if there is a match, return true (1).
+     */
     if ((*type & sensor->s_types) != 0) {
         return (1);
     } else {
@@ -340,10 +370,17 @@ sensor_mgr_find_next_bydevname(char *devname, struct sensor *prev_cursor)
 void
 sensor_pkg_init(void)
 {
+    /* Call directly until sysinit has the right hooks for us */
+#if 0
     /* Ensure this is only called by sysinit */
     SYSINIT_ASSERT_ACTIVE();
+#endif
 
     sensor_mgr_init();
+
+#if MYNEWT_VAL(SENSOR_CLI)
+    sensor_shell_register();
+#endif
 }
 
 
@@ -405,7 +442,6 @@ err:
 }
 
 
-
 /**
  * Register a sensor listener.  This allows a calling application to receive
  * callbacks for data from a given sensor object.
@@ -490,7 +526,7 @@ sensor_read(struct sensor *sensor, sensor_type_t type,
     src.user_func = data_func;
     src.user_arg = arg;
 
-    rc = sensor->s_funcs.sd_read(sensor, type, sensor_read_data_func, &src,
+    rc = sensor->s_funcs->sd_read(sensor, type, sensor_read_data_func, &src,
             timeout);
 
     sensor_unlock(sensor);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c44ff1f4/hw/sensor/src/sensor_priv.h
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_priv.h b/hw/sensor/src/sensor_priv.h
new file mode 100644
index 0000000..a15aa22
--- /dev/null
+++ b/hw/sensor/src/sensor_priv.h
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef __SENSOR_PRIV_H__
+#define __SENSOR_PRIV_H__
+
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(SENSOR_CLI)
+int sensor_shell_register(void);
+#endif
+
+#endif /* __SENSOR_PRIV_H__ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c44ff1f4/hw/sensor/src/sensor_shell.c
----------------------------------------------------------------------
diff --git a/hw/sensor/src/sensor_shell.c b/hw/sensor/src/sensor_shell.c
new file mode 100644
index 0000000..6c8b7ac
--- /dev/null
+++ b/hw/sensor/src/sensor_shell.c
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "syscfg/syscfg.h"
+
+#if MYNEWT_VAL(SENSOR_CLI)
+
+#include <string.h>
+#include <errno.h>
+#include <assert.h>
+
+#include "defs/error.h"
+
+#include "os/os.h"
+
+#include "sensor/sensor.h"
+#include "console/console.h"
+#include "shell/shell.h"
+
+static int sensor_cmd_exec(int, char **);
+static const struct shell_cmd shell_sensor_cmd = {
+    .sc_cmd = "sensor",
+    .sc_cmd_func = sensor_cmd_exec
+};
+
+static void
+sensor_display_help(void)
+{
+    console_printf("Possible commands for sensor are:\n");
+    console_printf("  list\n");
+}
+
+static void
+sensor_cmd_display_sensor(struct sensor *sensor)
+{
+    console_printf("sensor dev = %s, type = %lld\n", sensor->s_dev->od_name,
+            sensor->s_types);
+}
+
+static void
+sensor_cmd_list_sensors(void)
+{
+    struct sensor *sensor;
+
+    sensor = NULL;
+
+    sensor_mgr_lock();
+
+    while (1) {
+        sensor = sensor_mgr_find_next_bytype(SENSOR_TYPE_ALL, sensor);
+        if (sensor == NULL) {
+            break;
+        }
+
+        sensor_cmd_display_sensor(sensor);
+    }
+
+    sensor_mgr_unlock();
+}
+
+
+static int
+sensor_cmd_exec(int argc, char **argv)
+{
+    char *subcmd;
+    int rc;
+
+    if (argc <= 1) {
+        sensor_display_help();
+        rc = 0;
+        goto done;
+    }
+
+    subcmd = argv[1];
+    if (!strcmp(subcmd, "list")) {
+        sensor_cmd_list_sensors();
+    } else {
+        console_printf("Unknown sensor command %s\n", subcmd);
+        rc = SYS_EINVAL;
+        goto err;
+    }
+
+done:
+    return (0);
+err:
+    return (rc);
+}
+
+
+int
+sensor_shell_register(void)
+{
+    shell_cmd_register((struct shell_cmd *) &shell_sensor_cmd);
+
+    return (0);
+}
+
+#endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/c44ff1f4/hw/sensor/syscfg.yml
----------------------------------------------------------------------
diff --git a/hw/sensor/syscfg.yml b/hw/sensor/syscfg.yml
index b3dc9bb..0826cc9 100644
--- a/hw/sensor/syscfg.yml
+++ b/hw/sensor/syscfg.yml
@@ -22,3 +22,7 @@ syscfg.defs:
     SENSOR_MGR_WAKEUP_RATE:
         description: 'The default wakeup rate of the sensor manager'
         value: 1000
+
+    SENSOR_CLI:
+        description: 'Whether or not to enable the sensor shell support'
+        value: 1