ext: debug: segger: Terminal sharing using SEGGER_RTT_LOCK/UNLOCK macros
This commit allows to share default RTT (terminal) buffer with various Zephyr subsystems. Signed-off-by: Pavel Kral <pavel.kral@omsquare.com>
This commit is contained in:
parent
f19f217f08
commit
2c84fd2631
5 changed files with 52 additions and 7 deletions
|
@ -36,15 +36,14 @@ static void wait(void)
|
|||
|
||||
static int rtt_console_out(int character)
|
||||
{
|
||||
unsigned int key;
|
||||
char c = (char)character;
|
||||
unsigned int cnt;
|
||||
int max_cnt = CONFIG_RTT_TX_RETRY_CNT;
|
||||
|
||||
do {
|
||||
key = irq_lock();
|
||||
SEGGER_RTT_LOCK();
|
||||
cnt = SEGGER_RTT_WriteNoLock(0, &c, 1);
|
||||
irq_unlock(key);
|
||||
SEGGER_RTT_UNLOCK();
|
||||
|
||||
/* There are two possible reasons for not writing any data to
|
||||
* RTT:
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
|
||||
zephyr_include_directories_ifdef(CONFIG_HAS_SEGGER_RTT .)
|
||||
zephyr_sources_ifdef(CONFIG_HAS_SEGGER_RTT rtt/SEGGER_RTT.c)
|
||||
zephyr_sources_ifdef(CONFIG_HAS_SEGGER_RTT
|
||||
rtt/SEGGER_RTT.c
|
||||
rtt/SEGGER_RTT_zephyr.c
|
||||
)
|
||||
zephyr_sources_ifdef(CONFIG_SEGGER_SYSTEMVIEW systemview/SEGGER_SYSVIEW.c)
|
||||
|
|
|
@ -138,7 +138,12 @@ Revision: $Rev: 9599 $
|
|||
* Rowley CrossStudio and GCC
|
||||
*/
|
||||
#if (defined __SES_ARM) || (defined __CROSSWORKS_ARM) || (defined __GNUC__)
|
||||
#ifdef __ARM_ARCH_6M__
|
||||
#ifdef __ZEPHYR__
|
||||
#include <kernel.h>
|
||||
extern struct k_mutex rtt_term_mutex;
|
||||
#define SEGGER_RTT_LOCK() k_mutex_lock(&rtt_term_mutex, K_FOREVER);
|
||||
#define SEGGER_RTT_UNLOCK() k_mutex_unlock(&rtt_term_mutex);
|
||||
#elif __ARM_ARCH_6M__
|
||||
#define SEGGER_RTT_LOCK() { \
|
||||
unsigned int LockState; \
|
||||
__asm volatile ("mrs %0, primask \n\t" \
|
||||
|
|
20
ext/debug/segger/rtt/SEGGER_RTT_zephyr.c
Normal file
20
ext/debug/segger/rtt/SEGGER_RTT_zephyr.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright (c) 2018 omSquare s.r.o.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <kernel.h>
|
||||
|
||||
/*
|
||||
* Common mutex for locking access to terminal buffer.
|
||||
* Note that SEGGER uses same lock macros for both SEGGER_RTT_Write and
|
||||
* SEGGER_RTT_Read functions. Because of this we are not able generally
|
||||
* separate up and down access using two mutexes until SEGGER library fix
|
||||
* this.
|
||||
*
|
||||
* If sharing access cause performance problems, consider using another
|
||||
* non terminal buffers.
|
||||
*/
|
||||
|
||||
K_MUTEX_DEFINE(rtt_term_mutex);
|
|
@ -26,7 +26,16 @@ static int drop_warn = 0;
|
|||
#endif /* CONFIG_LOG_BACKEND_RTT_MODE_DROP */
|
||||
|
||||
#if CONFIG_LOG_BACKEND_RTT_BUFFER > 0
|
||||
|
||||
#define RTT_LOCK()
|
||||
#define RTT_UNLOCK()
|
||||
static u8_t rtt_buf[CONFIG_LOG_BACKEND_RTT_BUFFER_SIZE];
|
||||
|
||||
#else
|
||||
|
||||
#define RTT_LOCK() SEGGER_RTT_LOCK()
|
||||
#define RTT_UNLOCK() SEGGER_RTT_UNLOCK()
|
||||
|
||||
#endif /* CONFIG_LOG_BACKEND_RTT_BUFFER > 0 */
|
||||
|
||||
static u8_t line_buf[CONFIG_LOG_BACKEND_RTT_MESSAGE_SIZE + DROP_MESSAGE_LEN];
|
||||
|
@ -107,8 +116,10 @@ static int log_backend_rtt_write(void)
|
|||
}
|
||||
}
|
||||
|
||||
RTT_LOCK();
|
||||
int ret = SEGGER_RTT_WriteSkipNoLock(CONFIG_LOG_BACKEND_RTT_BUFFER,
|
||||
line_buf, line_pos - line_buf + 1);
|
||||
RTT_UNLOCK();
|
||||
|
||||
if (!ret) {
|
||||
drop_cnt++;
|
||||
|
@ -124,9 +135,15 @@ static int log_backend_rtt_write(void)
|
|||
|
||||
static int log_backend_rtt_write(void)
|
||||
{
|
||||
unsigned int ret;
|
||||
*line_pos = '\r';
|
||||
if (SEGGER_RTT_WriteSkipNoLock(CONFIG_LOG_BACKEND_RTT_BUFFER, line_buf,
|
||||
line_pos - line_buf + 1)) {
|
||||
|
||||
RTT_LOCK();
|
||||
ret = SEGGER_RTT_WriteSkipNoLock(CONFIG_LOG_BACKEND_RTT_BUFFER,
|
||||
line_buf, line_pos - line_buf + 1);
|
||||
RTT_UNLOCK();
|
||||
|
||||
if (ret) {
|
||||
log_backend_rtt_flush();
|
||||
return 0;
|
||||
}
|
||||
|
@ -139,6 +156,7 @@ static int log_backend_rtt_panic(u8_t *data, size_t length)
|
|||
{
|
||||
unsigned int written;
|
||||
|
||||
/* do not respect mutex, take it over */
|
||||
written = SEGGER_RTT_WriteNoLock(CONFIG_LOG_BACKEND_RTT_BUFFER, data,
|
||||
length);
|
||||
log_backend_rtt_flush();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue