driver/sensors: add flags O_DIRECT to watch sensor state to avoid rpmsg work

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2024-07-04 11:21:44 +08:00 committed by Xiang Xiao
parent 05f5517f4f
commit a5729a81e3
1 changed files with 29 additions and 23 deletions

View File

@ -615,28 +615,31 @@ static int sensor_open(FAR struct file *filep)
}
}
if (filep->f_oflags & O_RDOK)
if ((filep->f_oflags & O_DIRECT) == 0)
{
if (upper->state.nsubscribers == 0 && lower->ops->activate)
if (filep->f_oflags & O_RDOK)
{
ret = lower->ops->activate(lower, filep, true);
if (ret < 0)
if (upper->state.nsubscribers == 0 && lower->ops->activate)
{
goto errout_with_open;
ret = lower->ops->activate(lower, filep, true);
if (ret < 0)
{
goto errout_with_open;
}
}
user->role |= SENSOR_ROLE_RD;
upper->state.nsubscribers++;
}
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)
if (filep->f_oflags & O_WROK)
{
lower->persist = true;
user->role |= SENSOR_ROLE_WR;
upper->state.nadvertisers++;
if (filep->f_oflags & SENSOR_PERSIST)
{
lower->persist = true;
}
}
}
@ -695,18 +698,21 @@ static int sensor_close(FAR struct file *filep)
}
}
if (filep->f_oflags & O_RDOK)
if ((filep->f_oflags & O_DIRECT) == 0)
{
upper->state.nsubscribers--;
if (upper->state.nsubscribers == 0 && lower->ops->activate)
if (filep->f_oflags & O_RDOK)
{
lower->ops->activate(lower, filep, false);
upper->state.nsubscribers--;
if (upper->state.nsubscribers == 0 && lower->ops->activate)
{
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);