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/incubator-nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 2bd3a17  sched note: printf API example
2bd3a17 is described below

commit 2bd3a1701c3602e454ba9c63a9f7d2669f655f52
Author: zhanghu6 <[email protected]>
AuthorDate: Wed Dec 1 11:06:05 2021 +0800

    sched note: printf API example
    
    test API:
    void sched_note_string(FAR const char *buf);
    void sched_note_dump(uint32_t module, uint8_t event,
                         FAR const void *buf, size_t len);
    void sched_note_printf(FAR const char *fmt, ...) printflike(1, 2);
    void sched_note_bprintf(uint32_t module, uint8_t event,
                            FAR const char *fmt, ...) printflike(3, 4);
    https://github.com/apache/incubator-nuttx/pull/4963
    
    suggestion:
    1. add "&" after the command when running this example.
    2. must enable SCHED_INSTRUMENTATION_DUMP, and that enable 
CONFIG_SYSTEM_TRACE can help you view log.
---
 examples/noteprintf/Kconfig           |  30 ++++++++++
 examples/noteprintf/Make.defs         |  23 ++++++++
 examples/noteprintf/Makefile          |  30 ++++++++++
 examples/noteprintf/noteprintf_main.c | 107 ++++++++++++++++++++++++++++++++++
 4 files changed, 190 insertions(+)

diff --git a/examples/noteprintf/Kconfig b/examples/noteprintf/Kconfig
new file mode 100644
index 0000000..aef99e5
--- /dev/null
+++ b/examples/noteprintf/Kconfig
@@ -0,0 +1,30 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config EXAMPLES_NOTEPRINTF
+       tristate "\"Note printf!\" example"
+       default n
+       depends on SCHED_INSTRUMENTATION_DUMP
+       ---help---
+               Enable the \"Note printf!\" example
+
+if EXAMPLES_NOTEPRINTF
+
+config EXAMPLES_NOTEPRINTF_PROGNAME
+       string "Program name"
+       default "noteprintf"
+       ---help---
+               This is the name of the program that will be used when the NSH 
ELF
+               program is installed.
+
+config EXAMPLES_NOTEPRINTF_PRIORITY
+       int "Note printf task priority"
+       default 100
+
+config EXAMPLES_NOTEPRINTF_STACKSIZE
+       int "Note printf stack size"
+       default DEFAULT_TASK_STACKSIZE
+
+endif
diff --git a/examples/noteprintf/Make.defs b/examples/noteprintf/Make.defs
new file mode 100644
index 0000000..3c48128
--- /dev/null
+++ b/examples/noteprintf/Make.defs
@@ -0,0 +1,23 @@
+############################################################################
+# apps/examples/noteprintf/Make.defs
+#
+# 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.
+#
+############################################################################
+
+ifneq ($(CONFIG_EXAMPLES_NOTEPRINTF),)
+CONFIGURED_APPS += $(APPDIR)/examples/noteprintf
+endif
diff --git a/examples/noteprintf/Makefile b/examples/noteprintf/Makefile
new file mode 100644
index 0000000..79f08d0
--- /dev/null
+++ b/examples/noteprintf/Makefile
@@ -0,0 +1,30 @@
+############################################################################
+# apps/examples/noteprintf/Make.defs
+#
+# 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 $(APPDIR)/Make.defs
+
+PROGNAME  = $(CONFIG_EXAMPLES_NOTEPRINTF_PROGNAME)
+PRIORITY  = $(CONFIG_EXAMPLES_NOTEPRINTF_PRIORITY)
+STACKSIZE = $(CONFIG_EXAMPLES_NOTEPRINTF_STACKSIZE)
+MODULE    = $(CONFIG_EXAMPLES_NOTEPRINTF)
+
+MAINSRC = noteprintf_main.c
+
+include $(APPDIR)/Application.mk
diff --git a/examples/noteprintf/noteprintf_main.c 
b/examples/noteprintf/noteprintf_main.c
new file mode 100644
index 0000000..a12df95
--- /dev/null
+++ b/examples/noteprintf/noteprintf_main.c
@@ -0,0 +1,107 @@
+/****************************************************************************
+ * apps/examples/noteprintf/noteprintf_main.c
+ *
+ * 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 <nuttx/config.h>
+#include <stdio.h>
+
+#include "nuttx/sched_note.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MAIN_MODULE NOTE_MODULE('m', 'a', 'i', 'n')
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * noteprintf_main
+ ****************************************************************************/
+
+int main(int argc, FAR char *argv[])
+{
+  struct binary
+    {
+      uint8_t val1;
+      uint8_t val2;
+    } binary =
+      {
+        .val1        = 0x01,
+        .val2        = 0x02
+      };
+
+  char *str      = "shced note test";
+  int count      = 0;
+  char c         = 1;
+  short s        = 2;
+  int i          = 3;
+  long l         = 4;
+#ifdef CONFIG_LIBC_LONG_LONG
+  long long ll   = 5;
+#endif
+  intmax_t im    = 6;
+  size_t sz      = 7;
+  ptrdiff_t ptr  = 8;
+#ifdef CONFIG_HAVE_FLOAT
+  float f        = 0.1;
+#endif
+#ifdef CONFIG_HAVE_DOUBLE
+  double d       = 0.2;
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+  long double ld = 0.3;
+#endif
+
+  while (1)
+    {
+      sched_note_printf("shced note test count = %d.", count++);
+      sched_note_string(str);
+      sched_note_dump(MAIN_MODULE, 1, &binary, sizeof(struct binary));
+      sched_note_bprintf(MAIN_MODULE, 2, "%hhd", c);
+      sched_note_bprintf(MAIN_MODULE, 3, "%hd", s);
+      sched_note_bprintf(MAIN_MODULE, 4, "%d", i);
+      sched_note_bprintf(MAIN_MODULE, 5, "%ld", l);
+      sched_note_bprintf(MAIN_MODULE, 6, "%lld", ll);
+      sched_note_bprintf(MAIN_MODULE, 7, "%jd", im);
+      sched_note_bprintf(MAIN_MODULE, 8, "%zd", sz);
+      sched_note_bprintf(MAIN_MODULE, 9, "%td", ptr);
+#ifdef CONFIG_HAVE_FLOAT
+      sched_note_bprintf(MAIN_MODULE, 10, "%e", f);
+#endif
+#ifdef CONFIG_HAVE_DOUBLE
+      sched_note_bprintf(MAIN_MODULE, 11, "%le", d);
+#endif
+#ifdef CONFIG_HAVE_LONG_DOUBLE
+      sched_note_bprintf(MAIN_MODULE, 12, "%Le", ld);
+#endif
+      sched_note_bprintf(MAIN_MODULE, 13,
+                         "%hhd  %hd  %d  %ld  %lld  %jd  %zd  %td",
+                          c,    s,   i,  l,    ll,  im,  sz,  ptr);
+      usleep(10);
+    }
+
+  return 0;
+}

Reply via email to