driver/sensor: support sensor_ops: selftest

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2021-09-27 20:16:15 +08:00 committed by Alan Carvalho de Assis
parent c58fddb915
commit 5ee16ee684
3 changed files with 43 additions and 0 deletions

View File

@ -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;

View File

@ -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 */

View File

@ -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
*