You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/07/25 13:24:56 UTC

[GitHub] [incubator-nuttx] Donny9 opened a new pull request, #6704: driver/sensors[1]: enhance sensor driver

Donny9 opened a new pull request, #6704:
URL: https://github.com/apache/incubator-nuttx/pull/6704

   ## Summary
   1. support users to write data to sensor device.
   2. simplify buffer operation and some structure update.
   3. support multi users to access sensor device.
   ## Impact
   This PR is a part of https://github.com/apache/incubator-nuttx/pull/6653.
   ## Testing
   Vela CI
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] zouboan commented on pull request #6704: driver/sensors[1]: enhance sensor driver

Posted by "zouboan (via GitHub)" <gi...@apache.org>.
zouboan commented on PR #6704:
URL: https://github.com/apache/nuttx/pull/6704#issuecomment-1461991273

   Thanks so much for your explanation! I think i misread the role of `usensor`, I thought the `usensor `is used for sensors(e.g. mpu60x0) that didn't registered under the `sensor.c` in the nuttx, and when we use uorb on these sensors(e.g. mpu60x0), we register it under `sensor.c` by `usensor`. 
   BTW, it seems that only the sensor registered by `int sensor_register(FAR struct sensor_lowerhalf_s *lower, int devno)` can be used in uORB, but there's only ds18b20,bmp280,hyt271,l3gd20,lsm303agr,lsm6dsl,ltr308,ms5611,msa301,wtgahrs2 is registered by `sensor_register`, does it means most of other sensor driver registered in traditional way(e.g. mpu60x0) cannot be used in uORB method at present?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on pull request #6704: driver/sensors[1]: enhance sensor driver

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #6704:
URL: https://github.com/apache/nuttx/pull/6704#issuecomment-1460758490

   For usensor case, the data is provided by orb publisher and consumed by orb subscriber. The sensor upper half does all required functionality(FIFO, file operation etc), that's why the sensor lower half is empty.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] zouboan commented on pull request #6704: driver/sensors[1]: enhance sensor driver

Posted by "zouboan (via GitHub)" <gi...@apache.org>.
zouboan commented on PR #6704:
URL: https://github.com/apache/nuttx/pull/6704#issuecomment-1463848762

   got it, Thank you for your reply


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] zouboan commented on pull request #6704: driver/sensors[1]: enhance sensor driver

Posted by "zouboan (via GitHub)" <gi...@apache.org>.
zouboan commented on PR #6704:
URL: https://github.com/apache/nuttx/pull/6704#issuecomment-1458356230

   Hello:
      I'm very interested in NuttX's native uORB, but there's some question puzzled me. when uORB register a customer sensor by `ioctl` of usensor:
   https://github.com/apache/nuttx-apps/blob/master/system/uorb/uORB/uORB.c#L85
   usensor will call `sensor_custom_register` to register a new sensor, and the `file_operations` of new sensor is given by `lower->driver.ops = &g_usensor_ops;`
   https://github.com/apache/nuttx/blob/master/drivers/sensors/usensor.c#L113-L115
   what puzzled me is that the `g_usensor_ops` is actually `NULL`, and there's no assignment for `g_usensor_ops` In usensor.c or `lower->ops` in sensor.c. so, how can the new sensor's file_operations working?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] pkarashchenko commented on a diff in pull request #6704: driver/sensors[1]: enhance sensor driver

Posted by "pkarashchenko (via GitHub)" <gi...@apache.org>.
pkarashchenko commented on code in PR #6704:
URL: https://github.com/apache/nuttx/pull/6704#discussion_r929754337


