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.git


The following commit(s) were added to refs/heads/master by this push:
     new e14f23226b9 include/nuttx: add unified tag header tag.h
e14f23226b9 is described below

commit e14f23226b9f130339f64844155192b61338b42f
Author: cuiziwei <[email protected]>
AuthorDate: Tue Mar 24 18:28:40 2026 +0800

    include/nuttx: add unified tag header tag.h
    
    Add tag.h and lib_tag.c as the unified tag definition for
    kernel and user-space tracing subsystems. All kernel tags
    are auto-numbered via enum with NXTAG_ prefix. User-extension
    tags start from NXTAG_USER_BASE(64) with NXTAG_MAX(128).
    Bitmask helpers and nxtag_get_name API are provided for
    runtime tag management. User-space frameworks can define
    g_user_names to register custom tag names visible through
    nxtag_get_name.
    
    Signed-off-by: cuiziwei <[email protected]>
---
 include/nuttx/tag.h           | 141 ++++++++++++++++++++++++++++++++++++++++++
 libs/libc/misc/CMakeLists.txt |   2 +
 libs/libc/misc/Make.defs      |   1 +
 libs/libc/misc/lib_tag.c      | 110 ++++++++++++++++++++++++++++++++
 4 files changed, 254 insertions(+)

diff --git a/include/nuttx/tag.h b/include/nuttx/tag.h
new file mode 100644
index 00000000000..e4a3966a5c1
--- /dev/null
+++ b/include/nuttx/tag.h
@@ -0,0 +1,141 @@
+/****************************************************************************
+ * include/nuttx/tag.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 __INCLUDE_NUTTX_TAG_H
+#define __INCLUDE_NUTTX_TAG_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdint.h>
+#include <string.h>
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* Unified tag enumeration -- single source of truth for all tags.
+ * Auto-numbered; add new entries alphabetically before NXTAG_KERNEL_LAST.
+ */
+
+enum nxtag_e
+{
+  NXTAG_ANALOG,
+  NXTAG_AUDIO,
+  NXTAG_BATTERY,
+  NXTAG_BINFMT,
+  NXTAG_CAN,
+  NXTAG_CAPTURE,
+  NXTAG_CONTACTLESS,
+  NXTAG_CRYPTO,
+  NXTAG_DMA,
+  NXTAG_FS,
+  NXTAG_GPIO,
+  NXTAG_GRAPHICS,
+  NXTAG_HWTRACING,
+  NXTAG_I2C,
+  NXTAG_I2S,
+  NXTAG_I3C,
+  NXTAG_INPUT,
+  NXTAG_IPC,
+  NXTAG_IRQ,
+  NXTAG_LCD,
+  NXTAG_LEDS,
+  NXTAG_LIB,
+  NXTAG_MEMCARD,
+  NXTAG_MM,
+  NXTAG_MOTOR,
+  NXTAG_NET,
+  NXTAG_PAGING,
+  NXTAG_PCI,
+  NXTAG_POWER,
+  NXTAG_PTP,
+  NXTAG_PWM,
+  NXTAG_RC,
+  NXTAG_REGMAP,
+  NXTAG_RESET,
+  NXTAG_RMT,
+  NXTAG_RPMSG,
+  NXTAG_RPTUN,
+  NXTAG_RTC,
+  NXTAG_SAFETY,
+  NXTAG_SCHED,
+  NXTAG_SENSORS,
+  NXTAG_SPI,
+  NXTAG_STEPPER,
+  NXTAG_SYSCALL,
+  NXTAG_THERMAL,
+  NXTAG_TIMER,
+  NXTAG_USB,
+  NXTAG_VHOST,
+  NXTAG_VIDEO,
+  NXTAG_VIRTIO,
+  NXTAG_WATCHDOG,
+  NXTAG_WIRELESS,
+  NXTAG_KERNEL_MAX,
+
+  NXTAG_USER_BASE = 128,
+  NXTAG_MAX = 255
+};
+
+/* Bitmask helpers for tag enable/disable masks.
+ * A mask is an array of uint8_t with NXTAG_MASK_SIZE bytes.
+ */
+
+#define NXTAG_MASK_SIZE             ((NXTAG_MAX + 7) / 8)
+#define NXTAG_MASK_SET(mask, tag)   ((mask)[(tag) / 8] |= (1u << ((tag) % 8)))
+#define NXTAG_MASK_CLR(mask, tag)   ((mask)[(tag) / 8] &= ~(1u << ((tag) % 8)))
+#define NXTAG_MASK_ISSET(mask, tag) ((mask)[(tag) / 8] & (1u << ((tag) % 8)))
+#define NXTAG_MASK_ZERO(mask)       memset((mask), 0, NXTAG_MASK_SIZE)
+#define NXTAG_MASK_FILL(mask)       memset((mask), 0xff, NXTAG_MASK_SIZE)
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/****************************************************************************
+ * Name: nxtag_get_name
+ *
+ * Description:
+ *   Get the human-readable name for a tag (kernel or user).
+ *
+ * Input Parameters:
+ *   tag - Tag value (0..NXTAG_MAX-1)
+ *
+ * Returned Value:
+ *   Pointer to name string, or NULL if not registered.
+ *
+ ****************************************************************************/
+
+FAR const char *nxtag_get_name(uint8_t tag);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __INCLUDE_NUTTX_TAG_H */
diff --git a/libs/libc/misc/CMakeLists.txt b/libs/libc/misc/CMakeLists.txt
index e577ffebef7..3334e8e4702 100644
--- a/libs/libc/misc/CMakeLists.txt
+++ b/libs/libc/misc/CMakeLists.txt
@@ -142,6 +142,8 @@ if(CONFIG_FDCHECK)
   list(APPEND SRCS lib_fdcheck.c)
 endif()
 
