This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 5ee16ee driver/sensor: support sensor_ops: selftest
5ee16ee is described below
commit 5ee16ee6847667a1651ab54376aa115daad1f241
Author: Jiuzhu Dong <[email protected]>
AuthorDate: Mon Sep 27 20:16:15 2021 +0800
driver/sensor: support sensor_ops: selftest
Signed-off-by: Jiuzhu Dong <[email protected]>
---
drivers/sensors/sensor.c | 12 ++++++++++++
include/nuttx/sensors/ioctl.h | 9 +++++++++
include/nuttx/sensors/sensor.h | 22 ++++++++++++++++++++++
3 files changed, 43 insertions(+)
diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c
index 1bc143b..74e5db9 100644
--- a/drivers/sensors/sensor.c
+++ b/drivers/sensors/sensor.c
@@ -428,6 +428,18 @@ static int sensor_ioctl(FAR struct file *filep, int cmd,
unsigned long arg)
}
break;
+ case SNIOC_SELFTEST:
+ {
+ if (lower->ops->selftest == NULL)
+ {
+ ret = -ENOTSUP;
+ break;
+ }
+
+ ret = lower->ops->selftest(lower, arg);
+ }
+ break;
+
case SNIOC_GET_NEVENTBUF:
{
*val = lower->buffer_number + lower->batch_number;
diff --git a/include/nuttx/sensors/ioctl.h b/include/nuttx/sensors/ioctl.h
index 8e1f8c3..2b4e4ea 100644
--- a/include/nuttx/sensors/ioctl.h
+++ b/include/nuttx/sensors/ioctl.h
@@ -288,4 +288,13 @@
#define SNIOC_GET_POSITION _SNIOC(0x0085)
+/* Command: SNIOC_SELFTEST
+ * Description: Take a selftest for sensor.
+ * Argument: A argument of selftest for sensor.
+ * Note: If selftest is failed, return errno, otherwise, return OK.
+ * This cmd is handled by sensor_ops_s::selftest.
+ */
+
+#define SNIOC_SELFTEST _SNIOC(0x0086)
+
#endif /* __INCLUDE_NUTTX_SENSORS_IOCTL_H */
diff --git a/include/nuttx/sensors/sensor.h b/include/nuttx/sensors/sensor.h
index 56c7eea..63546af 100644
--- a/include/nuttx/sensors/sensor.h
+++ b/include/nuttx/sensors/sensor.h
@@ -542,6 +542,28 @@ struct sensor_ops_s
FAR char *buffer, size_t buflen);
/**************************************************************************
+ * Name: selftest
+ *
+ * Selftest allows for the testing of the mechanical and electrical
+ * portions of the sensors. When the selftest is activated, the
+ * electronics cause the sensors to be actuated and produce an output
+ * signal. The output signal is used to observe the selftest response.
+ * When the selftest response exceeds the min/max values,
+ * the part is deemed to have failed selftest.
+ *
+ * Input Parameters:
+ * lower - The instance of lower half sensor driver.
+ * arg - The parameters associated with selftest.
+ *
+ * Returned Value:
+ * Zero (OK) on success; a negated errno value on failure.
+ *
+ **************************************************************************/
+
+ CODE int (*selftest)(FAR struct sensor_lowerhalf_s *lower,
+ unsigned long arg);
+
+ /**************************************************************************
* Name: control
*
* With this method, the user can set some special config for the sensor,