driver/sensor: support userspace wirte data into sensor device
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
5f68aa56fd
commit
dad5ab75ff
@ -89,10 +89,14 @@ static int sensor_open(FAR struct file *filep);
|
||||
static int sensor_close(FAR struct file *filep);
|
||||
static ssize_t sensor_read(FAR struct file *filep, FAR char *buffer,
|
||||
size_t buflen);
|
||||
static ssize_t sensor_write(FAR struct file *filep, FAR const char *buffer,
|
||||
size_t buflen);
|
||||
static int sensor_ioctl(FAR struct file *filep, int cmd,
|
||||
unsigned long arg);
|
||||
static int sensor_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
bool setup);
|
||||
static ssize_t sensor_push_event(FAR void *priv, FAR const void *data,
|
||||
size_t bytes);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
@ -140,7 +144,7 @@ static const struct file_operations g_sensor_fops =
|
||||
sensor_open, /* open */
|
||||
sensor_close, /* close */
|
||||
sensor_read, /* read */
|
||||
NULL, /* write */
|
||||
sensor_write, /* write */
|
||||
NULL, /* seek */
|
||||
sensor_ioctl, /* ioctl */
|
||||
sensor_poll /* poll */
|
||||
@ -346,6 +350,15 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t sensor_write(FAR struct file *filep, FAR const char *buffer,
|
||||
size_t buflen)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct sensor_upperhalf_s *upper = inode->i_private;
|
||||
|
||||
return sensor_push_event(upper, buffer, buflen);
|
||||
}
|
||||
|
||||
static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
@ -600,15 +613,22 @@ errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void sensor_push_event(FAR void *priv, FAR const void *data,
|
||||
size_t bytes)
|
||||
static ssize_t sensor_push_event(FAR void *priv, FAR const void *data,
|
||||
size_t bytes)
|
||||
{
|
||||
FAR struct sensor_upperhalf_s *upper = priv;
|
||||
int semcount;
|
||||
int ret;
|
||||
|
||||
if (!bytes || nxsem_wait(&upper->exclsem) < 0)
|
||||
if (!bytes)
|
||||
{
|
||||
return;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = nxsem_wait(&upper->exclsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
circbuf_overwrite(&upper->buffer, data, bytes);
|
||||
@ -620,6 +640,7 @@ static void sensor_push_event(FAR void *priv, FAR const void *data,
|
||||
}
|
||||
|
||||
nxsem_post(&upper->exclsem);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static void sensor_notify_event(FAR void *priv)
|
||||
|
@ -843,13 +843,17 @@ struct sensor_lowerhalf_s
|
||||
* It is provided by upper half driver to lower half driver.
|
||||
*
|
||||
* Input Parameters:
|
||||
* priv - Upper half driver handle
|
||||
* priv - Upper half driver handle.
|
||||
* data - The buffer of event, it can be all type of sensor events.
|
||||
* bytes - The number of bytes of sensor event
|
||||
* bytes - The number of bytes of sensor event.
|
||||
*
|
||||
* Returned Value:
|
||||
* The bytes of push is returned when success;
|
||||
* A negated errno value is returned on any failure.
|
||||
**********************************************************************/
|
||||
|
||||
CODE void (*push_event)(FAR void *priv, FAR const void *data,
|
||||
size_t bytes);
|
||||
CODE ssize_t (*push_event)(FAR void *priv, FAR const void *data,
|
||||
size_t bytes);
|
||||
|
||||
/**********************************************************************
|
||||
* Name: notify_event
|
||||
|
Loading…
Reference in New Issue
Block a user