+list(APPEND SRCS lib_tag.c)
+
 if(CONFIG_SCHED_INSTRUMENTATION_DUMP)
   list(APPEND SRCS lib_note.c)
 endif()
diff --git a/libs/libc/misc/Make.defs b/libs/libc/misc/Make.defs
index 3e3bc942123..01aa6a6aa8d 100644
--- a/libs/libc/misc/Make.defs
+++ b/libs/libc/misc/Make.defs
@@ -56,6 +56,7 @@ CSRCS += lib_crc8h1d.c lib_crc8h2f.c lib_crc16h1021.c 
lib_crc16h8005.c
 CSRCS += lib_crc32h04c11db7.c lib_crc32hf4acfb13.c lib_crc64emac.c
 CSRCS += lib_backtrace.c lib_ftok.c lib_err.c lib_instrument.c lib_glob.c
 CSRCS += lib_crc16ibm.c lib_crc16xmodem.c lib_xorsum16.c
+CSRCS += lib_fdcheck.c lib_tag.c
 
 # Keyboard driver encoder/decoder
 
diff --git a/libs/libc/misc/lib_tag.c b/libs/libc/misc/lib_tag.c
new file mode 100644
index 00000000000..e338aaa5e31
--- /dev/null
+++ b/libs/libc/misc/lib_tag.c
@@ -0,0 +1,110 @@
+/****************************************************************************
+ * libs/libc/misc/lib_tag.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stddef.h>
+#include <sys/param.h>
+
+#include <nuttx/tag.h>
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Kernel tag names -- order must match enum nxtag_e exactly */
+
+static FAR const char *const g_nxtag_names[] =
+{
+  "analog",
+  "audio",
+  "battery",
+  "binfmt",
+  "can",
+  "capture",
+  "contactless",
+  "crypto",
+  "dma",
+  "fs",
+  "gpio",
+  "graphics",
+  "hwtracing",
+  "i2c",
+  "i2s",
+  "i3c",
+  "input",
+  "ipc",
+  "irq",
+  "lcd",
+  "leds",
+  "lib",
+  "memcard",
+  "mm",
+  "motor",
+  "net",
+  "paging",
+  "pci",
+  "power",
+  "ptp",
+  "pwm",
+  "rc",
+  "regmap",
+  "reset",
+  "rmt",
+  "rpmsg",
+  "rptun",
+  "rtc",
+  "safety",
+  "sched",
+  "sensors",
+  "spi",
+  "stepper",
+  "syscall",
+  "thermal",
+  "timer",
+  "usb",
+  "vhost",
+  "video",
+  "virtio",
+  "watchdog",
+  "wireless",
+};
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxtag_get_name
+ ****************************************************************************/
+
+FAR const char *nxtag_get_name(uint8_t tag)
+{
+  if (tag < nitems(g_nxtag_names))
+    {
+      return g_nxtag_names[tag];
+    }
+
+  return NULL;
+}

Reply via email to