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 <anchao@xiaomi.com>
This commit is contained in:
parent
794df92fc9
commit
e04ccba78a
@ -133,3 +133,4 @@ source "drivers/rf/Kconfig"
|
||||
source "drivers/rc/Kconfig"
|
||||
source "drivers/motor/Kconfig"
|
||||
source "drivers/math/Kconfig"
|
||||
source "drivers/segger/Kconfig"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
2
drivers/segger/.gitignore
vendored
Normal file
2
drivers/segger/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/RTT
|
||||
/SystemView
|
67
drivers/segger/Kconfig
Normal file
67
drivers/segger/Kconfig
Normal file
@ -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
|
41
drivers/segger/Make.defs
Normal file
41
drivers/segger/Make.defs
Normal file
@ -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
|
45
drivers/segger/config/Global.h
Normal file
45
drivers/segger/config/Global.h
Normal file
@ -0,0 +1,45 @@
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* 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_GLOBAL_H
|
||||
#define __DRIVERS_SEGGER_CONFIG_GLOBAL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#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 */
|
84
drivers/segger/config/SEGGER_RTT_Conf.h
Normal file
84
drivers/segger/config/SEGGER_RTT_Conf.h
Normal file
@ -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 */
|
79
drivers/segger/config/SEGGER_SYSVIEW_Conf.h
Normal file
79
drivers/segger/config/SEGGER_SYSVIEW_Conf.h
Normal file
@ -0,0 +1,79 @@
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* 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_SYSVIEW_CONF_H
|
||||
#define __DRIVERS_SEGGER_CONFIG_SEGGER_SYSVIEW_CONF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
unsigned int sysview_get_interrupt_id(void);
|
||||
unsigned int sysview_get_timestamp(void);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DRIVERS_SEGGER_CONFIG_SEGGER_SYSVIEW_CONF_H */
|
493
drivers/segger/note_sysview.c
Normal file
493
drivers/segger/note_sysview.c
Normal file
@ -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
|
52
include/nuttx/note/note_sysview.h
Normal file
52
include/nuttx/note/note_sysview.h
Normal file
@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* 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_NOTE_NOTE_SYSVIEW_H
|
||||
#define __INCLUDE_NUTTX_NOTE_NOTE_SYSVIEW_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_SEGGER_SYSVIEW
|
||||
int sysview_initialize(void);
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_NOTE_NOTE_SYSVIEW_H */
|
Loading…
Reference in New Issue
Block a user