You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/02/01 10:27:01 UTC

[incubator-nuttx] 01/03: drivers/syslog: Implement RTT based log channel

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

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

commit 01b791d77362f4411a10aa3fa8767b6579d0368f
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon Jan 31 16:37:29 2022 +0800

    drivers/syslog: Implement RTT based log channel
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 drivers/segger/Kconfig            |  3 ++-
 drivers/segger/Make.defs          |  4 +++
 drivers/segger/syslog_rtt.c       | 45 ++++++++++++++++++++++++++++++++
 drivers/syslog/Kconfig            | 11 ++++++--
 drivers/syslog/syslog_channel.c   | 25 +++++++++++++++++-
 include/nuttx/syslog/syslog_rtt.h | 54 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 138 insertions(+), 4 deletions(-)

diff --git a/drivers/segger/Kconfig b/drivers/segger/Kconfig
index f5451b5..63ac76b 100644
--- a/drivers/segger/Kconfig
+++ b/drivers/segger/Kconfig
@@ -38,7 +38,8 @@ config SEGGER_RTT_MAX_NUM_DOWN_BUFFERS
 
 config SEGGER_RTT_BUFFER_SIZE_UP
 	int "Segger RTT UP Buffer Size"
-	default 1024
+	default 1024 if SYSLOG_RTT
+	default 1 if !SYSLOG_RTT
 	---help---
 		Size of the buffer for terminal output of target, up to host
 
diff --git a/drivers/segger/Make.defs b/drivers/segger/Make.defs
index 11e343d..6698740 100644
--- a/drivers/segger/Make.defs
+++ b/drivers/segger/Make.defs
@@ -45,6 +45,10 @@ TARGET_ZIP += $(SGDIR)/RTT.zip
 
 endif
 
+ifeq ($(CONFIG_SYSLOG_RTT),y)
+  CSRCS += segger/syslog_rtt.c
+endif
+
 ifeq ($(CONFIG_SEGGER_SYSVIEW),y)
   CSRCS += segger/note_sysview.c
   CSRCS += segger/SystemView/SYSVIEW/SEGGER_SYSVIEW.c
diff --git a/drivers/segger/syslog_rtt.c b/drivers/segger/syslog_rtt.c
new file mode 100644
index 0000000..ed68c88
--- /dev/null
+++ b/drivers/segger/syslog_rtt.c
@@ -0,0 +1,45 @@
+/****************************************************************************
+ * drivers/segger/syslog_rtt.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 <nuttx/syslog/syslog_rtt.h>
+
+#include <SEGGER_RTT.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int syslog_rtt_putc(FAR struct syslog_channel_s *channel, int ch)
+{
+  SEGGER_RTT_PutChar(0, ch);
+  return ch;
+}
+
+ssize_t syslog_rtt_write(FAR struct syslog_channel_s *channel,
+                         FAR const char *buffer, size_t buflen)
+{
+  return SEGGER_RTT_Write(0, buffer, buflen);
+}
diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig
index 29869b3..408aa47 100644
--- a/drivers/syslog/Kconfig
+++ b/drivers/syslog/Kconfig
@@ -203,16 +203,23 @@ config SYSLOG_RPMSG
 	---help---
 		Use the rpmsg as a SYSLOG output device, send message to remote proc.
 
+config SYSLOG_RTT
+	bool "Log to Segger J-Link RTT"
+	select SEGGER_RTT
+	default n
+	---help---
+		Use Segger J-Link RTT as a SYSLOG output device.
+
 config SYSLOG_CONSOLE
 	bool "Log to /dev/console"
-	default !ARCH_LOWPUTC && !SYSLOG_CHAR && !RAMLOG_SYSLOG && !SYSLOG_RPMSG
+	default !ARCH_LOWPUTC && !SYSLOG_CHAR && !RAMLOG_SYSLOG && !SYSLOG_RPMSG && !SYSLOG_RTT
 	depends on DEV_CONSOLE
 	---help---
 		Use the system console as a SYSLOG output device.
 
 config SYSLOG_DEFAULT
 	bool "Default SYSLOG device"
-	default ARCH_LOWPUTC && !SYSLOG_CHAR && !RAMLOG_SYSLOG && !SYSLOG_RPMSG && !SYSLOG_CONSOLE
+	default ARCH_LOWPUTC && !SYSLOG_CHAR && !RAMLOG_SYSLOG && !SYSLOG_RPMSG && !SYSLOG_RTT && !SYSLOG_CONSOLE
 	---help---
 		syslog() interfaces will be present, but all output will go to the
 		up_putc(ARCH_LOWPUTC == y) or bit-bucket(ARCH_LOWPUTC == n).
diff --git a/drivers/syslog/syslog_channel.c b/drivers/syslog/syslog_channel.c
index bff3d8d..ec6cde9 100644
--- a/drivers/syslog/syslog_channel.c
+++ b/drivers/syslog/syslog_channel.c
@@ -40,6 +40,10 @@
 #  include <nuttx/syslog/syslog_rpmsg.h>
 #endif
 
+#ifdef CONFIG_SYSLOG_RTT
+#  include <nuttx/syslog/syslog_rtt.h>
+#endif
+
 #ifdef CONFIG_ARCH_LOWPUTC
 #  include <nuttx/arch.h>
 #endif
@@ -95,6 +99,21 @@ static struct syslog_channel_s g_rpmsg_channel =
 };
 #endif
 
+#if defined(CONFIG_SYSLOG_RTT)
+static const struct syslog_channel_ops_s g_rtt_channel_ops =
+{
+  syslog_rtt_putc,
+  syslog_rtt_putc,
+  NULL,
+  syslog_rtt_write
+};
+
+static struct syslog_channel_s g_rtt_channel =
+{
+  &g_rtt_channel_ops
+};
+#endif
+
 #if defined(CONFIG_SYSLOG_DEFAULT)
 #  if defined(CONFIG_ARCH_LOWPUTC)
 static sem_t g_syslog_default_sem = SEM_INITIALIZER(1);
@@ -128,7 +147,11 @@ FAR struct syslog_channel_s
 #endif
 
 #if defined(CONFIG_SYSLOG_RPMSG)
-  &g_rpmsg_channel
+  &g_rpmsg_channel,
+#endif
+
+#if defined(CONFIG_SYSLOG_RTT)
+  &g_rtt_channel
 #endif
 };
 
diff --git a/include/nuttx/syslog/syslog_rtt.h b/include/nuttx/syslog/syslog_rtt.h
new file mode 100644
index 0000000..9e5014b
--- /dev/null
+++ b/include/nuttx/syslog/syslog_rtt.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+ * include/nuttx/syslog/syslog_rtt.h
+ *
+ * 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_SYSLOG_SYSLOG_RTT_H
+#define __INCLUDE_NUTTX_SYSLOG_SYSLOG_RTT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/syslog/syslog.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+#ifdef CONFIG_SYSLOG_RTT
+int syslog_rtt_putc(FAR struct syslog_channel_s *channel, int ch);
+ssize_t syslog_rtt_write(FAR struct syslog_channel_s *channel,
+                         FAR const char *buffer, size_t buflen);
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __INCLUDE_NUTTX_SYSLOG_SYSLOG_RTT_H */