driver/sensor: move readlast for each user

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-05-10 22:15:54 +08:00 committed by Xiang Xiao
parent 6f3873dfa2
commit 74b2be20d0

View file

@ -84,6 +84,7 @@ struct sensor_user_s
unsigned long generation; /* Last generation subscriber has seen */
unsigned long interval; /* The interval for subscriber */
unsigned long latency; /* The bactch latency for subscriber */
bool readlast; /* The flag of readlast */
};
/* This structure describes the state of the upper half driver */
@ -95,7 +96,6 @@ struct sensor_upperhalf_s
struct circbuf_s buffer; /* The circular buffer of sensor device */
sem_t exclsem; /* Manages exclusive access to file operations */
struct list_node userlist; /* List of users */
bool readlast; /* The flag of readlast */
};
/****************************************************************************
@ -402,6 +402,7 @@ static int sensor_open(FAR struct file *filep)
user->interval = ULONG_MAX;
user->latency = ULONG_MAX;
user->generation = upper->state.generation;
user->readlast = true;
nxsem_init(&user->buffersem, 0, 0);
nxsem_set_protocol(&user->buffersem, SEM_PRIO_NONE);
list_add_tail(&upper->userlist, &user->node);
@ -532,7 +533,7 @@ static ssize_t sensor_read(FAR struct file *filep, FAR char *buffer,
* it will return 0 when there isn't new data.
*/
if (upper->readlast)
if (user->readlast)
{
if (circbuf_is_empty(&upper->buffer))
{
@ -716,7 +717,9 @@ static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
case SNIOC_READLAST:
{
upper->readlast = !!arg;
sensor_semtake(upper);
user->readlast = !!arg;
sensor_semgive(upper);
}
break;
@ -985,7 +988,6 @@ int sensor_custom_register(FAR struct sensor_lowerhalf_s *lower,
/* Initialize the upper-half data structure */
list_initialize(&upper->userlist);
upper->readlast = true;
upper->state.esize = esize;
upper->state.min_interval = ULONG_MAX;
upper->state.min_latency = ULONG_MAX;