You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/01/29 09:26:17 UTC
[incubator-nuttx] 01/05: note/sysview: add Segger System View support
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.git
commit e04ccba78aa1dacf92c321b1f9b1466c81283ede
Author: chao.an <an...@xiaomi.com>
AuthorDate: Fri Jan 21 20:00:26 2022 +0800
note/sysview: add Segger System View support
Reference:
https://www.segger.com/products/development-tools/systemview
https://github.com/SEGGERMicro/SystemView
https://github.com/SEGGERMicro/RTT
Signed-off-by: chao.an <an...@xiaomi.com>
---
drivers/Kconfig | 1 +
drivers/Makefile | 1 +
drivers/note/Kconfig | 12 +
drivers/note/note_driver.c | 9 +
drivers/segger/.gitignore | 2 +
drivers/segger/Kconfig | 67 +++
drivers/segger/Make.defs | 41 ++
.../{note/note_driver.c => segger/config/Global.h} | 60 +--
drivers/segger/config/SEGGER_RTT_Conf.h | 84 ++++
.../config/SEGGER_SYSVIEW_Conf.h} | 78 ++--
drivers/segger/note_sysview.c | 493 +++++++++++++++++++++
.../nuttx/note/note_sysview.h | 39 +-
12 files changed, 783 insertions(+), 104 deletions(-)
diff --git a/drivers/Kconfig b/drivers/Kconfig
index e5cf67c..45ea433 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -133,3 +133,4 @@ source "drivers/rf/Kconfig"
source "drivers/rc/Kconfig"
source "drivers/motor/Kconfig"
source "drivers/math/Kconfig"
+source "drivers/segger/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index 9b226a5..94c1460 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -64,6 +64,7 @@ include contactless/Make.defs
include 1wire/Make.defs
include rf/Make.defs
include rc/Make.defs
+include segger/Make.defs
ifeq ($(CONFIG_SPECIFIC_DRIVERS),y)
-include platform/Make.defs
diff --git a/drivers/note/Kconfig b/drivers/note/Kconfig
index 646f919..cc81864 100644
--- a/drivers/note/Kconfig
+++ b/drivers/note/Kconfig
@@ -52,6 +52,18 @@ config DRIVER_NOTELOG
---help---
The note driver output to syslog.
+config SEGGER_SYSVIEW
+ bool "Note SEGGER SystemView driver"
+ select SEGGER_RTT
+ select SCHED_INSTRUMENTATION_EXTERNAL
+ ---help---
+ SystemView is a real-time recording and visualization tool for embedded
+ systems that reveals the true runtime behavior of an application,
+ going far deeper than the system insights provided by debuggers. This is
+ particularly effective when developing and working with complex embedded
+ systems comprising multiple threads and interrupts. SystemView can ensure
+ unintended interactions and resource conflicts.
+
endchoice
config DRIVER_NOTERAM_BUFSIZE
diff --git a/drivers/note/note_driver.c b/drivers/note/note_driver.c
index 93c2466..7bdd26a 100644
--- a/drivers/note/note_driver.c
+++ b/drivers/note/note_driver.c
@@ -23,6 +23,7 @@
****************************************************************************/
#include <nuttx/note/note_driver.h>
+#include <nuttx/note/note_sysview.h>
#include <nuttx/note/noteram_driver.h>
#include <nuttx/note/notectl_driver.h>
@@ -65,5 +66,13 @@ int note_register(void)
}
#endif
+#ifdef CONFIG_SEGGER_SYSVIEW
+ ret = sysview_initialize();
+ if (ret < 0)
+ {
+ return ret;
+ }
+#endif
+
return ret;
}
diff --git a/drivers/segger/.gitignore b/drivers/segger/.gitignore
new file mode 100644
index 0000000..481d748
--- /dev/null
+++ b/drivers/segger/.gitignore
@@ -0,0 +1,2 @@
+/RTT
+/SystemView
diff --git a/drivers/segger/Kconfig b/drivers/segger/Kconfig
new file mode 100644
index 0000000..f5451b5
--- /dev/null
+++ b/drivers/segger/Kconfig
@@ -0,0 +1,67 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config SEGGER_RTT
+ bool
+ ---help---
+ Enable Segger J-Link RTT libraries for platforms that support it.
+ Selection of this option enables use of RTT for various subsystems.
+ Note that by enabling this option, RTT buffers consume more RAM.
+
+if SEGGER_RTT
+
+config SEGGER_RTT_CPU_CACHE_LINE_SIZE
+ int "Segger RTT Cache Line Size"
+ default 0
+ ---help---
+ Largest cache line size (in bytes) in the target system.
+
+config SEGGER_RTT_UNCACHED_OFF
+ int "Segger RTT uncached offset"
+ default 0
+ ---help---
+ Address alias where RTT CB and buffers can be accessed uncached
+
+config SEGGER_RTT_MAX_NUM_UP_BUFFERS
+ int "Segger RTT Maximum Number of UP Buffers"
+ default 3
+ ---help---
+ Number of up-buffers (T->H) available on this target
+
+config SEGGER_RTT_MAX_NUM_DOWN_BUFFERS
+ int "Segger RTT Maximum Number of Down Buffers"
+ default 3
+ ---help---
+ Number of down-buffers (H->T) available on this target
+
+config SEGGER_RTT_BUFFER_SIZE_UP
+ int "Segger RTT UP Buffer Size"
+ default 1024
+ ---help---
+ Size of the buffer for terminal output of target, up to host
+
+config SEGGER_RTT_BUFFER_SIZE_DOWN
+ int "Segger RTT Down Buffer Size"
+ default 16
+ ---help---
+ Size of the buffer for terminal input to target from host (Usually keyboard input)
+
+if SEGGER_SYSVIEW
+
+config SEGGER_SYSVIEW_RTT_BUFFER_SIZE
+ int "Segger System View buffer size"
+ default 1024
+ ---help---
+ Number of bytes that SystemView uses for the RTT buffer.
+
+config SEGGER_SYSVIEW_RAM_BASE
+ int "Segger System View Ram Base"
+ default 0
+ ---help---
+ The lowest RAM address used for IDs
+
+endif
+
+endif
diff --git a/drivers/segger/Make.defs b/drivers/segger/Make.defs
new file mode 100644
index 0000000..902f063
--- /dev/null
+++ b/drivers/segger/Make.defs
@@ -0,0 +1,41 @@
+############################################################################
+# drivers/segger/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.
+#
+############################################################################
+
+ifeq ($(CONFIG_SEGGER_RTT),y)
+ CSRCS += segger/RTT/RTT/SEGGER_RTT.c
+
+ CFLAGS += -Wno-shadow -Wno-array-bounds
+
+ CFLAGS += ${shell $(INCDIR) "$(CC)" segger$(DELIM)config}
+ CFLAGS += ${shell $(INCDIR) "$(CC)" segger$(DELIM)RTT$(DELIM)RTT}
+
+ ifeq ($(CONFIG_ARCH_ARMV7M),y)
+ ASRCS += segger/RTT/RTT/SEGGER_RTT_ASM_ARMv7M.S
+ endif
+endif
+
+ifeq ($(CONFIG_SEGGER_SYSVIEW),y)
+ CSRCS += segger/note_sysview.c
+ CSRCS += segger/SystemView/SYSVIEW/SEGGER_SYSVIEW.c
+
+ CFLAGS += ${shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)sched}
+ CFLAGS += ${shell $(INCDIR) "$(CC)" segger$(DELIM)SystemView$(DELIM)SEGGER}
+ CFLAGS += ${shell $(INCDIR) "$(CC)" segger$(DELIM)SystemView$(DELIM)SYSVIEW}
+endif
diff --git a/drivers/note/note_driver.c b/drivers/segger/config/Global.h
similarity index 59%
copy from drivers/note/note_driver.c
copy to drivers/segger/config/Global.h
index 93c2466..5d63230 100644
--- a/drivers/note/note_driver.c
+++ b/drivers/segger/config/Global.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * drivers/note/note_driver.c
+ * drivers/segger/config/Global.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -18,52 +18,28 @@
*
****************************************************************************/
+#ifndef __DRIVERS_SEGGER_CONFIG_GLOBAL_H
+#define __DRIVERS_SEGGER_CONFIG_GLOBAL_H
+
/****************************************************************************
* Included Files
****************************************************************************/
-#include <nuttx/note/note_driver.h>
-#include <nuttx/note/noteram_driver.h>
-#include <nuttx/note/notectl_driver.h>
+#include <nuttx/config.h>
+#include <stdint.h>
/****************************************************************************
- * Public Functions
+ * Pre-processor Definitions
****************************************************************************/
-/****************************************************************************
- * Name: note_register
- *
- * Description:
- * Register sched note related drivers at /dev folder that can be used by
- * an application to read or filter the note data.
- *
- * Input Parameters:
- * None.
- *
- * Returned Value:
- * Zero on succress. A negated errno value is returned on a failure.
- *
- ****************************************************************************/
-
-int note_register(void)
-{
- int ret = 0;
-
-#ifdef CONFIG_DRIVER_NOTERAM
- ret = noteram_register();
- if (ret < 0)
- {
- return ret;
- }
-#endif
-
-#ifdef CONFIG_DRIVER_NOTECTL
- ret = notectl_register();
- if (ret < 0)
- {
- return ret;
- }
-#endif
-
- return ret;
-}
+#define U8 uint8_t
+#define I8 int8_t
+#define U16 uint16_t
+#define I16 int16_t
+#define U32 uint32_t
+#define I32 int32_t
+#define U64 uint64_t
+#define I64 int64_t
+#define PTR_ADDR uintptr_t
+
+#endif /* __DRIVERS_SEGGER_CONFIG_GLOBAL_H */
diff --git a/drivers/segger/config/SEGGER_RTT_Conf.h b/drivers/segger/config/SEGGER_RTT_Conf.h
new file mode 100644
index 0000000..5de85b9
--- /dev/null
+++ b/drivers/segger/config/SEGGER_RTT_Conf.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * drivers/segger/config/SEGGER_RTT_Conf.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 __DRIVERS_SEGGER_CONFIG_SEGGER_RTT_CONF_H
+#define __DRIVERS_SEGGER_CONFIG_SEGGER_RTT_CONF_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <nuttx/spinlock.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Take in and set to correct values for Cortex systems with CPU cache */
+
+/* Largest cache line size (in bytes) in the current system */
+
+#define SEGGER_RTT_CPU_CACHE_LINE_SIZE CONFIG_SEGGER_RTT_CPU_CACHE_LINE_SIZE
+
+/* Address alias where RTT CB and buffers can be accessed uncached */
+
+#define SEGGER_RTT_UNCACHED_OFF CONFIG_SEGGER_RTT_UNCACHED_OFF
+
+/* Number of up-buffers (T->H) available on this target */
+
+#define SEGGER_RTT_MAX_NUM_UP_BUFFERS CONFIG_SEGGER_RTT_MAX_NUM_UP_BUFFERS
+
+/* Number of down-buffers (H->T) available on this target */
+
+#define SEGGER_RTT_MAX_NUM_DOWN_BUFFERS CONFIG_SEGGER_RTT_MAX_NUM_DOWN_BUFFERS
+
+/* Size of the buffer for terminal output of target, up to host */
+
+#define BUFFER_SIZE_UP CONFIG_SEGGER_RTT_BUFFER_SIZE_UP
+
+/* Size of the buffer for terminal input to target from host */
+
+#define BUFFER_SIZE_DOWN CONFIG_SEGGER_RTT_BUFFER_SIZE_DOWN
+
+/* Mode for pre-initialized terminal channel */
+
+#define SEGGER_RTT_MODE_DEFAULT SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
+
+/* 0: Use memcpy/SEGGER_RTT_MEMCPY, 1: Use a simple byte-loop */
+
+#define SEGGER_RTT_MEMCPY_USE_BYTELOOP 0
+
+/* RTT lock configuration */
+
+/* Lock RTT (nestable) (i.e. disable interrupts) */
+
+#define SEGGER_RTT_LOCK() irqstate_t __flags = spin_lock_irqsave(NULL)
+
+/* Unlock RTT (nestable) (i.e. enable previous interrupt lock state) */
+
+#define SEGGER_RTT_UNLOCK() spin_unlock_irqrestore(NULL, __flags)
+
+/* Disable RTT SEGGER_RTT_WriteSkipNoLock */
+
+#define RTT_USE_ASM 0
+
+#endif /* __DRIVERS_SEGGER_CONFIG_SEGGER_RTT_CONF_H */
diff --git a/drivers/note/note_driver.c b/drivers/segger/config/SEGGER_SYSVIEW_Conf.h
similarity index 51%
copy from drivers/note/note_driver.c
copy to drivers/segger/config/SEGGER_SYSVIEW_Conf.h
index 93c2466..6dcadb1 100644
--- a/drivers/note/note_driver.c
+++ b/drivers/segger/config/SEGGER_SYSVIEW_Conf.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * drivers/note/note_driver.c
+ * drivers/segger/config/SEGGER_SYSVIEW_Conf.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -18,52 +18,62 @@
*
****************************************************************************/
+#ifndef __DRIVERS_SEGGER_CONFIG_SEGGER_SYSVIEW_CONF_H
+#define __DRIVERS_SEGGER_CONFIG_SEGGER_SYSVIEW_CONF_H
+
/****************************************************************************
* Included Files
****************************************************************************/
-#include <nuttx/note/note_driver.h>
-#include <nuttx/note/noteram_driver.h>
-#include <nuttx/note/notectl_driver.h>
+#include <nuttx/config.h>
/****************************************************************************
- * Public Functions
+ * Pre-processor Definitions
****************************************************************************/
+/* Function macro to retrieve the Id of the currently active interrupt.
+ * Call user-supplied function SEGGER_SYSVIEW_X_GetInterruptId().
+ */
+
+#define SEGGER_SYSVIEW_GET_INTERRUPT_ID sysview_get_interrupt_id
+
+/* Function macro to retrieve a system timestamp for SYSVIEW events.
+ * Call user-supplied function SEGGER_SYSVIEW_X_GetTimestamp().
+ */
+
+#define SEGGER_SYSVIEW_GET_TIMESTAMP sysview_get_timestamp
+
+/* Number of bytes that SystemView uses for the RTT buffer. */
+
+#define SEGGER_SYSVIEW_RTT_BUFFER_SIZE CONFIG_SEGGER_SYSVIEW_RTT_BUFFER_SIZE
+
+/* Largest cache line size (in bytes) in the target system. */
+
+#define SEGGER_SYSVIEW_CPU_CACHE_LINE_SIZE CONFIG_SEGGER_RTT_CPU_CACHE_LINE_SIZE
+
/****************************************************************************
- * Name: note_register
- *
- * Description:
- * Register sched note related drivers at /dev folder that can be used by
- * an application to read or filter the note data.
- *
- * Input Parameters:
- * None.
- *
- * Returned Value:
- * Zero on succress. A negated errno value is returned on a failure.
- *
+ * Public Data
****************************************************************************/
-int note_register(void)
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
{
- int ret = 0;
-
-#ifdef CONFIG_DRIVER_NOTERAM
- ret = noteram_register();
- if (ret < 0)
- {
- return ret;
- }
+#else
+#define EXTERN extern
#endif
-#ifdef CONFIG_DRIVER_NOTECTL
- ret = notectl_register();
- if (ret < 0)
- {
- return ret;
- }
-#endif
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+unsigned int sysview_get_interrupt_id(void);
+unsigned int sysview_get_timestamp(void);
- return ret;
+#undef EXTERN
+#if defined(__cplusplus)
}
+#endif
+
+#endif /* __DRIVERS_SEGGER_CONFIG_SEGGER_SYSVIEW_CONF_H */
diff --git a/drivers/segger/note_sysview.c b/drivers/segger/note_sysview.c
new file mode 100644
index 0000000..053eb1a
--- /dev/null
+++ b/drivers/segger/note_sysview.c
@@ -0,0 +1,493 @@
+/****************************************************************************
+ * drivers/segger/note_sysview.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 <syslog.h>
+
+#include <nuttx/clock.h>
+#include <nuttx/sched.h>
+#include <nuttx/sched_note.h>
+
+#include <SEGGER_RTT.h>
+#include <SEGGER_SYSVIEW.h>
+
+#include "sched/sched.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct sysview_s
+{
+ unsigned int irq[CONFIG_SMP_NCPUS];
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+ struct note_filter_mode_s mode;
+#endif
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+ struct note_filter_irq_s irq_mask;
+#endif
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct sysview_s g_sysview =
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+ .mode =
+ {
+ .flag = CONFIG_SCHED_INSTRUMENTATION_FILTER_DEFAULT_MODE,
+#ifdef CONFIG_SMP
+ .cpuset = CONFIG_SCHED_INSTRUMENTATION_CPUSET,
+#endif
+ }
+#endif
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sysview_send_taskinfo
+ ****************************************************************************/
+
+static void sysview_send_taskinfo(FAR struct tcb_s *tcb)
+{
+ SEGGER_SYSVIEW_TASKINFO info;
+
+ info.TaskID = tcb->pid;
+ info.sName = tcb->name;
+ info.Prio = tcb->sched_priority;
+ info.StackBase = (uintptr_t)tcb->stack_base_ptr;
+ info.StackSize = tcb->adj_stack_size;
+
+ SEGGER_SYSVIEW_SendTaskInfo(&info);
+}
+
+/****************************************************************************
+ * Name: sysview_get_time
+ ****************************************************************************/
+
+static uint64_t sysview_get_time(void)
+{
+ return TICK2USEC(clock_systime_ticks());
+}
+
+/****************************************************************************
+ * Name: sysview_send_tasklist
+ ****************************************************************************/
+
+static void sysview_send_tasklist(void)
+{
+ int i;
+
+ for (i = 0; i < g_npidhash; i++)
+ {
+ if (g_pidhash[i] != NULL)
+ {
+ sysview_send_taskinfo(g_pidhash[i]);
+ }
+ }
+}
+
+/****************************************************************************
+ * Name: sysview_send_description
+ ****************************************************************************/
+
+static void sysview_send_description(void)
+{
+ SEGGER_SYSVIEW_SendSysDesc("N="SEGGER_SYSVIEW_APP_NAME);
+ SEGGER_SYSVIEW_SendSysDesc("D="CONFIG_LIBC_HOSTNAME);
+ SEGGER_SYSVIEW_SendSysDesc("O=NuttX");
+}
+
+/****************************************************************************
+ * Name: sysview_isenabled
+ *
+ * Description:
+ * Check whether the instrumentation is enabled.
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * True is returned if the instrumentation is enabled.
+ *
+ ****************************************************************************/
+
+static bool sysview_isenabled(void)
+{
+ bool enable;
+
+ enable = SEGGER_SYSVIEW_IsStarted();
+
+#if defined(CONFIG_SCHED_INSTRUMENTATION_FILTER) && defined(CONFIG_SMP)
+ /* Ignore notes that are not in the set of monitored CPUs */
+
+ if (enable && (g_sysview.mode.cpuset & (1 << this_cpu())) == 0)
+ {
+ /* Not in the set of monitored CPUs. Do not log the note. */
+
+ return false;
+ }
+#endif
+
+ return enable;
+}
+
+/****************************************************************************
+ * Name: sysview_isenabled_irqhandler
+ *
+ * Description:
+ * Check whether the interrupt handler instrumentation is enabled.
+ *
+ * Input Parameters:
+ * irq - IRQ number
+ * enter - interrupt enter/leave flag
+ *
+ * Returned Value:
+ * True is returned if the instrumentation is enabled.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+static bool sysview_isenabled_irq(int irq, bool enter)
+{
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+ if (!sysview_isenabled())
+ {
+ return false;
+ }
+
+ /* If the IRQ trace is disabled or the IRQ number is masked, disable
+ * subsequent syscall traces until leaving the interrupt handler
+ */
+
+ if ((g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_IRQ) == 0 ||
+ NOTE_FILTER_IRQMASK_ISSET(irq, &g_sysview.irq_mask))
+ {
+ return false;
+ }
+#endif
+
+ return true;
+}
+#endif
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sched_note_start, sched_note_stop, sched_note_switch,
+ * sched_note_premption
+ *
+ * Description:
+ * Hooks to scheduler monitor
+ *
+ * Input Parameters:
+ * Varies
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void sched_note_start(FAR struct tcb_s *tcb)
+{
+ if (!sysview_isenabled())
+ {
+ return;
+ }
+
+ SEGGER_SYSVIEW_OnTaskCreate(tcb->pid);
+ sysview_send_taskinfo(tcb);
+}
+
+void sched_note_stop(FAR struct tcb_s *tcb)
+{
+ if (!sysview_isenabled())
+ {
+ return;
+ }
+
+ SEGGER_SYSVIEW_OnTaskTerminate(tcb->pid);
+}
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH
+void sched_note_suspend(FAR struct tcb_s *tcb)
+{
+ if (!sysview_isenabled())
+ {
+ return;
+ }
+
+ if (!up_interrupt_context())
+ {
+ SEGGER_SYSVIEW_OnTaskStopExec();
+ }
+}
+
+void sched_note_resume(FAR struct tcb_s *tcb)
+{
+ if (!sysview_isenabled())
+ {
+ return;
+ }
+
+ if (!up_interrupt_context())
+ {
+ if (tcb->flink == NULL)
+ {
+ SEGGER_SYSVIEW_OnIdle();
+ }
+ else
+ {
+ SEGGER_SYSVIEW_OnTaskStartExec(tcb->pid);
+ }
+ }
+}
+#endif
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+void sched_note_irqhandler(int irq, FAR void *handler, bool enter)
+{
+ if (!sysview_isenabled_irq(irq, enter))
+ {
+ return;
+ }
+
+ if (enter)
+ {
+ g_sysview.irq[up_cpu_index()] = irq;
+
+ SEGGER_SYSVIEW_OnTaskStopExec();
+ SEGGER_SYSVIEW_RecordEnterISR();
+ }
+ else
+ {
+ SEGGER_SYSVIEW_RecordExitISR();
+
+ if (up_interrupt_context())
+ {
+ FAR struct tcb_s *tcb = this_task();
+
+ if (tcb && tcb->flink != NULL)
+ {
+ SEGGER_SYSVIEW_OnTaskStartExec(tcb->pid);
+ }
+ else
+ {
+ SEGGER_SYSVIEW_OnIdle();
+ }
+ }
+
+ g_sysview.irq[up_cpu_index()] = 0;
+ }
+}
+#endif
+
+/****************************************************************************
+ * Name: sysview_get_interrupt_id
+ *
+ * Description:
+ * Retrieve the Id of the currently active interrupt.
+ *
+ ****************************************************************************/
+
+unsigned int sysview_get_interrupt_id(void)
+{
+ return g_sysview.irq[up_cpu_index()];
+}
+
+/****************************************************************************
+ * Name: sysview_get_timestamp
+ *
+ * Description:
+ * Retrieve a system timestamp for SYSVIEW events.
+ *
+ ****************************************************************************/
+
+unsigned int sysview_get_timestamp(void)
+{
+ return up_perf_gettime();
+}
+
+/****************************************************************************
+ * Name: sysview_initialize
+ *
+ * Description:
+ * Initializes the SYSVIEW module.
+ *
+ * Input Parameters:
+ * None.
+ *
+ * Returned Value:
+ * Zero on succress. A negated errno value is returned on a failure.
+ *
+ ****************************************************************************/
+
+int sysview_initialize(void)
+{
+ uint32_t freq = up_perf_getfreq();
+
+ static const SEGGER_SYSVIEW_OS_API g_sysview_trace_api =
+ {
+ sysview_get_time,
+ sysview_send_tasklist,
+ };
+
+ SEGGER_SYSVIEW_Init(freq, freq, &g_sysview_trace_api,
+ sysview_send_description);
+
+#if CONFIG_SEGGER_SYSVIEW_RAM_BASE != 0
+ SEGGER_SYSVIEW_SetRAMBase(CONFIG_SEGGER_SYSVIEW_RAM_BASE);
+#endif
+
+ if ((g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE) != 0)
+ {
+ SEGGER_SYSVIEW_Start();
+ }
+
+ syslog(LOG_NOTICE, "SEGGER RTT Control Block Address: %#" PRIxPTR "\n",
+ (uintptr_t)&_SEGGER_RTT +
+ CONFIG_SEGGER_RTT_UNCACHED_OFF);
+ return 0;
+}
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_FILTER
+
+/****************************************************************************
+ * Name: sched_note_filter_mode
+ *
+ * Description:
+ * Set and get note filter mode.
+ * (Same as NOTECTL_GETMODE / NOTECTL_SETMODE ioctls)
+ *
+ * Input Parameters:
+ * oldm - A writable pointer to struct note_filter_mode_s to get current
+ * filter mode
+ * If 0, no data is written.
+ * newm - A read-only pointer to struct note_filter_mode_s which holds the
+ * new filter mode
+ * If 0, the filter mode is not updated.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void sched_note_filter_mode(struct note_filter_mode_s *oldm,
+ struct note_filter_mode_s *newm)
+{
+ irqstate_t flags;
+
+ flags = spin_lock_irqsave(NULL);
+
+ if (oldm != NULL)
+ {
+ if (SEGGER_SYSVIEW_IsStarted())
+ {
+ g_sysview.mode.flag |= NOTE_FILTER_MODE_FLAG_ENABLE;
+ }
+ else
+ {
+ g_sysview.mode.flag &= ~NOTE_FILTER_MODE_FLAG_ENABLE;
+ }
+
+ *oldm = g_sysview.mode;
+ }
+
+ if (newm != NULL)
+ {
+ g_sysview.mode = *newm;
+
+ if ((g_sysview.mode.flag & NOTE_FILTER_MODE_FLAG_ENABLE) != 0)
+ {
+ if (!SEGGER_SYSVIEW_IsStarted())
+ {
+ SEGGER_SYSVIEW_Start();
+ }
+ }
+ else
+ {
+ if (SEGGER_SYSVIEW_IsStarted())
+ {
+ SEGGER_SYSVIEW_Stop();
+ }
+ }
+ }
+
+ spin_unlock_irqrestore(NULL, flags);
+}
+
+/****************************************************************************
+ * Name: sched_note_filter_irq
+ *
+ * Description:
+ * Set and get IRQ filter setting
+ * (Same as NOTECTL_GETIRQFILTER / NOTECTL_SETIRQFILTER ioctls)
+ *
+ * Input Parameters:
+ * oldf - A writable pointer to struct note_filter_irq_s to get
+ * current IRQ filter setting
+ * If 0, no data is written.
+ * newf - A read-only pointer to struct note_filter_irq_s of the new
+ * IRQ filter setting
+ * If 0, the setting is not updated.
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
+void sched_note_filter_irq(struct note_filter_irq_s *oldf,
+ struct note_filter_irq_s *newf)
+{
+ irqstate_t flags;
+
+ flags = spin_lock_irqsave(NULL);
+
+ if (oldf != NULL)
+ {
+ /* Return the current filter setting */
+
+ *oldf = g_sysview.irq_mask;
+ }
+
+ if (newf != NULL)
+ {
+ /* Replace the syscall filter mask by the provided setting */
+
+ g_sysview.irq_mask = *newf;
+ }
+
+ spin_unlock_irqrestore(NULL, flags);
+}
+#endif
+
+#endif
diff --git a/drivers/note/note_driver.c b/include/nuttx/note/note_sysview.h
similarity index 73%
copy from drivers/note/note_driver.c
copy to include/nuttx/note/note_sysview.h
index 93c2466..44633b6 100644
--- a/drivers/note/note_driver.c
+++ b/include/nuttx/note/note_sysview.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * drivers/note/note_driver.c
+ * include/nuttx/note/note_sysview.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -18,24 +18,24 @@
*
****************************************************************************/
+#ifndef __INCLUDE_NUTTX_NOTE_NOTE_SYSVIEW_H
+#define __INCLUDE_NUTTX_NOTE_NOTE_SYSVIEW_H
+
/****************************************************************************
* Included Files
****************************************************************************/
-#include <nuttx/note/note_driver.h>
-#include <nuttx/note/noteram_driver.h>
-#include <nuttx/note/notectl_driver.h>
+#include <nuttx/config.h>
/****************************************************************************
- * Public Functions
+ * Public Function Prototypes
****************************************************************************/
/****************************************************************************
- * Name: note_register
+ * Name: sysview_initialize
*
* Description:
- * Register sched note related drivers at /dev folder that can be used by
- * an application to read or filter the note data.
+ * Initializes the SYSVIEW module.
*
* Input Parameters:
* None.
@@ -45,25 +45,8 @@
*
****************************************************************************/
-int note_register(void)
-{
- int ret = 0;
-
-#ifdef CONFIG_DRIVER_NOTERAM
- ret = noteram_register();
- if (ret < 0)
- {
- return ret;
- }
-#endif
-
-#ifdef CONFIG_DRIVER_NOTECTL
- ret = notectl_register();
- if (ret < 0)
- {
- return ret;
- }
+#ifdef CONFIG_SEGGER_SYSVIEW
+int sysview_initialize(void);
#endif
- return ret;
-}
+#endif /* __INCLUDE_NUTTX_NOTE_NOTE_SYSVIEW_H */