You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/09/28 03:40:09 UTC

(nuttx) 08/10: driver/sensors: add flags O_DIRECT to watch sensor state to avoid rpmsg work

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a5729a81e3a27ee8d0f46ca2500dc2a0529336f3
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Thu Jul 4 11:21:44 2024 +0800

    driver/sensors: add flags O_DIRECT to watch sensor state to avoid rpmsg work
    
    Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
 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);