From 741626dc8f9037397abe35a2c5d4d64504129776 Mon Sep 17 00:00:00 2001 From: Diego Ismirlian Date: Sun, 29 Sep 2019 12:37:06 -0300 Subject: Add SEGGER RTT and SystemView bindings for ChibiOS --- .../SYSTEMVIEW/SEGGER_SYSVIEW_ChibiOS.c | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 os/various/segger_bindings/SYSTEMVIEW/SEGGER_SYSVIEW_ChibiOS.c (limited to 'os/various/segger_bindings/SYSTEMVIEW/SEGGER_SYSVIEW_ChibiOS.c') diff --git a/os/various/segger_bindings/SYSTEMVIEW/SEGGER_SYSVIEW_ChibiOS.c b/os/various/segger_bindings/SYSTEMVIEW/SEGGER_SYSVIEW_ChibiOS.c new file mode 100644 index 0000000..08d2e73 --- /dev/null +++ b/os/various/segger_bindings/SYSTEMVIEW/SEGGER_SYSVIEW_ChibiOS.c @@ -0,0 +1,73 @@ +/* + ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. + Copyright (C) 2019 Diego Ismirlian, (dismirlian (at) google's mail) + + Licensed 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. +*/ + +#include "ch.h" +#include "SEGGER_SYSVIEW.h" +#include "hal.h" + +#include + +static systime_t start; +static const char *isr_desc; + +static void _cbSendTaskList(void) { + thread_t *tp; + tp = chRegFirstThread(); + do { + SYSVIEW_ChibiOS_SendTaskInfo(tp); + tp = chRegNextThread(tp); + } while (tp != NULL); +} + +static U64 _cbGetTime(void) { + return TIME_I2US(chVTTimeElapsedSinceX(start)); +} + +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("O=ChibiOS"); + SEGGER_SYSVIEW_SendSysDesc(isr_desc); +} + +static const SEGGER_SYSVIEW_OS_API os_api = { + _cbGetTime, + _cbSendTaskList, +}; + +void SYSVIEW_ChibiOS_Start(U32 SysFreq, U32 CPUFreq, const char *isr_description) { + start = chVTGetSystemTimeX(); + isr_desc = isr_description; + SEGGER_SYSVIEW_Init(SysFreq, CPUFreq, &os_api, _cbSendSystemDesc); + SEGGER_SYSVIEW_Start(); +} + +void SYSVIEW_ChibiOS_SendTaskInfo(const void *_tp) { + const thread_t *const tp = (const thread_t *)_tp; + SEGGER_SYSVIEW_TASKINFO TaskInfo; + + //Fill all elements with 0 to allow extending the structure + //in future version without breaking the code + memset(&TaskInfo, 0, sizeof(TaskInfo)); + TaskInfo.TaskID = (U32)tp; + TaskInfo.sName = tp->name; + TaskInfo.Prio = (U32)tp->prio; +#if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) + TaskInfo.StackBase = (U32)tp->wabase; + TaskInfo.StackSize = (U32)tp->ctx.sp - (U32)tp->wabase; +#else + TaskInfo.StackBase = 0U; + TaskInfo.StackSize = (U32)tp->wabase; +#endif + SEGGER_SYSVIEW_SendTaskInfo(&TaskInfo); +} -- cgit v1.2.3