This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 8d9c3aef701e4ba8e7123bb95f374f7abeb7ce7f Author: dongjiuzhu1 <[email protected]> AuthorDate: Fri May 9 12:17:06 2025 +0800 system/uorb: Add orb_subscribe_wakeup() and orb_subscribe_multi_wakeup(). The sensor driver opens every user in non-wakeup mode, so orb_subscribe() and orb_subscribe_multi() already get non-wakeup subscriptions, and orb_subscribe_nonwakeup() only repeats the default. There is no API to request a wakeup subscription, which is what a subscriber needs when it must receive data while the system sleeps. Add orb_subscribe_wakeup() and orb_subscribe_multi_wakeup(), which turn wakeup on for the new subscriber. orb_subscribe_multi_nonwakeup() and orb_subscribe_nonwakeup() become inline aliases of orb_subscribe_multi() and orb_subscribe(). The default behavior of the existing APIs does not change. Signed-off-by: dongjiuzhu1 <[email protected]> Signed-off-by: likun17 <[email protected]> --- system/uorb/uORB/uORB.c | 12 ++++++------ system/uorb/uORB/uORB.h | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 10 deletions(-) diff --git a/system/uorb/uORB/uORB.c b/system/uorb/uORB/uORB.c index fd1fd3c31..3c715f38e 100644 --- a/system/uorb/uORB/uORB.c +++ b/system/uorb/uORB/uORB.c @@ -140,7 +140,7 @@ static int orb_advsub_open(FAR const struct orb_metadata *meta, int flags, ioctl(fd, SNIOC_SET_BUFFER_NUMBER, (unsigned long)queue_size); } - if (non_wakeup) + if (!non_wakeup) { ioctl(fd, SNIOC_SET_NONWAKEUP, (unsigned long)non_wakeup); } @@ -161,7 +161,7 @@ orb_advertise_multi_queue_flags(FAR const struct orb_metadata *meta, inst = instance ? *instance : orb_group_count(meta); - fd = orb_advsub_open(meta, flags, inst, queue_size, info, false); + fd = orb_advsub_open(meta, flags, inst, queue_size, info, true); if (fd < 0) { uorberr("%s advertise failed (%i)", meta->o_name, fd); @@ -255,13 +255,13 @@ ssize_t orb_publish_multi(int fd, FAR const void *data, size_t len) int orb_subscribe_multi(FAR const struct orb_metadata *meta, unsigned instance) { - return orb_advsub_open(meta, O_RDONLY, instance, 0, NULL, false); + return orb_advsub_open(meta, O_RDONLY, instance, 0, NULL, true); } -int orb_subscribe_multi_nonwakeup(FAR const struct orb_metadata *meta, - unsigned instance) +int orb_subscribe_multi_wakeup(FAR const struct orb_metadata *meta, + unsigned instance) { - return orb_advsub_open(meta, O_RDONLY, instance, 0, NULL, true); + return orb_advsub_open(meta, O_RDONLY, instance, 0, NULL, false); } ssize_t orb_copy_multi(int fd, FAR void *buffer, size_t len) diff --git a/system/uorb/uORB/uORB.h b/system/uorb/uORB/uORB.h index d8f8707d7..89071630a 100644 --- a/system/uorb/uORB/uORB.h +++ b/system/uorb/uORB/uORB.h @@ -449,7 +449,7 @@ static inline int orb_publish_auto(FAR const struct orb_metadata *meta, * Name: orb_subscribe_multi * * Description: - * Subscribe to a topic. + * Subscribe to a topic in a non-wakeup ways. * * The data is published to the topic and any waiting subscribers will be * notified. Subscribers that are not waiting can check the topic for @@ -490,7 +490,7 @@ static inline int orb_subscribe(FAR const struct orb_metadata *meta) * Description: * Subscribe to a topic in a non-wakeup ways. * - * The usage of orb_subscribe_multi_nonwakeup is similar to that of + * The usage of orb_subscribe_multi_nonwakeup is same to that of * orb_subscribe_multi, with the key difference lying in whether the * system's wakeup status needs to be concerned. This distinction is * particularly beneficial for low-power consumption scenarios. @@ -513,13 +513,53 @@ static inline int orb_subscribe(FAR const struct orb_metadata *meta) * this function will return -1 and set errno to ENOENT. ****************************************************************************/ +static inline int orb_subscribe_multi_nonwakeup(FAR const struct orb_metadata *meta, - unsigned instance); + unsigned instance) +{ + return orb_subscribe_multi(meta, instance); +} static inline int orb_subscribe_nonwakeup(FAR const struct orb_metadata *meta) { - return orb_subscribe_multi_nonwakeup(meta, 0); + return orb_subscribe(meta); +} + +/**************************************************************************** + * Name: orb_subscribe_multi_wakeup/orb_subscribe_wakeup + * + * Description: + * Subscribe to a topic in a wakeup ways. + * + * The usage of orb_subscribe_multi_wakeup is similar to that of + * orb_subscribe_multi, with the key difference lying in whether the + * system's wakeup status needs to be concerned. This distinction is + * particularly beneficial for low-power consumption scenarios. + * If the subscription is in a wakeup mode, the subscriber will be wokeup + * and it receives data while the system is in sleep mode. Typically, the + * subscriber and publisher of a topic reside in two separate systems. + * + * Input Parameters: + * meta The uORB metadata (usually from the ORB_ID() macro) + * instance The instance of the topic. Instance 0 matches the topic of + * the orb_subscribe() call. + * + * Returned Value: + * -1 on error, otherwise returns a fd + * that can be used to read and update the topic. + * If the topic in question is not known (due to an + * ORB_DEFINE_OPTIONAL with no corresponding ORB_DECLARE) + * this function will return -1 and set errno to ENOENT. + ****************************************************************************/ + +int orb_subscribe_multi_wakeup(FAR const struct orb_metadata *meta, + unsigned instance); + +static inline +int orb_subscribe_wakeup(FAR const struct orb_metadata *meta) +{ + return orb_subscribe_multi_wakeup(meta, 0); } /****************************************************************************
