From a5729a81e3a27ee8d0f46ca2500dc2a0529336f3 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Thu, 4 Jul 2024 11:21:44 +0800 Subject: [PATCH] driver/sensors: add flags O_DIRECT to watch sensor state to avoid rpmsg work Signed-off-by: dongjiuzhu1 --- drivers/sensors/sensor.c | 52 ++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/drivers/sensors/sensor.c b/drivers/sensors/sensor.c index 7ec0530cca..389085dd11 100644 --- a/drivers/sensors/sensor.c +++ b/drivers/sensors/sensor.c @@ -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);