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

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


The following commit(s) were added to refs/heads/master by this push:
     new 9c5a2ad06 mlearning/tflite-micro: add a config option to redirect 
micro log to syslog
9c5a2ad06 is described below

commit 9c5a2ad062069cadc3209186f35338260360efd4
Author: chao an <anc...@lixiang.com>
AuthorDate: Mon Dec 9 13:25:11 2024 +0800

    mlearning/tflite-micro: add a config option to redirect micro log to syslog
    
    new config option TFLITEMICRO_SYSLOG to redirect micro log to syslog
    
    Signed-off-by: chao an <anc...@lixiang.com>
---
 mlearning/tflite-micro/CMakeLists.txt |  4 +++
 mlearning/tflite-micro/Kconfig        | 24 +++++++++++++
 mlearning/tflite-micro/Makefile       |  5 +++
 mlearning/tflite-micro/tflm_syslog.cc | 66 +++++++++++++++++++++++++++++++++++
 4 files changed, 99 insertions(+)

diff --git a/mlearning/tflite-micro/CMakeLists.txt 
b/mlearning/tflite-micro/CMakeLists.txt
index abc9b9fa5..eb5221ec4 100644
--- a/mlearning/tflite-micro/CMakeLists.txt
+++ b/mlearning/tflite-micro/CMakeLists.txt
@@ -101,6 +101,10 @@ if(CONFIG_TFLITEMICRO)
 
   # Remove test file
   list(FILTER TFLITE_MICRO_SRCS EXCLUDE REGEX ".*test.cc")
+  if(CONFIG_TFLITEMICRO_SYSLOG)
+    list(FILTER TFLITE_MICRO_SRCS EXCLUDE REGEX "micro_log.cc")
+    list(APPEND TFLITE_MICRO_SRCS ${CMAKE_CURRENT_LIST_DIR}/tflm_syslog.cc)
+  endif()
 
   if(CONFIG_MLEARNING_CMSIS_NN)
     list(APPEND COMMON_FLAGS -DCMSIS_NN)
diff --git a/mlearning/tflite-micro/Kconfig b/mlearning/tflite-micro/Kconfig
index 06193fff1..359ea5819 100644
--- a/mlearning/tflite-micro/Kconfig
+++ b/mlearning/tflite-micro/Kconfig
@@ -32,6 +32,30 @@ config TFLITEMICRO_TOOL
        bool "tflite-micro cmdline tool"
        default n
 
+config TFLITEMICRO_SYSLOG
+       bool "tflite-micro syslog backend"
+       default n
+
+if TFLITEMICRO_SYSLOG
+
+config TFLITEMICRO_SYSLOG_LEVEL
+       int "tflite-micro syslog level"
+       default 6
+       ---help---
+               Syslog level mapping of tflm, This log level mapping is 
consistent
+               with the nuttx syslog level, please refer to syslog.h:
+
+               define LOG_EMERG     0  /* System is unusable */
+               define LOG_ALERT     1  /* Action must be taken immediately */
+               define LOG_CRIT      2  /* Critical conditions */
+               define LOG_ERR       3  /* Error conditions */
+               define LOG_WARNING   4  /* Warning conditions */
+               define LOG_NOTICE    5  /* Normal, but significant, condition */
+               define LOG_INFO      6  /* Informational message */
+               define LOG_DEBUG     7  /* Debug-level message */
+
+endif # TFLITEMICRO_SYSLOG
+
 if TFLITEMICRO_TOOL
 config TFLITEMICRO_TOOL_PRIORITY
        int "tflite-micro tool priority"
diff --git a/mlearning/tflite-micro/Makefile b/mlearning/tflite-micro/Makefile
index b5dbd7f81..dd0c1c6ad 100644
--- a/mlearning/tflite-micro/Makefile
+++ b/mlearning/tflite-micro/Makefile
@@ -78,6 +78,11 @@ CXXSRCS += $(wildcard 
$(TFLM_DIR)/tensorflow/lite/micro/tflite_bridge/*.cc)
 CXXSRCS += $(wildcard $(TFLM_DIR)/tensorflow/lite/schema/*.cc)
 CXXSRCS := $(filter-out %test.cc, $(CXXSRCS))
 
+ifneq ($(CONFIG_TFLITEMICRO_SYSLOG),)
+  CXXSRCS := $(filter-out %micro_log.cc, $(CXXSRCS))
+  CXXSRCS += $(wildcard $(CURDIR)/tflm_syslog.cc)
+endif
+
 # cmsis
 ifneq ($(CONFIG_MLEARNING_CMSIS_NN),)
 COMMON_FLAGS += -DCMSIS_NN
diff --git a/mlearning/tflite-micro/tflm_syslog.cc 
b/mlearning/tflite-micro/tflm_syslog.cc
new file mode 100644
index 000000000..f306a9153
--- /dev/null
+++ b/mlearning/tflite-micro/tflm_syslog.cc
@@ -0,0 +1,66 @@
+/****************************************************************************
+ * apps/mlearning/tflite-micro/tflm_syslog.cc
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#include "tensorflow/lite/micro/micro_log.h"
+
+#include <syslog.h>
+#include <stdio.h>
+
+#if !defined(TF_LITE_STRIP_ERROR_STRINGS)
+#include "tensorflow/lite/micro/debug_log.h"
+#endif
+
+#if !defined(TF_LITE_STRIP_ERROR_STRINGS)
+
+void VMicroPrintf(FAR const char *format, va_list ap)
+{
+  vsyslog(CONFIG_TFLITEMICRO_SYSLOG_LEVEL, format, ap);
+}
+
+void MicroPrintf(FAR const char *format, ...)
+{
+  va_list ap;
+
+  /* Let vsyslog do the work */
+
+  va_start(ap, format);
+  vsyslog(CONFIG_TFLITEMICRO_SYSLOG_LEVEL, format, ap);
+  va_end(ap);
+}
+
+int MicroSnprintf(FAR char *buffer, size_t buf_size, FAR const char *format, 
...)
+{
+  va_list ap;
+  int ret;
+
+  va_start(ap, format);
+  ret = vsnprintf(buffer, buf_size, format, ap);
+  va_end(ap);
+
+  return ret;
+}
+
+int MicroVsnprintf(FAR char *buffer, size_t buf_size,
+                   FAR const char *format, va_list vlist)
+{
+  return vsnprintf(buffer, buf_size, format, vlist);
+}
+
+#endif  // !defined(TF_LITE_STRIP_ERROR_STRINGS)

Reply via email to