From 01b791d77362f4411a10aa3fa8767b6579d0368f Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 31 Jan 2022 16:37:29 +0800 Subject: [PATCH] drivers/syslog: Implement RTT based log channel Signed-off-by: Xiang Xiao --- 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(-) create mode 100644 drivers/segger/syslog_rtt.c create mode 100644 include/nuttx/syslog/syslog_rtt.h diff --git a/drivers/segger/Kconfig b/drivers/segger/Kconfig index f5451b5d2e..63ac76b8dc 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 11e343d8f1..6698740812 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 0000000000..ed68c8893b --- /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 + +#include + +#include + +/**************************************************************************** + * 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 29869b31e4..408aa47291 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 bff3d8d1cc..ec6cde95b9 100644 --- a/drivers/syslog/syslog_channel.c +++ b/drivers/syslog/syslog_channel.c @@ -40,6 +40,10 @@ # include #endif +#ifdef CONFIG_SYSLOG_RTT +# include +#endif + #ifdef CONFIG_ARCH_LOWPUTC # include #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 0000000000..9e5014bf1f --- /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 +#include + +/**************************************************************************** + * 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 */