-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SEGGER RTT and SystemView bindings for ChibiOS
- Loading branch information
1 parent
8db69eb
commit 741626d
Showing
12 changed files
with
917 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SEGGER |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
All the code contained under ./ext is not part of the ChibiOS/ChibiOS-Contrib | ||
project and supplied as-is without any additional warranty by ChibiOS/ | ||
ChibiOS-Contrib. For ownership and copyright statements see the license | ||
details inside the code. | ||
|
||
Some modules may contain changes from the ChibiOS-Contrib team in order to | ||
increase compatibility or usability with ChibiOS itself. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
ChibiOS - Copyright (C) 2006..2017 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 "hal.h" | ||
#include "SEGGER_RTT_streams.h" | ||
|
||
RTTDriver RTTD0; | ||
static bool rtt_global_init; | ||
|
||
static size_t _write(RTTDriver *rttdp, const uint8_t *bp, size_t n) { | ||
return SEGGER_RTT_Write(rttdp->up_buffer_index, bp, n); | ||
} | ||
|
||
static size_t _read(RTTDriver *rttdp, uint8_t *bp, size_t n) { | ||
(void)rttdp, (void)bp, (void)n; | ||
/* TODO: implement */ | ||
return 0; | ||
} | ||
|
||
static msg_t _put(RTTDriver *rttdp, uint8_t b) { | ||
if (SEGGER_RTT_PutChar(rttdp->up_buffer_index, b) == 1) { | ||
return MSG_OK; | ||
} | ||
return MSG_TIMEOUT; | ||
} | ||
|
||
static msg_t _get(RTTDriver *rttdp) { | ||
(void)rttdp; | ||
/* TODO: implement */ | ||
return MSG_TIMEOUT; | ||
} | ||
|
||
static const struct RTTDriverVMT vmt = { | ||
(size_t)0, | ||
(size_t (*)(void *, const uint8_t *, size_t))_write, | ||
(size_t (*)(void *, uint8_t *, size_t))_read, | ||
(msg_t (*)(void *, uint8_t))_put, | ||
(msg_t (*)(void *))_get, | ||
}; | ||
|
||
static inline void _object_init(RTTDriver *rttdp) { | ||
rttdp->state = RTT_STATE_READY; | ||
rttdp->vmt = &vmt; | ||
} | ||
|
||
void rttInit(void) { | ||
osalDbgAssert(rtt_global_init == false, "double init"); | ||
SEGGER_RTT_LOCK(); | ||
SEGGER_RTT_Init(); | ||
RTTD0.up_buffer_index = 0; | ||
RTTD0.down_buffer_index = 0; | ||
_object_init(&RTTD0); | ||
rtt_global_init = true; | ||
RTTD0.state = RTT_STATE_READY; | ||
SEGGER_RTT_UNLOCK(); | ||
} | ||
|
||
void rttObjectInit(RTTDriver *rttdp, const RTTConfig *cfg) { | ||
osalDbgCheck(rttdp); | ||
osalDbgAssert(rtt_global_init, "uninitialized"); | ||
osalDbgAssert(rttdp != &RTTD0, "RTTD0 is automatically initialized on rttInit"); | ||
|
||
int idx; | ||
|
||
SEGGER_RTT_LOCK(); | ||
if (cfg->down.size) { | ||
idx = SEGGER_RTT_AllocDownBuffer(cfg->name, cfg->down.buff, cfg->down.size, cfg->down.flags); | ||
osalDbgAssert(idx > 0, "can't alloc down buffer"); | ||
rttdp->down_buffer_index = (unsigned)idx; | ||
} else { | ||
rttdp->down_buffer_index = 0; | ||
} | ||
|
||
if (cfg->up.size) { | ||
idx = SEGGER_RTT_AllocUpBuffer(cfg->name, cfg->up.buff, cfg->up.size, cfg->up.flags); | ||
osalDbgAssert(idx > 0, "can't alloc up buffer"); | ||
rttdp->up_buffer_index = (unsigned)idx; | ||
} else { | ||
rttdp->up_buffer_index = 0; | ||
} | ||
|
||
_object_init(rttdp); | ||
SEGGER_RTT_UNLOCK(); | ||
} | ||
|
||
void rttSetUpFlags(RTTDriver *rttdp, rtt_mode_flags_t flags) { | ||
int ret = SEGGER_RTT_SetFlagsUpBuffer(rttdp->up_buffer_index, (unsigned)flags); | ||
osalDbgAssert(ret >= 0, "error"); | ||
} | ||
|
||
void rttSetDownFlags(RTTDriver *rttdp, rtt_mode_flags_t flags) { | ||
int ret = SEGGER_RTT_SetFlagsDownBuffer(rttdp->down_buffer_index, (unsigned)flags); | ||
osalDbgAssert(ret >= 0, "error"); | ||
} | ||
|
||
void rttStart(RTTDriver *rttdp) { | ||
osalDbgCheck(rttdp); | ||
osalDbgAssert(rtt_global_init, "uninitialized"); | ||
osalDbgAssert((rttdp->state == RTT_STATE_ACTIVE) | ||
|| (rttdp->state == RTT_STATE_READY), "wrong state"); | ||
rttdp->state = RTT_STATE_READY; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio | ||
Copyright (C) 2015..2017 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. | ||
*/ | ||
|
||
#ifndef SEGGER_RTT_streams_H_ | ||
#define SEGGER_RTT_streams_H_ | ||
|
||
#include "hal.h" | ||
#include "SEGGER_RTT.h" | ||
|
||
/*===========================================================================*/ | ||
/* Driver pre-compile time settings. */ | ||
/*===========================================================================*/ | ||
|
||
/*===========================================================================*/ | ||
/* Derived constants and error checks. */ | ||
/*===========================================================================*/ | ||
|
||
/*===========================================================================*/ | ||
/* Driver data structures and types. */ | ||
/*===========================================================================*/ | ||
|
||
typedef enum { | ||
RTT_STATE_UNINIT = 0, | ||
RTT_STATE_STOP = 1, | ||
RTT_STATE_ACTIVE = 2, | ||
RTT_STATE_READY = 3 | ||
} rtt_state_t; | ||
|
||
typedef enum { | ||
RTT_MODE_FLAGS_NO_BLOCK_SKIP = SEGGER_RTT_MODE_NO_BLOCK_SKIP, | ||
RTT_MODE_FLAGS_NO_BLOCK_TRIM = SEGGER_RTT_MODE_NO_BLOCK_TRIM, | ||
RTT_MODE_FLAGS_BLOCK_IF_FIFO_FULL = SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL, | ||
} rtt_mode_flags_t; | ||
|
||
#define _rtt_driver_methods \ | ||
_base_sequential_stream_methods | ||
|
||
struct RTTDriverVMT { | ||
_rtt_driver_methods | ||
}; | ||
|
||
typedef struct RTTDriver RTTDriver; | ||
typedef struct RTTConfig RTTConfig; | ||
typedef struct RTTBufferConfig RTTBufferConfig; | ||
|
||
struct RTTDriver { | ||
/* inherited from abstract asyncrhonous channel driver */ | ||
const struct RTTDriverVMT *vmt; | ||
_base_sequential_stream_data | ||
|
||
rtt_state_t state; | ||
unsigned int up_buffer_index; | ||
unsigned int down_buffer_index; | ||
}; | ||
|
||
struct RTTBufferConfig { | ||
void *buff; | ||
unsigned int size; | ||
rtt_mode_flags_t flags; | ||
}; | ||
|
||
struct RTTConfig { | ||
const char *name; | ||
RTTBufferConfig up; | ||
RTTBufferConfig down; | ||
}; | ||
|
||
/*===========================================================================*/ | ||
/* Driver macros. */ | ||
/*===========================================================================*/ | ||
#define rttGetState(rttdp) ((rttdp)->state) | ||
#define rttGetUpBufferIndex(rttdp) ((rttdp)->up_buffer_index) | ||
#define rttGetDownBufferIndex(rttdp) ((rttdp)->down_buffer_index) | ||
|
||
/*===========================================================================*/ | ||
/* External declarations. */ | ||
/*===========================================================================*/ | ||
extern RTTDriver RTTD0; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
/* RTT device driver */ | ||
void rttInit(void); | ||
void rttObjectInit(RTTDriver *rttdp, const RTTConfig *cfg); | ||
void rttStart(RTTDriver *rttdp); | ||
void rttSetUpFlags(RTTDriver *rttdp, rtt_mode_flags_t flags); | ||
void rttSetDownFlags(RTTDriver *rttdp, rtt_mode_flags_t flags); | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* SEGGER_RTT_streams_H_ */ |
73 changes: 73 additions & 0 deletions
73
os/various/segger_bindings/SYSTEMVIEW/SEGGER_SYSVIEW_ChibiOS.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <string.h> | ||
|
||
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); | ||
} |
Oops, something went wrong.