xiaoxiang781216 commented on code in PR #3743:
URL: https://github.com/apache/nuttx-apps/pull/3743#discussion_r3887371738


##########
include/system/zbus_macros.h:
##########
@@ -0,0 +1,172 @@
+/****************************************************************************
+ * apps/include/system/zbus_macros.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* Compact variadic macro engine used by <system/zbus.h>.  Replaces the
+ * subset of Zephyr's util_macro.h needed by the zbus definition macros.
+ * Supports observer lists with 0 to 16 entries per channel.  Relies on the
+ * GNU ", ## __VA_ARGS__" extension (available on all NuttX toolchains).
+ */
+
+#ifndef __APPS_INCLUDE_SYSTEM_ZBUS_MACROS_H
+#define __APPS_INCLUDE_SYSTEM_ZBUS_MACROS_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define _ZB_CAT(a, b)  _ZB_CAT_(a, b)

Review Comment:
   reuse nuttx/macros.h



##########
include/system/zbus.h:
##########
@@ -0,0 +1,655 @@
+/****************************************************************************
+ * apps/include/system/zbus.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Copyright (c) 2022 Rodrigo Peixoto <[email protected]>
+ * Copyright (c) 2026 NuttX port
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.  You may obtain
+ * a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* NuttX port of the Zephyr zbus message bus.
+ *
+ * Differences from the Zephyr original:
+ *  - Timeouts are given in milliseconds (int32_t): ZBUS_NO_WAIT (0) and
+ *    ZBUS_FOREVER (-1) replace K_NO_WAIT/K_FOREVER.
+ *  - Subscribers and message subscribers use POSIX message queues opened
+ *    lazily on first zbus API call (no k_msgq/k_fifo/net_buf).
+ *  - Priority boost (HLP) is not implemented; enable NuttX native
+ *    CONFIG_PRIORITY_INHERITANCE for equivalent protection.
+ *  - Publishing from interrupt context is not supported.
+ *  - Requires the board linker script to include the iterable section
+ *    fragments <nuttx/linker/common-rom.ld> and common-ram.ld.
+ */
+
+#ifndef __APPS_INCLUDE_SYSTEM_ZBUS_H
+#define __APPS_INCLUDE_SYSTEM_ZBUS_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/iterable_sections.h>
+
+#include <assert.h>
+#include <errno.h>
+#include <semaphore.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+#include <time.h>
+
+#ifdef CONFIG_ZBUS_RUNTIME_OBSERVERS
+#  include <nuttx/list.h>
+#endif
+
+#include <sys/types.h>
+
+#include <system/zbus_macros.h>
+
+#ifdef __cplusplus
+#define _ZBUS_CPP_EXTERN extern
+extern "C"
+{
+#else
+#define _ZBUS_CPP_EXTERN
+#endif
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Timeout special values (milliseconds) */
+
+#define ZBUS_NO_WAIT  0
+#define ZBUS_FOREVER  (-1)
+
+/* Channel without a unique numeric identifier */
+
+#define ZBUS_CHAN_ID_INVALID UINT32_MAX
+
+#ifdef CONFIG_ZBUS_ASSERT_MOCK
+#  define _ZBUS_ASSERT(cond, msg) \
+  do                              \
+    {                             \
+      if (!(cond))                \
+        {                         \
+          return -EFAULT;         \
+        }                         \
+    }                             \
+  while (0)
+#else
+#  define _ZBUS_ASSERT(cond, msg) DEBUGASSERT(cond)
+#endif
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+struct zbus_channel;
+
+/* Mutable data associated with every channel */
+
+struct zbus_channel_data
+{
+  /* Boundaries of this channel's static observations inside the sorted
+   * zbus_channel_observation iterable section (computed on first use).
+   */
+
+  int16_t observers_start_idx;
+  int16_t observers_end_idx;
+
+  /* Channel access semaphore */
+
+  sem_t sem;
+
+#ifdef CONFIG_ZBUS_RUNTIME_OBSERVERS
+  /* Runtime (dynamically added) observers */
+
+  struct list_node observers;
+#endif
+
+#ifdef CONFIG_ZBUS_CHANNEL_PUBLISH_STATS
+  struct timespec publish_timestamp;
+  uint32_t publish_count;
+#endif
+};
+
+/* A channel: constant descriptor placed in ROM (iterable section) */
+
+struct zbus_channel
+{
+#ifdef CONFIG_ZBUS_CHANNEL_NAME
+  const char *name;
+#endif
+#ifdef CONFIG_ZBUS_CHANNEL_ID
+  uint32_t id;
+#endif
+
+  /* Shared message memory, its size, and optional user data/validator */
+
+  void *message;
+  size_t message_size;
+  void *user_data;
+  bool (*validator)(const void *msg, size_t msg_size);
+
+  struct zbus_channel_data *data;
+};
+
+/* Observer types */
+
+enum zbus_observer_type
+{
+  ZBUS_OBSERVER_LISTENER_TYPE = 0,
+  ZBUS_OBSERVER_SUBSCRIBER_TYPE,
+  ZBUS_OBSERVER_MSG_SUBSCRIBER_TYPE,
+  ZBUS_OBSERVER_ASYNC_LISTENER_TYPE,
+};
+
+/* Mutable data associated with every observer */
+
+struct zbus_observer_data
+{
+  bool enabled;
+
+  /* Notification queue (subscriber/msg subscriber/async listener), opened
+   * lazily with file_mq_open() so it is usable from any task, unlike
+   * per-task mqd_t descriptors.  mq.f_inode == NULL means "not opened".
+   */
+
+  struct file mq;

Review Comment:
   file can only be used by kernel



##########
include/system/zbus_macros.h:
##########
@@ -0,0 +1,172 @@
+/****************************************************************************
+ * apps/include/system/zbus_macros.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* Compact variadic macro engine used by <system/zbus.h>.  Replaces the
+ * subset of Zephyr's util_macro.h needed by the zbus definition macros.
+ * Supports observer lists with 0 to 16 entries per channel.  Relies on the
+ * GNU ", ## __VA_ARGS__" extension (available on all NuttX toolchains).
+ */
+
+#ifndef __APPS_INCLUDE_SYSTEM_ZBUS_MACROS_H
+#define __APPS_INCLUDE_SYSTEM_ZBUS_MACROS_H
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define _ZB_CAT(a, b)  _ZB_CAT_(a, b)
+#define _ZB_CAT_(a, b) a##b
+
+/* Empty argument list detection (P99 ISEMPTY technique).  Needed because
+ * ZBUS_OBSERVERS_EMPTY expands to nothing, producing an empty-but-present
+ * argument, and the GNU ", ## __VA_ARGS__" comma deletion is not reliable
+ * for that case across compiler versions.  Only valid for lists of plain
+ * identifiers, which is what the zbus macros take.
+ */
+
+#define _ZB_ARG18(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, \
+                  a14, a15, a16, a17, a18, ...) a18
+#define _ZB_HAS_COMMA(...) \
+  _ZB_ARG18(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \
+            0)
+#define _ZB_TRIGGER_PARENTHESIS_(...) ,
+#define _ZB_PASTE5(a1, a2, a3, a4, a5) a1##a2##a3##a4##a5
+#define _ZB_IS_EMPTY(...)                                                 \
+  _ZB_IS_EMPTY_I(_ZB_HAS_COMMA(__VA_ARGS__),                              \
+                 _ZB_HAS_COMMA(_ZB_TRIGGER_PARENTHESIS_ __VA_ARGS__),     \
+                 _ZB_HAS_COMMA(__VA_ARGS__ ()),                           \
+                 _ZB_HAS_COMMA(_ZB_TRIGGER_PARENTHESIS_ __VA_ARGS__ ()))
+#define _ZB_IS_EMPTY_I(c1, c2, c3, c4) \
+  _ZB_HAS_COMMA(_ZB_PASTE5(_ZB_IS_EMPTY_CASE_, c1, c2, c3, c4))
+#define _ZB_IS_EMPTY_CASE_0001 ,
+
+/* Count 1..16 variadic arguments (the list must NOT be empty; the
+ * dispatchers below guarantee that).
+ */
+
+#define _ZB_NARG(...) \
+  _ZB_NARG_(__VA_ARGS__, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, \
+            4, 3, 2, 1)
+#define _ZB_NARG_(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, \
+                  a13, a14, a15, a16, n, ...) n
+
+/* ZBUS_FOR_EACH(F, ...): expand F(arg) for each argument */
+
+#define _ZB_FE1_0(f)
+#define _ZB_FE1_1(f, o1) f(o1)
+#define _ZB_FE1_2(f, o1, o2) f(o1) f(o2)
+#define _ZB_FE1_3(f, o1, o2, o3) f(o1) f(o2) f(o3)
+#define _ZB_FE1_4(f, o1, o2, o3, o4) f(o1) f(o2) f(o3) f(o4)
+#define _ZB_FE1_5(f, o1, o2, o3, o4, o5) f(o1) f(o2) f(o3) f(o4) f(o5)
+#define _ZB_FE1_6(f, o1, o2, o3, o4, o5, o6) \
+  _ZB_FE1_5(f, o1, o2, o3, o4, o5) f(o6)
+#define _ZB_FE1_7(f, o1, o2, o3, o4, o5, o6, o7) \
+  _ZB_FE1_6(f, o1, o2, o3, o4, o5, o6) f(o7)
+#define _ZB_FE1_8(f, o1, o2, o3, o4, o5, o6, o7, o8) \
+  _ZB_FE1_7(f, o1, o2, o3, o4, o5, o6, o7) f(o8)
+#define _ZB_FE1_9(f, o1, o2, o3, o4, o5, o6, o7, o8, o9) \
+  _ZB_FE1_8(f, o1, o2, o3, o4, o5, o6, o7, o8) f(o9)
+#define _ZB_FE1_10(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10) \
+  _ZB_FE1_9(f, o1, o2, o3, o4, o5, o6, o7, o8, o9) f(o10)
+#define _ZB_FE1_11(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11) \
+  _ZB_FE1_10(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10) f(o11)
+#define _ZB_FE1_12(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12) \
+  _ZB_FE1_11(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11) f(o12)
+#define _ZB_FE1_13(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, \
+                   o13) \
+  _ZB_FE1_12(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12) f(o13)
+#define _ZB_FE1_14(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, \
+                   o13, o14) \
+  _ZB_FE1_13(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13) \
+  f(o14)
+#define _ZB_FE1_15(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, \
+                   o13, o14, o15) \
+  _ZB_FE1_14(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, \
+             o14) f(o15)
+#define _ZB_FE1_16(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, \
+                   o13, o14, o15, o16) \
+  _ZB_FE1_15(f, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, o13, \
+             o14, o15) f(o16)
+
+#define _ZB_FE1_DISPATCH_1(f, ...)
+#define _ZB_FE1_DISPATCH_0(f, ...) \
+  _ZB_CAT(_ZB_FE1_, _ZB_NARG(__VA_ARGS__))(f, __VA_ARGS__)
+
+#define ZBUS_FOR_EACH(f, ...) \
+  _ZB_CAT(_ZB_FE1_DISPATCH_, _ZB_IS_EMPTY(__VA_ARGS__))(f, __VA_ARGS__)
+
+/* ZBUS_OBS_FOR_EACH(F, fixed, ...): expand F(idx2, arg, fixed) for each
+ * argument, where idx2 is the two-digit position of the argument in the
+ * list (00, 01, ... 15).  The two-digit index is what makes the linker's
+ * SORT_BY_NAME() order the channel observations by observer priority.
+ */
+
+#define _ZB_FE2_0(f, x)
+#define _ZB_FE2_1(f, x, o1) f(00, o1, x)
+#define _ZB_FE2_2(f, x, o1, o2) f(00, o1, x) f(01, o2, x)
+#define _ZB_FE2_3(f, x, o1, o2, o3) f(00, o1, x) f(01, o2, x) f(02, o3, x)
+#define _ZB_FE2_4(f, x, o1, o2, o3, o4) \
+  _ZB_FE2_3(f, x, o1, o2, o3) f(03, o4, x)
+#define _ZB_FE2_5(f, x, o1, o2, o3, o4, o5) \
+  _ZB_FE2_4(f, x, o1, o2, o3, o4) f(04, o5, x)
+#define _ZB_FE2_6(f, x, o1, o2, o3, o4, o5, o6) \
+  _ZB_FE2_5(f, x, o1, o2, o3, o4, o5) f(05, o6, x)
+#define _ZB_FE2_7(f, x, o1, o2, o3, o4, o5, o6, o7) \
+  _ZB_FE2_6(f, x, o1, o2, o3, o4, o5, o6) f(06, o7, x)
+#define _ZB_FE2_8(f, x, o1, o2, o3, o4, o5, o6, o7, o8) \
+  _ZB_FE2_7(f, x, o1, o2, o3, o4, o5, o6, o7) f(07, o8, x)
+#define _ZB_FE2_9(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9) \
+  _ZB_FE2_8(f, x, o1, o2, o3, o4, o5, o6, o7, o8) f(08, o9, x)
+#define _ZB_FE2_10(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10) \
+  _ZB_FE2_9(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9) f(09, o10, x)
+#define _ZB_FE2_11(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11) \
+  _ZB_FE2_10(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10) f(10, o11, x)
+#define _ZB_FE2_12(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, \
+                   o12) \
+  _ZB_FE2_11(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11) \
+  f(11, o12, x)
+#define _ZB_FE2_13(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, \
+                   o12, o13) \
+  _ZB_FE2_12(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12) \
+  f(12, o13, x)
+#define _ZB_FE2_14(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, \
+                   o12, o13, o14) \
+  _ZB_FE2_13(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, \
+             o13) f(13, o14, x)
+#define _ZB_FE2_15(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, \
+                   o12, o13, o14, o15) \
+  _ZB_FE2_14(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, \
+             o13, o14) f(14, o15, x)
+#define _ZB_FE2_16(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, \
+                   o12, o13, o14, o15, o16) \
+  _ZB_FE2_15(f, x, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, o11, o12, \
+             o13, o14, o15) f(15, o16, x)
+
+#define _ZB_FE2_DISPATCH_1(f, fixed, ...)
+#define _ZB_FE2_DISPATCH_0(f, fixed, ...) \
+  _ZB_CAT(_ZB_FE2_, _ZB_NARG(__VA_ARGS__))(f, fixed, __VA_ARGS__)
+
+#define ZBUS_OBS_FOR_EACH(f, fixed, ...)                            \

