From 71bb4e8a0da65fdc3059a958cd92021bd283a4bb Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Tue, 29 Mar 2022 11:39:44 +0800 Subject: [PATCH 1/4] driver/sensor: add name prefix "sensor_" for sensor register Signed-off-by: Jiuzhu Dong --- drivers/sensors/sensor.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index c1587c7f3f777..c6001dbf9c399 100644 --- a/drivers/sensors/sensor.c +++ b/drivers/sensors/sensor.c @@ -46,8 +46,7 @@ /* Device naming ************************************************************/ #define ROUNDUP(x, esize) ((x + (esize - 1)) / (esize)) * (esize) -#define DEVNAME_FMT "/dev/sensor/%s%s%d" -#define DEVNAME_MAX 64 +#define DEVNAME_FMT "/dev/sensor/sensor_%s%s%d" #define DEVNAME_UNCAL "_uncal" /**************************************************************************** @@ -880,11 +879,11 @@ static void sensor_notify_event(FAR void *priv) int sensor_register(FAR struct sensor_lowerhalf_s *lower, int devno) { - char path[DEVNAME_MAX]; + char path[PATH_MAX]; DEBUGASSERT(lower != NULL); - snprintf(path, DEVNAME_MAX, DEVNAME_FMT, + snprintf(path, PATH_MAX, DEVNAME_FMT, g_sensor_info[lower->type].name, lower->uncalibrated ? DEVNAME_UNCAL : "", devno); @@ -1007,9 +1006,9 @@ int sensor_custom_register(FAR struct sensor_lowerhalf_s *lower, void sensor_unregister(FAR struct sensor_lowerhalf_s *lower, int devno) { - char path[DEVNAME_MAX]; + char path[PATH_MAX]; - snprintf(path, DEVNAME_MAX, DEVNAME_FMT, + snprintf(path, PATH_MAX, DEVNAME_FMT, g_sensor_info[lower->type].name, lower->uncalibrated ? DEVNAME_UNCAL : "", devno); From ce74f197adea66c64effd03d5a072f0639c063a6 Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Wed, 13 Apr 2022 14:00:08 +0800 Subject: [PATCH 2/4] driver/sensors: add open/close api and struct file for sensor_ops Signed-off-by: Jiuzhu Dong --- drivers/sensors/sensor.c | 59 +++++++++++++++++++++++--------- include/nuttx/sensors/sensor.h | 61 +++++++++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 17 deletions(-) diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index c6001dbf9c399..25431ae489cfc 100644 --- a/drivers/sensors/sensor.c +++ b/drivers/sensors/sensor.c @@ -196,7 +196,8 @@ static bool sensor_is_updated(unsigned long generation, return generation > ugeneration; } -static int sensor_update_interval(FAR struct sensor_upperhalf_s *upper, +static int sensor_update_interval(FAR struct file *filep, + FAR struct sensor_upperhalf_s *upper, FAR struct sensor_user_s *user, unsigned long interval) { @@ -237,7 +238,7 @@ static int sensor_update_interval(FAR struct sensor_upperhalf_s *upper, if (min_interval != ULONG_MAX && lower->ops->set_interval) { - ret = lower->ops->set_interval(lower, &min_interval); + ret = lower->ops->set_interval(lower, filep, &min_interval); if (ret < 0) { return ret; @@ -250,7 +251,8 @@ static int sensor_update_interval(FAR struct sensor_upperhalf_s *upper, return ret; } -static int sensor_update_latency(FAR struct sensor_upperhalf_s *upper, +static int sensor_update_latency(FAR struct file *filep, + FAR struct sensor_upperhalf_s *upper, FAR struct sensor_user_s *user, unsigned long latency) { @@ -296,7 +298,7 @@ static int sensor_update_latency(FAR struct sensor_upperhalf_s *upper, if (min_latency != ULONG_MAX && lower->ops->batch) { - ret = lower->ops->batch(lower, &min_latency); + ret = lower->ops->batch(lower, filep, &min_latency); if (ret < 0) { return ret; @@ -368,14 +370,23 @@ static int sensor_open(FAR struct file *filep) goto errout_with_sem; } + if (lower->ops->open) + { + ret = lower->ops->open(lower, filep); + if (ret < 0) + { + goto errout_with_user; + } + } + if (filep->f_oflags & O_RDOK) { if (upper->state.nsubscribers == 0 && lower->ops->activate) { - ret = lower->ops->activate(lower, true); + ret = lower->ops->activate(lower, filep, true); if (ret < 0) { - goto errout_with_user; + goto errout_with_open; } } @@ -401,6 +412,12 @@ static int sensor_open(FAR struct file *filep) filep->f_priv = user; goto errout_with_sem; +errout_with_open: + if (lower->ops->close) + { + lower->ops->close(lower, filep); + } + errout_with_user: kmm_free(user); errout_with_sem: @@ -422,12 +439,22 @@ static int sensor_close(FAR struct file *filep) return ret; } + if (lower->ops->close) + { + ret = lower->ops->close(lower, filep); + if (ret < 0) + { + nxsem_post(&upper->exclsem); + return ret; + } + } + if (filep->f_oflags & O_RDOK) { upper->state.nsubscribers--; if (upper->state.nsubscribers == 0 && lower->ops->activate) { - lower->ops->activate(lower, false); + lower->ops->activate(lower, filep, false); } } @@ -437,8 +464,8 @@ static int sensor_close(FAR struct file *filep) } list_delete(&user->node); - sensor_update_latency(upper, user, ULONG_MAX); - sensor_update_interval(upper, user, ULONG_MAX); + sensor_update_latency(filep, upper, user, ULONG_MAX); + sensor_update_interval(filep, upper, user, ULONG_MAX); nxsem_destroy(&user->buffersem); /* The user is closed, notify to other users */ @@ -494,7 +521,7 @@ static ssize_t sensor_read(FAR struct file *filep, FAR char *buffer, goto out; } - ret = lower->ops->fetch(lower, buffer, len); + ret = lower->ops->fetch(lower, filep, buffer, len); } else { @@ -604,13 +631,13 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case SNIOC_SET_INTERVAL: { - ret = sensor_update_interval(upper, user, arg); + ret = sensor_update_interval(filep, upper, user, arg); } break; case SNIOC_BATCH: { - ret = sensor_update_latency(upper, user, arg); + ret = sensor_update_latency(filep, upper, user, arg); } break; @@ -622,7 +649,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg) break; } - ret = lower->ops->selftest(lower, arg); + ret = lower->ops->selftest(lower, filep, arg); } break; @@ -634,7 +661,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg) break; } - ret = lower->ops->set_calibvalue(lower, arg); + ret = lower->ops->set_calibvalue(lower, filep, arg); } break; @@ -646,7 +673,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg) break; } - ret = lower->ops->calibrate(lower, arg); + ret = lower->ops->calibrate(lower, filep, arg); } break; @@ -682,7 +709,7 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg) if (lower->ops->control) { - ret = lower->ops->control(lower, cmd, arg); + ret = lower->ops->control(lower, filep, cmd, arg); } else { diff --git a/include/nuttx/sensors/sensor.h b/include/nuttx/sensors/sensor.h index 9be32a32689bd..a9ef796eb7657 100644 --- a/include/nuttx/sensors/sensor.h +++ b/include/nuttx/sensors/sensor.h @@ -32,6 +32,7 @@ #include #include +#include #include /**************************************************************************** @@ -584,6 +585,48 @@ struct sensor_cap /* Type: Capacitance */ struct sensor_lowerhalf_s; struct sensor_ops_s { + /************************************************************************** + * Name: open + * + * Description: + * The open method differs from the activate method with true because + * it's called and turned off every times, and it receives the pointer + * of file and the instance of lowerhalf sensor driver. It uses to do + * something about initialize for every user. + * + * Input Parameters: + * lower - The instance of lower half sensor driver + * filep - The pointer of file, represents each user using the sensor + * + * Returned Value: + * Zero (OK) or positive on success; a negated errno value on failure. + * + **************************************************************************/ + + CODE int (*open)(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep); + + /************************************************************************** + * Name: close + * + * Description: + * The close method differs from the activate method with false because + * it's called and turned off every times, and it receives the pointer + * of file and the instance of lowerhalf sensor driver. It uses to do + * something about uninitialize for every user. + * + * Input Parameters: + * lower - The instance of lower half sensor driver. + * filep - The pointer of file, represents each user using the sensor. + * + * Returned Value: + * Zero (OK) or positive on success; a negated errno value on failure. + * + **************************************************************************/ + + CODE int (*close)(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep); + /************************************************************************** * Name: activate * @@ -594,6 +637,7 @@ struct sensor_ops_s * * Input Parameters: * lower - The instance of lower half sensor driver + * filep - The pointer of file, represents each user using the sensor. * enable - true(enable) and false(disable) * * Returned Value: @@ -601,7 +645,8 @@ struct sensor_ops_s * **************************************************************************/ - CODE int (*activate)(FAR struct sensor_lowerhalf_s *lower, bool enable); + CODE int (*activate)(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, bool enable); /************************************************************************** * Name: set_interval @@ -619,6 +664,7 @@ struct sensor_ops_s * * Input Parameters: * lower - The instance of lower half sensor driver. + * filep - The pointer of file, represents each user using sensor. * period_us - the time between samples, in us, it may be overwrite by * lower half driver. * @@ -628,6 +674,7 @@ struct sensor_ops_s **************************************************************************/ CODE int (*set_interval)(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *period_us); /************************************************************************** @@ -663,6 +710,7 @@ struct sensor_ops_s * * Input Parameters: * lower - The instance of lower half sensor driver. + * filep - The pointer of file, represents each user using sensor. * latency_us - the time between batch data, in us. It may by overwrite * by lower half driver. * @@ -672,6 +720,7 @@ struct sensor_ops_s **************************************************************************/ CODE int (*batch)(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *latency_us); /************************************************************************** @@ -693,6 +742,7 @@ struct sensor_ops_s * * Input Parameters: * lower - The instance of lower half sensor driver. + * filep - The pointer of file, represents each user using sensor. * buffer - The buffer of receive sensor event, it's provided by * file_operation::sensor_read. * buflen - The size of buffer. @@ -704,6 +754,7 @@ struct sensor_ops_s **************************************************************************/ CODE int (*fetch)(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR char *buffer, size_t buflen); /************************************************************************** @@ -718,6 +769,7 @@ struct sensor_ops_s * * Input Parameters: * lower - The instance of lower half sensor driver. + * filep - The pointer of file, represents each user using sensor. * arg - The parameters associated with selftest. * * Returned Value: @@ -726,6 +778,7 @@ struct sensor_ops_s **************************************************************************/ CODE int (*selftest)(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, unsigned long arg); /************************************************************************** @@ -738,6 +791,7 @@ struct sensor_ops_s * * Input Parameters: * lower - The instance of lower half sensor driver. + * filep - The pointer of file, represents each user using sensor. * arg - The parameters associated with calibration value. * * Returned Value: @@ -746,6 +800,7 @@ struct sensor_ops_s **************************************************************************/ CODE int (*set_calibvalue)(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, unsigned long arg); /**************************************************************************** @@ -762,6 +817,7 @@ struct sensor_ops_s * * Input Parameters: * lower - The instance of lower half sensor driver. + * filep - The pointer of file, represents each user using sensor. * arg - The parameters associated with calibration value. * * Returned Value: @@ -770,6 +826,7 @@ struct sensor_ops_s **************************************************************************/ CODE int (*calibrate)(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, unsigned long arg); /************************************************************************** @@ -781,6 +838,7 @@ struct sensor_ops_s * * Input Parameters: * lower - The instance of lower half sensor driver. + * filep - The pointer of file, represents each user using sensor. * cmd - The special cmd for sensor. * arg - The parameters associated with cmd. * @@ -791,6 +849,7 @@ struct sensor_ops_s **************************************************************************/ CODE int (*control)(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, int cmd, unsigned long arg); }; From 1d06aebc1c89da33effa3d7eec0000970efa7f49 Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Thu, 14 Apr 2022 11:58:35 +0800 Subject: [PATCH 3/4] driver/sensor: add struct file for all sensor_ops_s Signed-off-by: Jiuzhu Dong --- drivers/sensors/bmp280.c | 6 ++++++ drivers/sensors/ds18b20.c | 21 +++++++++++++++------ drivers/sensors/fakesensor.c | 9 +++++++-- drivers/sensors/hyt271.c | 17 ++++++++++++----- drivers/sensors/l3gd20.c | 6 ++++-- drivers/sensors/ms5611.c | 6 ++++-- drivers/sensors/wtgahrs2.c | 8 ++++++-- 7 files changed, 54 insertions(+), 19 deletions(-) diff --git a/drivers/sensors/bmp280.c b/drivers/sensors/bmp280.c index 723c6cc349a2b..93c3bc70c7cb0 100644 --- a/drivers/sensors/bmp280.c +++ b/drivers/sensors/bmp280.c @@ -160,10 +160,13 @@ static int bmp280_putreg8(FAR struct bmp280_dev_s *priv, uint8_t regaddr, /* Sensor methods */ static int bmp280_set_interval(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *period_us); static int bmp280_activate(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, bool enable); static int bmp280_fetch(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR char *buffer, size_t buflen); /**************************************************************************** @@ -504,6 +507,7 @@ static uint32_t bmp280_compensate_press(FAR struct bmp280_dev_s *priv, ****************************************************************************/ static int bmp280_set_interval(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *period_us) { FAR struct bmp280_dev_s *priv = container_of(lower, @@ -557,6 +561,7 @@ static int bmp280_set_interval(FAR struct sensor_lowerhalf_s *lower, ****************************************************************************/ static int bmp280_activate(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, bool enable) { FAR struct bmp280_dev_s *priv = container_of(lower, @@ -591,6 +596,7 @@ static int bmp280_activate(FAR struct sensor_lowerhalf_s *lower, ****************************************************************************/ static int bmp280_fetch(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR char *buffer, size_t buflen) { FAR struct bmp280_dev_s *priv = container_of(lower, diff --git a/drivers/sensors/ds18b20.c b/drivers/sensors/ds18b20.c index 67014bdf8f8dc..ffef8a4a17297 100644 --- a/drivers/sensors/ds18b20.c +++ b/drivers/sensors/ds18b20.c @@ -158,16 +158,20 @@ struct ds18b20_dev_s /* Sensor functions */ static int ds18b20_active(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, bool enabled); static int ds18b20_fetch(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR char *buffer, size_t buflen); static int ds18b20_control(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, int cmd, unsigned long arg); #ifdef CONFIG_SENSORS_DS18B20_POLL static int ds18b20_set_interval(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *period_us); #endif @@ -623,16 +627,18 @@ static int ds18b20_measure_read(FAR struct ds18b20_dev_s *dev, * conversion. * * Parameter: - * lower - Pointer to lower half sensor driver instance - * buffer - Pointer to the buffer for reading data - * buflen - Size of the buffer + * lower - Pointer to lower half sensor driver instance. + * filep - The pointer of file, represents each user using the sensor. + * buffer - Pointer to the buffer for reading data. + * buflen - Size of the buffer. * * Return: * OK - on success ****************************************************************************/ static int ds18b20_fetch(FAR struct sensor_lowerhalf_s *lower, - FAR char *buffer, size_t buflen) + FAR struct file *filep, + FAR char *buffer, size_t buflen) { int ret; struct ds18b20_sensor_data_s data; @@ -673,7 +679,8 @@ static int ds18b20_fetch(FAR struct sensor_lowerhalf_s *lower, ****************************************************************************/ static int ds18b20_control(FAR struct sensor_lowerhalf_s *lower, - int cmd, unsigned long arg) + FAR struct file *filep, + int cmd, unsigned long arg) { int ret; struct ds18b20_dev_s *priv = (FAR struct ds18b20_dev_s *)lower; @@ -740,6 +747,7 @@ static int ds18b20_control(FAR struct sensor_lowerhalf_s *lower, ****************************************************************************/ static int ds18b20_active(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, bool enabled) { #ifdef CONFIG_SENSORS_DS18B20_POLL @@ -778,7 +786,8 @@ static int ds18b20_active(FAR struct sensor_lowerhalf_s *lower, #ifdef CONFIG_SENSORS_DS18B20_POLL static int ds18b20_set_interval(FAR struct sensor_lowerhalf_s *lower, - FAR unsigned long *period_us) + FAR struct file *filep, + FAR unsigned long *period_us) { FAR struct ds18b20_dev_s *priv = (FAR struct ds18b20_dev_s *)lower; priv->interval = *period_us; diff --git a/drivers/sensors/fakesensor.c b/drivers/sensors/fakesensor.c index 823f15b1a2eb9..06953c88ec232 100644 --- a/drivers/sensors/fakesensor.c +++ b/drivers/sensors/fakesensor.c @@ -60,10 +60,12 @@ struct fakesensor_s ****************************************************************************/ static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower, - bool sw); + FAR struct file *filep, bool sw); static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *period_us); static int fakesensor_batch(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *latency_us); static void fakesensor_push_event(FAR struct sensor_lowerhalf_s *lower); static int fakesensor_thread(int argc, char** argv); @@ -213,7 +215,8 @@ static inline void fakesensor_read_gps(FAR struct fakesensor_s *sensor) sizeof(struct sensor_gps)); } -static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower, bool sw) +static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, bool sw) { FAR struct fakesensor_s *sensor = container_of(lower, struct fakesensor_s, lower); @@ -234,6 +237,7 @@ static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower, bool sw) } static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *period_us) { FAR struct fakesensor_s *sensor = container_of(lower, @@ -243,6 +247,7 @@ static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower, } static int fakesensor_batch(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *latency_us) { FAR struct fakesensor_s *sensor = container_of(lower, diff --git a/drivers/sensors/hyt271.c b/drivers/sensors/hyt271.c index 06945942ca28c..197c20e8e1c7b 100644 --- a/drivers/sensors/hyt271.c +++ b/drivers/sensors/hyt271.c @@ -110,16 +110,19 @@ struct hyt271_dev_s /* Sensor functions */ static int hyt271_active(FAR struct sensor_lowerhalf_s *lower, - bool enabled); + FAR struct file *filep, bool enabled); static int hyt271_fetch(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR char *buffer, size_t buflen); static int hyt271_control(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, int cmd, unsigned long arg); #ifdef CONFIG_SENSORS_HYT271_POLL static int hyt271_set_interval(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *period_us); #endif @@ -601,15 +604,17 @@ static int hyt271_measure_read(FAR struct hyt271_dev_s *dev, * conversion. * * Parameter: - * lower - Pointer to lower half sensor driver instance - * buffer - Pointer to the buffer for reading data - * buflen - Size of the buffer + * lower - Pointer to lower half sensor driver instance. + * filep - The pointer of file, represents each user using the sensor. + * buffer - Pointer to the buffer for reading data. + * buflen - Size of the buffer. * * Return: * OK - on success ****************************************************************************/ static int hyt271_fetch(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR char *buffer, size_t buflen) { int ret; @@ -664,6 +669,7 @@ static int hyt271_fetch(FAR struct sensor_lowerhalf_s *lower, ****************************************************************************/ static int hyt271_control(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, int cmd, unsigned long arg) { int ret; @@ -712,7 +718,7 @@ static int hyt271_control(FAR struct sensor_lowerhalf_s *lower, ****************************************************************************/ static int hyt271_active(FAR struct sensor_lowerhalf_s *lower, - bool enabled) + FAR struct file *filep, bool enabled) { #ifdef CONFIG_SENSORS_HYT271_POLL bool start_thread = false; @@ -751,6 +757,7 @@ static int hyt271_active(FAR struct sensor_lowerhalf_s *lower, #ifdef CONFIG_SENSORS_HYT271_POLL static int hyt271_set_interval(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *period_us) { FAR struct hyt271_sensor_s *priv = (FAR struct hyt271_sensor_s *)lower; diff --git a/drivers/sensors/l3gd20.c b/drivers/sensors/l3gd20.c index dad4cd5181941..648b7bfe685ee 100644 --- a/drivers/sensors/l3gd20.c +++ b/drivers/sensors/l3gd20.c @@ -91,11 +91,12 @@ static void l3gd20_read_temperature(FAR struct l3gd20_dev_s *dev, static int l3gd20_interrupt_handler(int irq, FAR void *context, FAR void *arg); static int l3gd20_activate(FAR struct sensor_lowerhalf_s *lower, - bool enable); + FAR struct file *filep, bool enable); #if CONFIG_SENSORS_L3GD20_BUFFER_SIZE > 0 static void l3gd20_worker(FAR void *arg); #else static int l3gd20_fetch(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR char *buffer, size_t buflen); #endif @@ -403,6 +404,7 @@ static void l3gd20_worker(FAR void *arg) ****************************************************************************/ static int l3gd20_fetch(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR char *buffer, size_t buflen) { FAR struct l3gd20_dev_s *priv = container_of(lower, @@ -427,7 +429,7 @@ static int l3gd20_fetch(FAR struct sensor_lowerhalf_s *lower, ****************************************************************************/ static int l3gd20_activate(FAR struct sensor_lowerhalf_s *lower, - bool enable) + FAR struct file *filep, bool enable) { FAR struct l3gd20_dev_s *priv = container_of(lower, FAR struct l3gd20_dev_s, diff --git a/drivers/sensors/ms5611.c b/drivers/sensors/ms5611.c index 095e08e9b83e6..506d05eaca6c3 100644 --- a/drivers/sensors/ms5611.c +++ b/drivers/sensors/ms5611.c @@ -121,9 +121,10 @@ static unsigned long ms5611_curtime(void); /* Sensor methods */ static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *period_us); static int ms5611_activate(FAR struct sensor_lowerhalf_s *lower, - bool enable); + FAR struct file *filep, bool enable); #if 0 /* Please read below */ static int ms5611_fetch(FAR struct sensor_lowerhalf_s *lower, @@ -540,6 +541,7 @@ static uint32_t ms5611_compensate_press(FAR struct ms5611_dev_s *priv, ****************************************************************************/ static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *period_us) { FAR struct ms5611_dev_s *priv = container_of(lower, @@ -555,7 +557,7 @@ static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower, ****************************************************************************/ static int ms5611_activate(FAR struct sensor_lowerhalf_s *lower, - bool enable) + FAR struct file *filep, bool enable) { bool start_thread = false; struct ms5611_dev_s *priv = (FAR struct ms5611_dev_s *)lower; diff --git a/drivers/sensors/wtgahrs2.c b/drivers/sensors/wtgahrs2.c index c1c54a2f83fe4..8ae2156b50215 100644 --- a/drivers/sensors/wtgahrs2.c +++ b/drivers/sensors/wtgahrs2.c @@ -95,8 +95,10 @@ struct wtgahrs2_dev_s * Private Function Prototypes ****************************************************************************/ -static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower, bool sw); +static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, bool sw); static int wtgahrs2_set_interval(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *interval); /**************************************************************************** @@ -152,7 +154,8 @@ static void wtgahrs2_sendcmd(FAR struct wtgahrs2_dev_s *rtdata, usleep(10000); } -static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower, bool sw) +static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, bool sw) { FAR struct wtgahrs2_sensor_s *dev = (FAR struct wtgahrs2_sensor_s *)lower; dev->enable = sw; @@ -161,6 +164,7 @@ static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower, bool sw) } static int wtgahrs2_set_interval(FAR struct sensor_lowerhalf_s *lower, + FAR struct file *filep, FAR unsigned long *interval) { FAR struct wtgahrs2_sensor_s *dev = (FAR struct wtgahrs2_sensor_s *)lower; From 5a7689a5f310b60993e1b2ff1bec30c98669a648 Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Sat, 9 Apr 2022 21:57:35 +0800 Subject: [PATCH 4/4] sensor: format custom ioctl argument by stucture sensor_ioctl_s Signed-off-by: Jiuzhu Dong --- include/nuttx/sensors/sensor.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/nuttx/sensors/sensor.h b/include/nuttx/sensors/sensor.h index a9ef796eb7657..0658d5c7882a0 100644 --- a/include/nuttx/sensors/sensor.h +++ b/include/nuttx/sensors/sensor.h @@ -958,6 +958,14 @@ struct sensor_reginfo_s }; #endif +/* This structure describes the context custom ioctl for device */ + +struct sensor_ioctl_s +{ + size_t len; /* The length of argument of ioctl */ + char data[1]; /* The argument buf of ioctl */ +}; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/