##########
drivers/sensors/usensor.c:
##########
@@ -0,0 +1,249 @@
+/****************************************************************************
+ * drivers/sensors/usensor.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/list.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/sensors/sensor.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define USENSOR_PATH       "/dev/usensor"
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int usensor_open(FAR struct file *filep);
+static int usensor_close(FAR struct file *filep);
+static ssize_t usensor_read(FAR struct file *filep, FAR char *buffer,
+                            size_t buflen);
+static ssize_t usensor_write(FAR struct file *filep, FAR const char *buffer,
+                             size_t buflen);
+static int usensor_ioctl(FAR struct file *filep, int cmd,
+                         unsigned long arg);
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure describes context of usensor */
+
+struct usensor_context_s
+{
+  sem_t            exclsem;   /* Manages exclusive access to file operations */
+  struct list_node list;      /* List of node registered */
+};
+
+/* This structure describes lowerhalf driver for an usensor registered */
+
+struct usensor_lowerhalf_s
+{
+  struct list_node          node;    /* node in all usensor list */
+  struct sensor_lowerhalf_s driver;  /* The lowerhalf driver of user sensor */
+  char                      path[1]; /* The path of usensor character device */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_usensor_fops =
+{
+  usensor_open,  /* open  */
+  usensor_close, /* close */
+  usensor_read,  /* read  */
+  usensor_write, /* write */
+  NULL,          /* seek  */
+  usensor_ioctl, /* ioctl */
+  NULL,          /* poll  */
+};
+
+static const struct sensor_ops_s g_usensor_ops =
+{
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int usensor_register(FAR struct usensor_context_s *usensor,
+                            FAR const struct sensor_reginfo_s *info)
+{
+  FAR struct usensor_lowerhalf_s *lower;
+  int ret;
+
+  lower = kmm_zalloc(sizeof(*lower) + strlen(info->path));
+  if (!lower)
+    {
+      return -ENOMEM;
+    }
+
+  lower->driver.nbuffer = info->nbuffer;
+  lower->driver.ops = &g_usensor_ops;
+  strcpy(lower->path, info->path);
+  ret = sensor_custom_register(&lower->driver, lower->path, info->esize);
+  if (ret < 0)
+    {
+      goto errout_with_lower;
+    }
+
+  ret = nxsem_wait(&usensor->exclsem);
+  if (ret < 0)
+    {
+      goto errout_with_register;
+    }
+
+  list_add_tail(&usensor->list, &lower->node);
+  nxsem_post(&usensor->exclsem);
+
+  return ret;
+
+errout_with_register:
+  sensor_custom_unregister(&lower->driver, info->path);
+errout_with_lower:
+  kmm_free(lower);
+  return ret;
+}
+
+static int usensor_unregister(FAR struct usensor_context_s *usensor,
+                              FAR const char *path)
+{
+  FAR struct usensor_lowerhalf_s *lower;
+  int ret;
+
+  ret = nxsem_wait(&usensor->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  list_for_every_entry(&usensor->list, lower, struct usensor_lowerhalf_s,
+                       node)
+    {
+      if (strcmp(path, lower->path) == 0)
+        {
+          list_delete(&lower->node);
+          nxsem_post(&usensor->exclsem);
+          sensor_custom_unregister(&lower->driver, path);
+          kmm_free(lower);
+          return 0;
+        }
+    }
+
+  nxsem_post(&usensor->exclsem);
+  return -ENOENT;
+}
+
+static int usensor_open(FAR struct file *filep)
+{
+  return 0;
+}
+
+static int usensor_close(FAR struct file *filep)
+{
+  return 0;
+}
+
+static ssize_t usensor_write(FAR struct file *filep, FAR const char *buffer,
+                             size_t buflen)
+{
+  return buflen;
+}
+
+static ssize_t usensor_read(FAR struct file *filep, FAR char *buffer,
+                            size_t buflen)
+{
+  return buflen;

Review Comment:
   I think `0` should be returned instead



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 merged pull request #6704: driver/sensors[1]: enhance sensor driver

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #6704:
URL: https://github.com/apache/incubator-nuttx/pull/6704


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #6704: driver/sensors[1]: enhance sensor driver

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #6704:
URL: https://github.com/apache/incubator-nuttx/pull/6704#discussion_r929754066


##########
drivers/sensors/usensor.c:
##########
@@ -0,0 +1,249 @@
+/****************************************************************************
+ * drivers/sensors/usensor.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/list.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/sensors/sensor.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define USENSOR_PATH       "/dev/usensor"
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int usensor_open(FAR struct file *filep);
+static int usensor_close(FAR struct file *filep);
+static ssize_t usensor_read(FAR struct file *filep, FAR char *buffer,
+                            size_t buflen);
+static ssize_t usensor_write(FAR struct file *filep, FAR const char *buffer,
+                             size_t buflen);
+static int usensor_ioctl(FAR struct file *filep, int cmd,
+                         unsigned long arg);
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure describes context of usensor */
+
+struct usensor_context_s
+{
+  sem_t            exclsem;   /* Manages exclusive access to file operations */
+  struct list_node list;      /* List of node registered */
+};
+
+/* This structure describes lowerhalf driver for an usensor registered */
+
+struct usensor_lowerhalf_s
+{
+  struct list_node          node;    /* node in all usensor list */
+  struct sensor_lowerhalf_s driver;  /* The lowerhalf driver of user sensor */
+  char                      path[1]; /* The path of usensor character device */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_usensor_fops =
+{
+  usensor_open,  /* open  */
+  usensor_close, /* close */
+  usensor_read,  /* read  */
+  usensor_write, /* write */
+  NULL,          /* seek  */
+  usensor_ioctl, /* ioctl */
+  NULL,          /* poll  */
+};
+
+static const struct sensor_ops_s g_usensor_ops =
+{
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int usensor_register(FAR struct usensor_context_s *usensor,
+                            FAR const struct sensor_reginfo_s *info)
+{
+  FAR struct usensor_lowerhalf_s *lower;
+  int ret;
+
+  lower = kmm_zalloc(sizeof(*lower) + strlen(info->path));
+  if (!lower)
+    {
+      return -ENOMEM;
+    }
+
+  lower->driver.nbuffer = info->nbuffer;
+  lower->driver.ops = &g_usensor_ops;
+  strcpy(lower->path, info->path);
+  ret = sensor_custom_register(&lower->driver, lower->path, info->esize);
+  if (ret < 0)
+    {
+      goto errout_with_lower;
+    }
+
+  ret = nxsem_wait(&usensor->exclsem);
+  if (ret < 0)
+    {
+      goto errout_with_register;
+    }
+
+  list_add_tail(&usensor->list, &lower->node);
+  nxsem_post(&usensor->exclsem);
+
+  return ret;
+
+errout_with_register:
+  sensor_custom_unregister(&lower->driver, info->path);
+errout_with_lower:
+  kmm_free(lower);
+  return ret;
+}
+
+static int usensor_unregister(FAR struct usensor_context_s *usensor,
+                              FAR const char *path)
+{
+  FAR struct usensor_lowerhalf_s *lower;
+  int ret;
+
+  ret = nxsem_wait(&usensor->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  list_for_every_entry(&usensor->list, lower, struct usensor_lowerhalf_s,
+                       node)
+    {
+      if (strcmp(path, lower->path) == 0)
+        {
+          list_delete(&lower->node);
+          nxsem_post(&usensor->exclsem);
+          sensor_custom_unregister(&lower->driver, path);
+          kmm_free(lower);
+          return 0;
+        }
+    }
+
+  nxsem_post(&usensor->exclsem);
+  return -ENOENT;
+}
+
+static int usensor_open(FAR struct file *filep)
+{
+  return 0;
+}
+
+static int usensor_close(FAR struct file *filep)
+{
+  return 0;
+}

Review Comment:
   I think those are not needed



##########
drivers/sensors/usensor.c:
##########
@@ -0,0 +1,249 @@
+/****************************************************************************
+ * drivers/sensors/usensor.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/list.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/sensors/sensor.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define USENSOR_PATH       "/dev/usensor"
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int usensor_open(FAR struct file *filep);
+static int usensor_close(FAR struct file *filep);
+static ssize_t usensor_read(FAR struct file *filep, FAR char *buffer,
+                            size_t buflen);
+static ssize_t usensor_write(FAR struct file *filep, FAR const char *buffer,
+                             size_t buflen);
+static int usensor_ioctl(FAR struct file *filep, int cmd,
+                         unsigned long arg);
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* This structure describes context of usensor */
+
+struct usensor_context_s
+{
+  sem_t            exclsem;   /* Manages exclusive access to file operations */
+  struct list_node list;      /* List of node registered */
+};
+
+/* This structure describes lowerhalf driver for an usensor registered */
+
+struct usensor_lowerhalf_s
+{
+  struct list_node          node;    /* node in all usensor list */
+  struct sensor_lowerhalf_s driver;  /* The lowerhalf driver of user sensor */
+  char                      path[1]; /* The path of usensor character device */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations g_usensor_fops =
+{
+  usensor_open,  /* open  */
+  usensor_close, /* close */
+  usensor_read,  /* read  */
+  usensor_write, /* write */
+  NULL,          /* seek  */
+  usensor_ioctl, /* ioctl */
+  NULL,          /* poll  */
+};
+
+static const struct sensor_ops_s g_usensor_ops =
+{
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int usensor_register(FAR struct usensor_context_s *usensor,
+                            FAR const struct sensor_reginfo_s *info)
+{
+  FAR struct usensor_lowerhalf_s *lower;
+  int ret;
+
+  lower = kmm_zalloc(sizeof(*lower) + strlen(info->path));
+  if (!lower)
+    {
+      return -ENOMEM;
+    }
+
+  lower->driver.nbuffer = info->nbuffer;
+  lower->driver.ops = &g_usensor_ops;
+  strcpy(lower->path, info->path);
+  ret = sensor_custom_register(&lower->driver, lower->path, info->esize);
+  if (ret < 0)
+    {
+      goto errout_with_lower;
+    }
+
+  ret = nxsem_wait(&usensor->exclsem);
+  if (ret < 0)
+    {
+      goto errout_with_register;
+    }
+
+  list_add_tail(&usensor->list, &lower->node);
+  nxsem_post(&usensor->exclsem);
+
+  return ret;
+
+errout_with_register:
+  sensor_custom_unregister(&lower->driver, info->path);
+errout_with_lower:
+  kmm_free(lower);
+  return ret;
+}
+
+static int usensor_unregister(FAR struct usensor_context_s *usensor,
+                              FAR const char *path)
+{
+  FAR struct usensor_lowerhalf_s *lower;
+  int ret;
+
+  ret = nxsem_wait(&usensor->exclsem);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  list_for_every_entry(&usensor->list, lower, struct usensor_lowerhalf_s,
+                       node)
+    {
+      if (strcmp(path, lower->path) == 0)
+        {
+          list_delete(&lower->node);
+          nxsem_post(&usensor->exclsem);
+          sensor_custom_unregister(&lower->driver, path);
+          kmm_free(lower);
+          return 0;
+        }
+    }
+
+  nxsem_post(&usensor->exclsem);
+  return -ENOENT;
+}
+
+static int usensor_open(FAR struct file *filep)
+{
+  return 0;
+}
+
+static int usensor_close(FAR struct file *filep)
+{
+  return 0;
+}
+
+static ssize_t usensor_write(FAR struct file *filep, FAR const char *buffer,
+                             size_t buflen)
+{
+  return buflen;
+}
+
+static ssize_t usensor_read(FAR struct file *filep, FAR char *buffer,
+                            size_t buflen)
+{
+  return buflen;

Review Comment:
   I think `0` should be returned in stead



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #6704: driver/sensors[1]: enhance sensor driver

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #6704:
URL: https://github.com/apache/incubator-nuttx/pull/6704#issuecomment-1194413353

   @acassis this PR depends on sensortest change https://github.com/apache/incubator-nuttx-apps/pull/1228.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nuttx] xiaoxiang781216 commented on pull request #6704: driver/sensors[1]: enhance sensor driver

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #6704:
URL: https://github.com/apache/nuttx/pull/6704#issuecomment-1462367310

   Yes, the old sensor developed before the new sensor driver framework need rewrite to integrate with uORB.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org