123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- /*
- * Copyright (c) 2018 Intel Corporation
- *
- * SPDX-License-Identifier: Apache-2.0
- */
- #include <kernel.h>
- #include <SEGGER_SYSVIEW.h>
- #include <ksched.h>
- extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI;
- #if CONFIG_THREAD_MAX_NAME_LEN
- #define THREAD_NAME_LEN CONFIG_THREAD_MAX_NAME_LEN
- #else
- #define THREAD_NAME_LEN 20
- #endif
- static void set_thread_name(char *name, struct k_thread *thread)
- {
- const char *tname = k_thread_name_get(thread);
- if (tname != NULL && tname[0] != '\0') {
- memcpy(name, tname, THREAD_NAME_LEN);
- name[THREAD_NAME_LEN - 1] = '\0';
- } else {
- snprintk(name, THREAD_NAME_LEN, "T%pE%p",
- thread, &thread->entry);
- }
- }
- void sys_trace_thread_info(struct k_thread *thread)
- {
- char name[THREAD_NAME_LEN];
- set_thread_name(name, thread);
- SEGGER_SYSVIEW_TASKINFO Info;
- Info.TaskID = (uint32_t)(uintptr_t)thread;
- Info.sName = name;
- Info.Prio = thread->base.prio;
- Info.StackBase = thread->stack_info.size;
- Info.StackSize = thread->stack_info.start;
- SEGGER_SYSVIEW_SendTaskInfo(&Info);
- }
- #if defined(CONFIG_SOC_LARK)
- #define INT_ID_DESC "I#2=TIM0,I#7=RTC,I#16=SD0,I#17=SD1,I#18=I2C0,I#19=I2C1," \
- "I#20=DSP,I#21=DSP1,I#27=DMA0,I#37=GPIO,I#43=LCD,I#49=DE," \
- "I#51=LRADC,I#56=BT,I#57=ANCDSP0,I#58=TWS,I#59=ANCDSP1"
- #else
- #define INT_ID_DESC ""
- #endif
- static void cbSendSystemDesc(void)
- {
- SEGGER_SYSVIEW_SendSysDesc("N=ZephyrSysView");
- SEGGER_SYSVIEW_SendSysDesc("D=" CONFIG_BOARD " "
- CONFIG_SOC_SERIES " " CONFIG_ARCH);
- SEGGER_SYSVIEW_SendSysDesc("O=Zephyr");
- SEGGER_SYSVIEW_SendSysDesc(INT_ID_DESC);
- }
- static void send_task_list_cb(void)
- {
- struct k_thread *thread;
- for (thread = _kernel.threads; thread; thread = thread->next_thread) {
- char name[THREAD_NAME_LEN];
- if (z_is_idle_thread_object(thread)) {
- continue;
- }
- set_thread_name(name, thread);
- SEGGER_SYSVIEW_SendTaskInfo(&(SEGGER_SYSVIEW_TASKINFO) {
- .TaskID = (uint32_t)(uintptr_t)thread,
- .sName = name,
- .StackSize = thread->stack_info.size,
- .StackBase = thread->stack_info.start,
- .Prio = thread->base.prio,
- });
- }
- }
- static U64 get_time_cb(void)
- {
- return (U64)k_cycle_get_32();
- }
- const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = {
- get_time_cb,
- send_task_list_cb,
- };
- void SEGGER_SYSVIEW_Conf(void)
- {
- SEGGER_SYSVIEW_Init(sys_clock_hw_cycles_per_sec(),
- sys_clock_hw_cycles_per_sec(),
- &SYSVIEW_X_OS_TraceAPI, cbSendSystemDesc);
- #if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_sram), okay)
- SEGGER_SYSVIEW_SetRAMBase(DT_REG_ADDR(DT_CHOSEN(zephyr_sram)));
- #else
- /* Setting RAMBase is just an optimization: this value is subtracted
- * from all pointers in order to save bandwidth. It's not an error
- * if a platform does not set this value.
- */
- #endif
- }
|