Review Comment:
   move to nuttx/macros.h



##########
system/zbus/zbus_priv.h:
##########
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * apps/system/zbus/zbus_priv.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __APPS_SYSTEM_ZBUS_ZBUS_PRIV_H
+#define __APPS_SYSTEM_ZBUS_ZBUS_PRIV_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <semaphore.h>
+#include <stdint.h>
+#include <time.h>
+
+#include <system/zbus.h>
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* Boundary symbols of the zbus iterable sections */
+
+STRUCT_SECTION_DECLARE(zbus_channel);
+STRUCT_SECTION_DECLARE(zbus_observer);
+STRUCT_SECTION_DECLARE(zbus_channel_observation);
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Deadline computed once per API call and honored by every internal wait */
+
+enum zb_deadline_mode_e
+{
+  ZB_DEADLINE_FOREVER = 0,
+  ZB_DEADLINE_NOWAIT,
+  ZB_DEADLINE_ABS
+};
+
+struct zb_deadline
+{
+  enum zb_deadline_mode_e mode;
+  struct timespec abs;          /* CLOCK_MONOTONIC absolute deadline */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* One-time lazy initialization (observation indexes, observer queues) */
+
+void zbus_port_init_once(void);
+
+/* Deadline helpers */
+
+void zb_deadline_init(int32_t timeout_ms, struct zb_deadline *d);
+
+/* Take a semaphore honoring the deadline.  Returns 0, -EBUSY (no-wait) or
+ * -EAGAIN (timed out).
+ */
+
+int zb_sem_take(sem_t *sem, const struct zb_deadline *d);

Review Comment:
   ```suggestion
   int zbus_sem_take(sem_t *sem, const struct zb_deadline *d);
   ```



##########
system/zbus/zbus_priv.h:
##########
@@ -0,0 +1,85 @@
+/****************************************************************************
+ * apps/system/zbus/zbus_priv.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __APPS_SYSTEM_ZBUS_ZBUS_PRIV_H
+#define __APPS_SYSTEM_ZBUS_ZBUS_PRIV_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <semaphore.h>
+#include <stdint.h>
+#include <time.h>
+
+#include <system/zbus.h>
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/* Boundary symbols of the zbus iterable sections */
+
+STRUCT_SECTION_DECLARE(zbus_channel);
+STRUCT_SECTION_DECLARE(zbus_observer);
+STRUCT_SECTION_DECLARE(zbus_channel_observation);
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Deadline computed once per API call and honored by every internal wait */
+
+enum zb_deadline_mode_e
+{
+  ZB_DEADLINE_FOREVER = 0,
+  ZB_DEADLINE_NOWAIT,
+  ZB_DEADLINE_ABS
+};
+
+struct zb_deadline
+{
+  enum zb_deadline_mode_e mode;
+  struct timespec abs;          /* CLOCK_MONOTONIC absolute deadline */
+};
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/* One-time lazy initialization (observation indexes, observer queues) */
+
+void zbus_port_init_once(void);
+
+/* Deadline helpers */
+
+void zb_deadline_init(int32_t timeout_ms, struct zb_deadline *d);

Review Comment:
   ```suggestion
   void zbus_deadline_init(int32_t timeout_ms, struct zb_deadline *d);
   ```



##########
system/zbus/zbus.c:
##########
@@ -0,0 +1,973 @@
+/****************************************************************************
+ * apps/system/zbus/zbus.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Copyright (c) 2022 Rodrigo Peixoto <[email protected]>
+ * Copyright (c) 2026 NuttX port
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License.  You may obtain
+ * a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+#include <nuttx/mqueue.h>
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <mqueue.h>
+#include <pthread.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <syslog.h>
+
+#include <system/zbus.h>
+
+#include "zbus_priv.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static pthread_once_t g_zbus_once = PTHREAD_ONCE_INIT;
+
+/* Protects observer enabled flags and observation masks */
+
+static pthread_mutex_t g_zbus_obs_lock = PTHREAD_MUTEX_INITIALIZER;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: zb_ts_add_ms / zb_ts_cmp / zb_ts_sub

Review Comment:
   why not use the same prefix zbus_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to