Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 33 additions & 31 deletions drivers/sensors/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ static int sensor_open(FAR struct file *filep)
goto errout_with_lock;
}

if (lower->ops->open)
if ((filep->f_oflags & O_DIRECT) == 0 && lower->ops->open)
{
ret = lower->ops->open(lower, filep);
if (ret < 0)
Expand All @@ -623,31 +623,32 @@ static int sensor_open(FAR struct file *filep)
}
}

if ((filep->f_oflags & O_DIRECT) == 0)
/* Using the O_DIRECT flag will prevent cross-core operations,
* allowing for direct I/O operations.
*/

if (filep->f_oflags & O_RDOK)
{
if (filep->f_oflags & O_RDOK)
if (upper->state.nsubscribers == 0 && lower->ops->activate)
{
if (upper->state.nsubscribers == 0 && lower->ops->activate)
ret = lower->ops->activate(lower, filep, true);
if (ret < 0)
{
ret = lower->ops->activate(lower, filep, true);
if (ret < 0)
{
goto errout_with_open;
}
goto errout_with_open;
}

user->role |= SENSOR_ROLE_RD;
upper->state.nsubscribers++;
}

if (filep->f_oflags & O_WROK)
user->role |= SENSOR_ROLE_RD;
upper->state.nsubscribers++;
}

if (filep->f_oflags & O_WROK)
{
user->role |= SENSOR_ROLE_WR;
upper->state.nadvertisers++;
if (filep->f_oflags & SENSOR_PERSIST)
{
user->role |= SENSOR_ROLE_WR;
upper->state.nadvertisers++;
if (filep->f_oflags & SENSOR_PERSIST)
{
lower->persist = true;
}
lower->persist = true;
}
}

Expand Down Expand Up @@ -696,7 +697,7 @@ static int sensor_close(FAR struct file *filep)
int ret = 0;

nxrmutex_lock(&upper->lock);
if (lower->ops->close)
if ((filep->f_oflags & O_DIRECT) == 0 && lower->ops->close)
{
ret = lower->ops->close(lower, filep);
if (ret < 0)
Expand All @@ -706,21 +707,22 @@ static int sensor_close(FAR struct file *filep)
}
}

if ((filep->f_oflags & O_DIRECT) == 0)
/* Using the O_DIRECT flag will prevent cross-core operations,
* allowing for direct I/O operations.
*/

if (filep->f_oflags & O_RDOK)
{
if (filep->f_oflags & O_RDOK)
upper->state.nsubscribers--;
if (upper->state.nsubscribers == 0 && lower->ops->activate)
{
upper->state.nsubscribers--;
if (upper->state.nsubscribers == 0 && lower->ops->activate)
{
lower->ops->activate(lower, filep, false);
}
lower->ops->activate(lower, filep, false);
}
}

if (filep->f_oflags & O_WROK)
{
upper->state.nadvertisers--;
}
if (filep->f_oflags & O_WROK)
{
upper->state.nadvertisers--;
}

