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

lupyuen pushed a commit to branch releases/12.7
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit de7bbc1b25d05598847b26e5165eb1bd9f4c3e1c
Author: dongjiuzhu1 <dongjiuz...@xiaomi.com>
AuthorDate: Tue Apr 2 20:15:10 2024 +0800

    uorb/flush: support flush operation
    
    After you call orb_flush(), you can determine whether the
    flush is completed by listening to the POLLPRI event
    of fd and getting the event in orb_get_events.
    
    After calling orb_get_events, the flush events will be cleared.
    
    Signed-off-by: dongjiuzhu1 <dongjiuz...@xiaomi.com>
---
 system/uorb/uORB/uORB.c | 15 +++++++++++++++
 system/uorb/uORB/uORB.h | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/system/uorb/uORB/uORB.c b/system/uorb/uORB/uORB.c
index 09f611c1b..4efac9bce 100644
--- a/system/uorb/uORB/uORB.c
+++ b/system/uorb/uORB/uORB.c
@@ -229,6 +229,16 @@ int orb_get_state(int fd, FAR struct orb_state *state)
   return ret;
 }
 
+int orb_get_events(int fd, FAR unsigned int *events)
+{
+  if (!events)
+    {
+      return -EINVAL;
+    }
+
+  return ioctl(fd, SNIOC_GET_EVENTS, (unsigned long)(uintptr_t)events);
+}
+
 int orb_check(int fd, FAR bool *updated)
 {
   return ioctl(fd, SNIOC_UPDATED, (unsigned long)(uintptr_t)updated);
@@ -239,6 +249,11 @@ int orb_ioctl(int fd, int cmd, unsigned long arg)
   return ioctl(fd, cmd, arg);
 }
 
+int orb_flush(int fd)
+{
+  return ioctl(fd, SNIOC_FLUSH, 0);
+}
+
 int orb_set_interval(int fd, unsigned interval)
 {
   return ioctl(fd, SNIOC_SET_INTERVAL, (unsigned long)interval);
diff --git a/system/uorb/uORB/uORB.h b/system/uorb/uORB/uORB.h
index 5c82d4807..4492a0b2a 100644
--- a/system/uorb/uORB/uORB.h
+++ b/system/uorb/uORB/uORB.h
@@ -79,6 +79,8 @@ typedef struct sensor_device_info_s orb_info_t;
  * Pre-processor Definitions
  ****************************************************************************/
 
+#define ORB_EVENT_FLUSH_COMPLETE SENSOR_EVENT_FLUSH_COMPLETE
+
 #define ORB_SENSOR_PATH        "/dev/uorb/"
 #define ORB_USENSOR_PATH       "/dev/usensor"
 #define ORB_PATH_MAX           (NAME_MAX + 16)
@@ -486,6 +488,23 @@ static inline int orb_copy(FAR const struct orb_metadata 
*meta,
 
 int orb_get_state(int fd, FAR struct orb_state *state);
 
+/****************************************************************************
+ * Name: orb_get_events
+ *
+ * Description:
+ *   Get the events about the specify subscriber of topic.
+ *
+ * Input Parameters:
+ *   fd       The fd returned from orb_advertise / orb_subscribe.
+ *   events   Pointer to events, type is unsigned int pointer.
+ *            eg: ORB_EVENT_FLUSH_COMPLETE
+ *
+ * Returned Value:
+ *   -1 on error.
+ ****************************************************************************/
+
+int orb_get_events(int fd, FAR unsigned int *events);
+
 /****************************************************************************
  * Name: orb_check
  *
@@ -528,6 +547,27 @@ int orb_check(int fd, FAR bool *updated);
 
 int orb_ioctl(int fd, int cmd, unsigned long arg);
 
+/****************************************************************************
+ * Name: orb_flush
+ *
+ * Description:
+ *   When topic data accumulates in the hardware buffer but does not reach
+ *   the watermark, you can mmediately read the fifo data through the flush
+ *   operation. You can call the flush operation at any time.
+ *
+ *   After you call flush, you can determine whether the flush is completed
+ *   by listening to the POLLPRI event of fd and getting the event in
+ *   orb_get_events
+ *
+ * Input Parameters:
+ *   fd       A fd returned from orb_advertise / orb_subscribe.
+ *
+ * Returned Value:
+ *   0 on success.
+ ****************************************************************************/
+
+int orb_flush(int fd);
+
 /****************************************************************************
  * Name: orb_set_batch_interval
  *

Reply via email to