From a5516121e21bd48cffcde0cbed7cb87d0a1a8168 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Tue, 2 Apr 2024 20:15:10 +0800 Subject: [PATCH] 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 --- 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 a4ccf35dc..212789918 100644 --- a/system/uorb/uORB/uORB.h +++ b/system/uorb/uORB/uORB.h @@ -114,6 +114,8 @@ struct orb_handle_s * 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) @@ -521,6 +523,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 * @@ -563,6 +582,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 *