list_delete(&user->node);
Expand Down
3 changes: 2 additions & 1 deletion drivers/sensors/sensor_rpmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,8 @@ static int sensor_rpmsg_get_info(FAR struct sensor_lowerhalf_s *lower,
{
ret = drv->ops->get_info(drv, filep, info);
}
else if (!(filep->f_oflags & SENSOR_REMOTE))

if (ret == -ENOTTY && !(filep->f_oflags & SENSOR_REMOTE))
{
ret = sensor_rpmsg_ioctl(dev, SNIOC_GET_INFO,
(unsigned long)(uintptr_t)info,
Expand Down
29 changes: 7 additions & 22 deletions drivers/sensors/usensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ static int usensor_ioctl(FAR struct file *filep, int cmd,
static int usensor_get_info(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR struct sensor_device_info_s *info);
static int usensor_control(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
int cmd, unsigned long arg);

/****************************************************************************
* Private Types
Expand All @@ -75,7 +72,7 @@ struct usensor_lowerhalf_s
{
struct list_node node; /* node in all usensor list */
struct sensor_lowerhalf_s driver; /* The lowerhalf driver of user sensor */
struct sensor_device_info_s info; /* Virtual sensor information */
struct sensor_device_info_s devinfo; /* Virtual sensor information */
char path[1]; /* The path of usensor character device */
};

Expand All @@ -99,7 +96,6 @@ static const struct file_operations g_usensor_fops =
static const struct sensor_ops_s g_usensor_ops =
{
.get_info = usensor_get_info,
.control = usensor_control
};

/****************************************************************************
Expand All @@ -124,6 +120,8 @@ static int usensor_register(FAR struct usensor_context_s *usensor,
lower->driver.persist = info->persist;
lower->driver.ops = &g_usensor_ops;
strlcpy(lower->path, info->path, size + 1);
memcpy(&lower->devinfo, &info->devinfo, sizeof(lower->devinfo));

ret = sensor_custom_register(&lower->driver, lower->path, info->esize);
if (ret < 0)
{
Expand Down Expand Up @@ -231,26 +229,13 @@ static int usensor_get_info(FAR struct sensor_lowerhalf_s *lower,
FAR struct usensor_lowerhalf_s *ulower = container_of(lower,
struct usensor_lowerhalf_s,
driver);

*info = ulower->info;
return 0;
}

static int usensor_control(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
int cmd, unsigned long arg)
{
FAR struct usensor_lowerhalf_s *ulower = container_of(lower,
struct usensor_lowerhalf_s,
driver);

if (cmd == SNIOC_SET_INFO)
if (ulower->devinfo.name[0] == '\0')
{
ulower->info = *(FAR struct sensor_device_info_s *)(uintptr_t)arg;
return 0;
return -ENOTTY;
}

return -ENOTTY;
*info = ulower->devinfo;
return 0;
}

/****************************************************************************
Expand Down
13 changes: 2 additions & 11 deletions include/nuttx/sensors/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,27 +444,18 @@

#define SNIOC_GET_INFO _SNIOC(0x009B)

#ifdef CONFIG_USENSOR
/* Command: SNIOC_SET_INFO
* Description: Set device information. Only used by user space.
* Argument: This is the device info pointer.
*/

# define SNIOC_SET_INFO _SNIOC(0x009C)
#endif

Comment on lines -447 to -455
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this considered a breaking change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ioctl is normally used with Android sensor HAL to report the additional sensor info required by Android, since both side is modified, the impact is minimal.

/* Command: SNIOC_FLUSH
* Description: Flush sensor hardware fifo buffer.
*/

#define SNIOC_FLUSH _SNIOC(0x009D)
#define SNIOC_FLUSH _SNIOC(0x009C)

/* Command: SNIOC_GET_EVENTS
* Description: Get events of the sensor device.
* Argument: The events pointer, (unsigned int *)
*/

#define SNIOC_GET_EVENTS _SNIOC(0x009E)
#define SNIOC_GET_EVENTS _SNIOC(0x009D)

/* Command: SNIOC_SET_THERMO
* Description: Set the thermocouple type.
Expand Down
35 changes: 18 additions & 17 deletions include/nuttx/uorb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1220,23 +1220,6 @@ struct sensor_ustate_s
uint64_t generation; /* The recent generation of circular buffer */
};

/* This structure describes the register info for the user sensor */

#ifdef CONFIG_USENSOR
struct sensor_reginfo_s
{
char path[NAME_MAX]; /* The path of user sensor */
uint32_t esize; /* The element size of user sensor */
uint32_t nbuffer; /* The number of queue buffered elements */

/* The flag is used to indicate that the validity of sensor data
* is persistent.
*/

int persist;
};
#endif

/* This structure describes the context custom ioctl for device */

struct sensor_ioctl_s
Expand Down Expand Up @@ -1311,4 +1294,22 @@ struct sensor_device_info_s
char vendor[SENSOR_INFO_NAME_SIZE];
};

/* This structure describes the register info for the user sensor */

#ifdef CONFIG_USENSOR
struct sensor_reginfo_s
{
char path[NAME_MAX]; /* The path of user sensor */
uint32_t esize; /* The element size of user sensor */
uint32_t nbuffer; /* The number of queue buffered elements */
struct sensor_device_info_s devinfo; /* The device info. */

/* The flag is used to indicate that the validity of sensor data
* is persistent.
*/

int persist;
};
#endif

#endif /* __INCLUDE_NUTTX_SENSORS_SENSOR_H */
Loading