diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index 1bc143b929..74e5db9d5e 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 8e1f8c3289..2b4e4ea4d6 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 56c7eeadcb..63546af435 100644 --- a/include/nuttx/sensors/sensor.h +++ b/include/nuttx/sensors/sensor.h @@ -541,6 +541,28 @@ struct sensor_ops_s CODE int (*fetch)(FAR struct sensor_lowerhalf_s *lower, 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 *