mirror of
https://github.com/espressif/openthread.git
synced 2026-09-30 21:07:39 +00:00
[efr32] add support for RTT log (#3285)
This commit is contained in:
committed by
Jonathan Hui
parent
ff0b30db55
commit
4279dbc14c
@@ -132,8 +132,9 @@ PRETTY_FILES =
|
||||
$(noinst_HEADERS) \
|
||||
$(NULL)
|
||||
|
||||
Dash = -
|
||||
libopenthread_efr32_a_LIBADD = \
|
||||
$(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o")
|
||||
Dash = -
|
||||
libopenthread_efr32_a_LIBADD = \
|
||||
$(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o") \
|
||||
$(shell find $(top_builddir)/third_party/jlink/SEGGER_RTT_V640/RTT $(Dash)type f $(Dash)name "*.o")
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
|
||||
@@ -34,15 +34,31 @@
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread/config.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
#include <openthread/platform/logging.h>
|
||||
#include <openthread/platform/toolchain.h>
|
||||
|
||||
#include <utils/logging_rtt.h>
|
||||
|
||||
#if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED) || \
|
||||
(OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_NCP_SPINEL)
|
||||
void efr32LogInit(void)
|
||||
{
|
||||
utilsLogRttInit();
|
||||
}
|
||||
|
||||
void efr32LogDeinit(void)
|
||||
{
|
||||
utilsLogRttDeinit();
|
||||
}
|
||||
|
||||
OT_TOOL_WEAK void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogLevel);
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
OT_UNUSED_VARIABLE(aFormat);
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, aFormat);
|
||||
|
||||
utilsLogRttOutput(aLogLevel, aLogRegion, aFormat, ap);
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -97,4 +97,16 @@ void efr32MiscInit(void);
|
||||
*/
|
||||
void efr32RandomInit(void);
|
||||
|
||||
/**
|
||||
* Initialization of Logger driver.
|
||||
*
|
||||
*/
|
||||
void efr32LogInit(void);
|
||||
|
||||
/**
|
||||
* Deinitialization of Logger driver.
|
||||
*
|
||||
*/
|
||||
void efr32LogDeinit(void);
|
||||
|
||||
#endif // PLATFORM_EFR32_H_
|
||||
|
||||
@@ -71,6 +71,7 @@ void otSysInit(int argc, char *argv[])
|
||||
wakeupFem();
|
||||
#endif
|
||||
|
||||
efr32LogInit();
|
||||
efr32RadioInit();
|
||||
efr32AlarmInit();
|
||||
efr32MiscInit();
|
||||
@@ -85,6 +86,7 @@ bool otSysPseudoResetWasRequested(void)
|
||||
void otSysDeinit(void)
|
||||
{
|
||||
efr32RadioDeinit();
|
||||
efr32LogDeinit();
|
||||
}
|
||||
|
||||
void otSysProcessDrivers(otInstance *aInstance)
|
||||
|
||||
@@ -73,7 +73,6 @@ COMMONCPPFLAGS
|
||||
-I$(top_srcdir)/third_party/NordicSemiconductor/nrfx/drivers/include \
|
||||
-I$(top_srcdir)/third_party/NordicSemiconductor/nrfx/mdk \
|
||||
-I$(top_srcdir)/third_party/NordicSemiconductor/nrfx/soc \
|
||||
-I$(top_srcdir)/third_party/NordicSemiconductor/segger_rtt \
|
||||
-I$(top_srcdir)/third_party/NordicSemiconductor/softdevice/s140/headers \
|
||||
-I$(top_srcdir)/third_party/NordicSemiconductor/softdevice/s140/headers/nrf52 \
|
||||
$(NULL)
|
||||
@@ -187,7 +186,6 @@ NORDICSEMI_SOURCES
|
||||
@top_builddir@/third_party/NordicSemiconductor/nrfx/hal/nrf_nvmc.c \
|
||||
@top_builddir@/third_party/NordicSemiconductor/nrfx/mdk/gcc_startup_nrf52840.S \
|
||||
@top_builddir@/third_party/NordicSemiconductor/nrfx/mdk/system_nrf52840.c \
|
||||
@top_builddir@/third_party/NordicSemiconductor/segger_rtt/SEGGER_RTT.c \
|
||||
$(NULL)
|
||||
|
||||
HWCRYPTO_SOURCES = \
|
||||
@@ -360,8 +358,6 @@ noinst_HEADERS
|
||||
$(top_srcdir)/third_party/NordicSemiconductor/nrfx/mdk/nrf52840_bitfields.h \
|
||||
$(top_srcdir)/third_party/NordicSemiconductor/nrfx/mdk/nrf52840_peripherals.h \
|
||||
$(top_srcdir)/third_party/NordicSemiconductor/nrfx/mdk/system_nrf52840.h \
|
||||
$(top_srcdir)/third_party/NordicSemiconductor/segger_rtt/SEGGER_RTT.h \
|
||||
$(top_srcdir)/third_party/NordicSemiconductor/segger_rtt/SEGGER_RTT_Conf.h \
|
||||
$(top_srcdir)/third_party/NordicSemiconductor/softdevice/s140/headers/ble.h \
|
||||
$(top_srcdir)/third_party/NordicSemiconductor/softdevice/s140/headers/ble_err.h \
|
||||
$(top_srcdir)/third_party/NordicSemiconductor/softdevice/s140/headers/ble_gap.h \
|
||||
@@ -390,12 +386,15 @@ PRETTY_FILES
|
||||
Dash = -
|
||||
|
||||
libopenthread_nrf52840_a_LIBADD = \
|
||||
$(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o")
|
||||
$(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o") \
|
||||
$(shell find $(top_builddir)/third_party/jlink/SEGGER_RTT_V640/RTT $(Dash)type f $(Dash)name "*.o")
|
||||
|
||||
libopenthread_nrf52840_sdk_a_LIBADD = \
|
||||
$(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o")
|
||||
$(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o") \
|
||||
$(shell find $(top_builddir)/third_party/jlink/SEGGER_RTT_V640/RTT $(Dash)type f $(Dash)name "*.o")
|
||||
|
||||
libopenthread_nrf52840_softdevice_sdk_a_LIBADD = \
|
||||
$(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o")
|
||||
$(shell find $(top_builddir)/examples/platforms/utils $(Dash)type f $(Dash)name "*.o") \
|
||||
$(shell find $(top_builddir)/third_party/jlink/SEGGER_RTT_V640/RTT $(Dash)type f $(Dash)name "*.o")
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
|
||||
@@ -34,149 +34,31 @@
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <utils/code_utils.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
#include <openthread/platform/logging.h>
|
||||
|
||||
#include "platform-nrf5.h"
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread/config.h>
|
||||
#include <utils/logging_rtt.h>
|
||||
|
||||
#if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED) || \
|
||||
(OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_NCP_SPINEL)
|
||||
#include <segger_rtt/SEGGER_RTT.h>
|
||||
|
||||
#if (LOG_RTT_COLOR_ENABLE == 1)
|
||||
#define RTT_COLOR_CODE_DEFAULT "\x1B[0m"
|
||||
#define RTT_COLOR_CODE_RED "\x1B[1;31m"
|
||||
#define RTT_COLOR_CODE_GREEN "\x1B[1;32m"
|
||||
#define RTT_COLOR_CODE_YELLOW "\x1B[1;33m"
|
||||
#define RTT_COLOR_CODE_CYAN "\x1B[1;36m"
|
||||
#else // LOG_RTT_COLOR_ENABLE == 1
|
||||
#define RTT_COLOR_CODE_DEFAULT ""
|
||||
#define RTT_COLOR_CODE_RED ""
|
||||
#define RTT_COLOR_CODE_GREEN ""
|
||||
#define RTT_COLOR_CODE_YELLOW ""
|
||||
#define RTT_COLOR_CODE_CYAN ""
|
||||
#endif // LOG_RTT_COLOR_ENABLE == 1
|
||||
|
||||
static bool sLogInitialized = false;
|
||||
static uint8_t sLogBuffer[LOG_RTT_BUFFER_SIZE];
|
||||
|
||||
/**
|
||||
* Function for getting color of a given level log.
|
||||
*
|
||||
* @param[in] aLogLevel The log level.
|
||||
*
|
||||
* @returns String with a log level color value.
|
||||
*/
|
||||
static inline const char *levelToString(otLogLevel aLogLevel)
|
||||
void nrf5LogInit(void)
|
||||
{
|
||||
switch (aLogLevel)
|
||||
{
|
||||
case OT_LOG_LEVEL_CRIT:
|
||||
return RTT_COLOR_CODE_RED;
|
||||
|
||||
case OT_LOG_LEVEL_WARN:
|
||||
return RTT_COLOR_CODE_YELLOW;
|
||||
|
||||
case OT_LOG_LEVEL_INFO:
|
||||
return RTT_COLOR_CODE_GREEN;
|
||||
|
||||
case OT_LOG_LEVEL_DEBG:
|
||||
default:
|
||||
return RTT_COLOR_CODE_DEFAULT;
|
||||
}
|
||||
utilsLogRttInit();
|
||||
}
|
||||
|
||||
#if (LOG_TIMESTAMP_ENABLE == 1)
|
||||
/**
|
||||
* Function for printing actual timestamp.
|
||||
*
|
||||
* @param[inout] aLogString Pointer to the log buffer.
|
||||
* @param[in] aMaxSize Maximum size of the log buffer.
|
||||
*
|
||||
* @returns Number of bytes successfully written to the log buffer.
|
||||
*/
|
||||
static inline uint16_t logTimestamp(char *aLogString, uint16_t aMaxSize)
|
||||
void nrf5LogDeinit(void)
|
||||
{
|
||||
return snprintf(aLogString, aMaxSize, "%s[%010ld]", RTT_COLOR_CODE_CYAN, otPlatAlarmMilliGetNow());
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Function for printing log level.
|
||||
*
|
||||
* @param[inout] aLogString Pointer to log buffer.
|
||||
* @param[in] aMaxSize Maximum size of log buffer.
|
||||
* @param[in] aLogLevel Log level.
|
||||
*
|
||||
* @returns Number of bytes successfully written to the log buffer.
|
||||
*/
|
||||
static inline uint16_t logLevel(char *aLogString, uint16_t aMaxSize, otLogLevel aLogLevel)
|
||||
{
|
||||
return snprintf(aLogString, aMaxSize, "%s ", levelToString(aLogLevel));
|
||||
}
|
||||
|
||||
void nrf5LogInit()
|
||||
{
|
||||
int res = SEGGER_RTT_ConfigUpBuffer(LOG_RTT_BUFFER_INDEX, LOG_RTT_BUFFER_NAME, sLogBuffer, LOG_RTT_BUFFER_SIZE,
|
||||
SEGGER_RTT_MODE_NO_BLOCK_TRIM);
|
||||
otEXPECT(res >= 0);
|
||||
|
||||
sLogInitialized = true;
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void nrf5LogDeinit()
|
||||
{
|
||||
sLogInitialized = false;
|
||||
utilsLogRttDeinit();
|
||||
}
|
||||
|
||||
OT_TOOL_WEAK void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, ...)
|
||||
{
|
||||
OT_UNUSED_VARIABLE(aLogRegion);
|
||||
va_list ap;
|
||||
|
||||
uint16_t length = 0;
|
||||
int charsWritten;
|
||||
char logString[LOG_PARSE_BUFFER_SIZE + 1];
|
||||
va_start(ap, aFormat);
|
||||
|
||||
otEXPECT(sLogInitialized == true);
|
||||
utilsLogRttOutput(aLogLevel, aLogRegion, aFormat, ap);
|
||||
|
||||
#if (LOG_TIMESTAMP_ENABLE == 1)
|
||||
length += logTimestamp(logString, LOG_PARSE_BUFFER_SIZE);
|
||||
#endif
|
||||
|
||||
// Add level information.
|
||||
length += logLevel(&logString[length], (LOG_PARSE_BUFFER_SIZE - length), aLogLevel);
|
||||
|
||||
// Parse user string.
|
||||
va_list paramList;
|
||||
va_start(paramList, aFormat);
|
||||
charsWritten = vsnprintf(&logString[length], (LOG_PARSE_BUFFER_SIZE - length), aFormat, paramList);
|
||||
otEXPECT(charsWritten >= 0);
|
||||
length += charsWritten;
|
||||
|
||||
if (length > LOG_PARSE_BUFFER_SIZE)
|
||||
{
|
||||
length = LOG_PARSE_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
logString[length++] = '\n';
|
||||
va_end(paramList);
|
||||
|
||||
// Write user log to the RTT memory block.
|
||||
SEGGER_RTT_WriteNoLock(0, logString, length);
|
||||
|
||||
exit:
|
||||
return;
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
#endif // (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED)
|
||||
#endif
|
||||
|
||||
@@ -248,71 +248,6 @@
|
||||
#define RNG_IRQ_PRIORITY 6
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* @section Log module configuration.
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @def LOG_RTT_BUFFER_INDEX
|
||||
*
|
||||
* RTT's buffer index.
|
||||
*
|
||||
*/
|
||||
#ifndef LOG_RTT_BUFFER_INDEX
|
||||
#define LOG_RTT_BUFFER_INDEX 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def LOG_RTT_BUFFER_NAME
|
||||
*
|
||||
* RTT's name.
|
||||
*
|
||||
*/
|
||||
#ifndef LOG_RTT_BUFFER_NAME
|
||||
#define LOG_RTT_BUFFER_NAME "Terminal"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def LOG_RTT_BUFFER_SIZE
|
||||
*
|
||||
* LOG RTT's buffer size.
|
||||
*
|
||||
*/
|
||||
#ifndef LOG_RTT_BUFFER_SIZE
|
||||
#define LOG_RTT_BUFFER_SIZE 256
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def LOG_RTT_COLOR_ENABLE
|
||||
*
|
||||
* Enable colors on RTT Viewer.
|
||||
*
|
||||
*/
|
||||
#ifndef LOG_RTT_COLOR_ENABLE
|
||||
#define LOG_RTT_COLOR_ENABLE 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def LOG_PARSE_BUFFER_SIZE
|
||||
*
|
||||
* LOG buffer used to parse print format. It will be locally allocated on the
|
||||
* stack.
|
||||
*
|
||||
*/
|
||||
#ifndef LOG_PARSE_BUFFER_SIZE
|
||||
#define LOG_PARSE_BUFFER_SIZE 128
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def LOG_TIMESTAMP_ENABLE
|
||||
*
|
||||
* Enable timestamp in the logs.
|
||||
*
|
||||
*/
|
||||
#ifndef LOG_TIMESTAMP_ENABLE
|
||||
#define LOG_TIMESTAMP_ENABLE 1
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* @section SPI Slave configuration.
|
||||
******************************************************************************/
|
||||
|
||||
@@ -30,20 +30,23 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
|
||||
|
||||
lib_LIBRARIES = libopenthread-platform-utils.a
|
||||
|
||||
libopenthread_platform_utils_a_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/examples/platforms \
|
||||
-I$(top_srcdir)/src/core \
|
||||
libopenthread_platform_utils_a_CPPFLAGS = \
|
||||
-I$(top_srcdir)/include \
|
||||
-I$(top_srcdir)/examples/platforms \
|
||||
-I$(top_srcdir)/src/core \
|
||||
-I$(top_srcdir)/third_party/jlink/SEGGER_RTT_V640/RTT \
|
||||
$(NULL)
|
||||
|
||||
libopenthread_platform_utils_a_SOURCES = \
|
||||
debug_uart.c \
|
||||
logging_rtt.c \
|
||||
settings_flash.c \
|
||||
$(NULL)
|
||||
|
||||
noinst_HEADERS = \
|
||||
code_utils.h \
|
||||
flash.h \
|
||||
logging_rtt.h \
|
||||
$(NULL)
|
||||
|
||||
include $(abs_top_nlbuild_autotools_dir)/automake/post.am
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2018, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file implements the OpenThread platform abstraction for logging.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <openthread-core-config.h>
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include <utils/code_utils.h>
|
||||
#include <openthread/platform/alarm-milli.h>
|
||||
#include <openthread/platform/logging.h>
|
||||
|
||||
#include "SEGGER_RTT.h"
|
||||
#include "logging_rtt.h"
|
||||
|
||||
#if (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED) || \
|
||||
(OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_NCP_SPINEL)
|
||||
#if (LOG_RTT_COLOR_ENABLE == 1)
|
||||
#define RTT_COLOR_CODE_DEFAULT "\x1B[0m"
|
||||
#define RTT_COLOR_CODE_RED "\x1B[1;31m"
|
||||
#define RTT_COLOR_CODE_GREEN "\x1B[1;32m"
|
||||
#define RTT_COLOR_CODE_YELLOW "\x1B[1;33m"
|
||||
#define RTT_COLOR_CODE_CYAN "\x1B[1;36m"
|
||||
#else // LOG_RTT_COLOR_ENABLE == 1
|
||||
#define RTT_COLOR_CODE_DEFAULT ""
|
||||
#define RTT_COLOR_CODE_RED ""
|
||||
#define RTT_COLOR_CODE_GREEN ""
|
||||
#define RTT_COLOR_CODE_YELLOW ""
|
||||
#define RTT_COLOR_CODE_CYAN ""
|
||||
#endif // LOG_RTT_COLOR_ENABLE == 1
|
||||
|
||||
static bool sLogInitialized = false;
|
||||
static uint8_t sLogBuffer[LOG_RTT_BUFFER_SIZE];
|
||||
|
||||
/**
|
||||
* Function for getting color of a given level log.
|
||||
*
|
||||
* @param[in] aLogLevel The log level.
|
||||
*
|
||||
* @returns String with a log level color value.
|
||||
*/
|
||||
static inline const char *levelToString(otLogLevel aLogLevel)
|
||||
{
|
||||
switch (aLogLevel)
|
||||
{
|
||||
case OT_LOG_LEVEL_CRIT:
|
||||
return RTT_COLOR_CODE_RED;
|
||||
|
||||
case OT_LOG_LEVEL_WARN:
|
||||
return RTT_COLOR_CODE_YELLOW;
|
||||
|
||||
case OT_LOG_LEVEL_INFO:
|
||||
return RTT_COLOR_CODE_GREEN;
|
||||
|
||||
case OT_LOG_LEVEL_DEBG:
|
||||
default:
|
||||
return RTT_COLOR_CODE_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
#if (LOG_TIMESTAMP_ENABLE == 1)
|
||||
/**
|
||||
* Function for printing actual timestamp.
|
||||
*
|
||||
* @param[inout] aLogString Pointer to the log buffer.
|
||||
* @param[in] aMaxSize Maximum size of the log buffer.
|
||||
*
|
||||
* @returns Number of bytes successfully written to the log buffer.
|
||||
*/
|
||||
static inline int logTimestamp(char *aLogString, uint16_t aMaxSize)
|
||||
{
|
||||
long unsigned int now = otPlatAlarmMilliGetNow();
|
||||
return snprintf(aLogString, (size_t)aMaxSize, "%s[%010lu]", RTT_COLOR_CODE_CYAN, now);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Function for printing log level.
|
||||
*
|
||||
* @param[inout] aLogString Pointer to log buffer.
|
||||
* @param[in] aMaxSize Maximum size of log buffer.
|
||||
* @param[in] aLogLevel Log level.
|
||||
*
|
||||
* @returns Number of bytes successfully written to the log buffer.
|
||||
*/
|
||||
static inline int logLevel(char *aLogString, uint16_t aMaxSize, otLogLevel aLogLevel)
|
||||
{
|
||||
return snprintf(aLogString, (size_t)aMaxSize, "%s ", levelToString(aLogLevel));
|
||||
}
|
||||
|
||||
void utilsLogRttInit(void)
|
||||
{
|
||||
int res = SEGGER_RTT_ConfigUpBuffer(LOG_RTT_BUFFER_INDEX, LOG_RTT_BUFFER_NAME, sLogBuffer, LOG_RTT_BUFFER_SIZE,
|
||||
SEGGER_RTT_MODE_NO_BLOCK_TRIM);
|
||||
otEXPECT(res >= 0);
|
||||
|
||||
sLogInitialized = true;
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void utilsLogRttDeinit(void)
|
||||
{
|
||||
sLogInitialized = false;
|
||||
}
|
||||
|
||||
void utilsLogRttOutput(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list ap)
|
||||
{
|
||||
(void)aLogRegion;
|
||||
|
||||
uint16_t length = 0;
|
||||
int charsWritten;
|
||||
char logString[LOG_PARSE_BUFFER_SIZE + 1];
|
||||
|
||||
otEXPECT(sLogInitialized == true);
|
||||
|
||||
#if (LOG_TIMESTAMP_ENABLE == 1)
|
||||
length += logTimestamp(logString, LOG_PARSE_BUFFER_SIZE);
|
||||
#endif
|
||||
|
||||
// Add level information.
|
||||
length += logLevel(&logString[length], (LOG_PARSE_BUFFER_SIZE - length), aLogLevel);
|
||||
|
||||
charsWritten = vsnprintf(&logString[length], (size_t)(LOG_PARSE_BUFFER_SIZE - length), aFormat, ap);
|
||||
otEXPECT(charsWritten >= 0);
|
||||
length += charsWritten;
|
||||
|
||||
if (length > LOG_PARSE_BUFFER_SIZE)
|
||||
{
|
||||
length = LOG_PARSE_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
logString[length++] = '\n';
|
||||
|
||||
// Write user log to the RTT memory block.
|
||||
SEGGER_RTT_WriteNoLock(0, logString, length);
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
#endif // (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_PLATFORM_DEFINED) ||
|
||||
// (OPENTHREAD_CONFIG_LOG_OUTPUT == OPENTHREAD_CONFIG_LOG_OUTPUT_NCP_SPINEL)
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2018, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief
|
||||
* This file defines the logging rtt interfaces and default constants used by logging_rtt.c.
|
||||
*/
|
||||
|
||||
#ifndef UTILS_LOGGING_RTT_H
|
||||
#define UTILS_LOGGING_RTT_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "openthread-core-config.h"
|
||||
#include <openthread/config.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def LOG_RTT_BUFFER_INDEX
|
||||
*
|
||||
* RTT's buffer index.
|
||||
*
|
||||
*/
|
||||
#ifndef LOG_RTT_BUFFER_INDEX
|
||||
#define LOG_RTT_BUFFER_INDEX 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def LOG_RTT_BUFFER_NAME
|
||||
*
|
||||
* RTT's name.
|
||||
*
|
||||
*/
|
||||
#ifndef LOG_RTT_BUFFER_NAME
|
||||
#define LOG_RTT_BUFFER_NAME "Terminal"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def LOG_RTT_BUFFER_SIZE
|
||||
*
|
||||
* LOG RTT's buffer size.
|
||||
*
|
||||
*/
|
||||
#ifndef LOG_RTT_BUFFER_SIZE
|
||||
#define LOG_RTT_BUFFER_SIZE 256
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def LOG_RTT_COLOR_ENABLE
|
||||
*
|
||||
* Enable colors on RTT Viewer.
|
||||
*
|
||||
*/
|
||||
#ifndef LOG_RTT_COLOR_ENABLE
|
||||
#define LOG_RTT_COLOR_ENABLE 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def LOG_PARSE_BUFFER_SIZE
|
||||
*
|
||||
* LOG buffer used to parse print format. It will be locally allocated on the
|
||||
* stack.
|
||||
*
|
||||
*/
|
||||
#ifndef LOG_PARSE_BUFFER_SIZE
|
||||
#define LOG_PARSE_BUFFER_SIZE 128
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @def LOG_TIMESTAMP_ENABLE
|
||||
*
|
||||
* Enable timestamp in the logs.
|
||||
*
|
||||
*/
|
||||
#ifndef LOG_TIMESTAMP_ENABLE
|
||||
#define LOG_TIMESTAMP_ENABLE 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Initialization of Logger driver.
|
||||
*
|
||||
*/
|
||||
void utilsLogRttInit(void);
|
||||
|
||||
/**
|
||||
* Deinitialization of Logger driver.
|
||||
*
|
||||
*/
|
||||
void utilsLogRttDeinit(void);
|
||||
|
||||
/**
|
||||
* This function outputs logs to SEGGER RTT.
|
||||
*
|
||||
* @param[in] aLogLevel The log level.
|
||||
* @param[in] aLogRegion The log region.
|
||||
* @param[in] aFormat A pointer to the format string.
|
||||
* @param[in] ap va_list matching information for aFormat
|
||||
*
|
||||
*/
|
||||
void utilsLogRttOutput(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat, va_list ap);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // UTILS_LOGGING_RTT_H
|
||||
Reference in New Issue
Block a user