mirror of https://github.com/ARMmbed/mbed-os.git
Squashed 'features/FEATURE_COMMON_PAL/mbed-trace/' changes from 31e338c23..af5f59cd2
af5f59cd2 Add CMakeLists.txt to support PAL Tools (#61) 24e16e766 Fix header documentation (#58) 23ea8f51c Update README.md (#57) 99aaa6eef Provide environment-agnostic configuration macros. (#54) da9eb9f3a Merge pull request #53 from ARMmbed/max_trace_level 0a51dcae8 Flash size can be limited by defining MBED_TRACE_MAX_LEVEL git-subtree-dir: features/FEATURE_COMMON_PAL/mbed-trace git-subtree-split: af5f59cd2cbac4064875be0c339da114d88fd5e1pull/3939/head^2
parent
7a4b3d11a3
commit
c8a16cc274
|
@ -0,0 +1 @@
|
||||||
|
/*CMakeLists.txt
|
|
@ -0,0 +1,17 @@
|
||||||
|
INCLUDE(CMakeForceCompiler)
|
||||||
|
|
||||||
|
cmake_minimum_required (VERSION 2.8)
|
||||||
|
SET(CMAKE_SYSTEM_NAME Generic)
|
||||||
|
|
||||||
|
project(mbedTrace)
|
||||||
|
|
||||||
|
|
||||||
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/mbed-trace/)
|
||||||
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../nanostack-libservice/mbed-client-libservice/)
|
||||||
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../nanostack-libservice/)
|
||||||
|
|
||||||
|
set (MBED_TRACE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/source/mbed_trace.c)
|
||||||
|
|
||||||
|
|
||||||
|
CREATE_LIBRARY(mbedTrace "${MBED_TRACE_SRC}" "")
|
||||||
|
|
18
README.md
18
README.md
|
@ -33,9 +33,9 @@ The purpose of the library is to provide a light, simple and general tracing sol
|
||||||
|
|
||||||
```
|
```
|
||||||
[DBG ][abc ]: This is a debug message from module abc<cr><lf>
|
[DBG ][abc ]: This is a debug message from module abc<cr><lf>
|
||||||
[ERR ][abc ]: Something goes wrong in module abc<cr><lf>
|
|
||||||
[WARN][br ]: Oh no, br warning occurs!<cr><lf>
|
|
||||||
[INFO][br ]: Hi there.<cr><lf>
|
[INFO][br ]: Hi there.<cr><lf>
|
||||||
|
[WARN][br ]: Oh no, br warning occurs!<cr><lf>
|
||||||
|
[ERR ][abc ]: Something goes wrong in module abc<cr><lf>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
@ -47,8 +47,10 @@ The purpose of the library is to provide a light, simple and general tracing sol
|
||||||
* To enable the tracing API:
|
* To enable the tracing API:
|
||||||
* With yotta: set `YOTTA_CFG_MBED_TRACE` to 1 or true. Setting the flag to 0 or false disables tracing.
|
* With yotta: set `YOTTA_CFG_MBED_TRACE` to 1 or true. Setting the flag to 0 or false disables tracing.
|
||||||
* [With mbed OS 5](#enabling-the-tracing-api-in-mbed-os-5)
|
* [With mbed OS 5](#enabling-the-tracing-api-in-mbed-os-5)
|
||||||
* By default, trace uses 1024 bytes buffer for trace lines, but you can change it by yotta with: `YOTTA_CFG_MBED_TRACE_LINE_LENGTH`.
|
* By default, trace uses 1024 bytes buffer for trace lines, but you can change it by setting the configuration macro `MBED_TRACE_LINE_LENGTH` to the desired value.
|
||||||
* To disable the IPv6 conversion, set `YOTTA_CFG_MBED_TRACE_FEA_IPV6 = 0`.
|
* To disable the IPv6 conversion:
|
||||||
|
* With yotta: set `YOTTA_CFG_MBED_TRACE_FEA_IPV6 = 0`.
|
||||||
|
* With mbed OS 5: set `MBED_CONF_MBED_TRACE_FEA_IPV6 = 0`.
|
||||||
* If thread safety is needed, configure the wait and release callback functions before initialization to enable the protection. Usually, this needs to be done only once in the application's lifetime.
|
* If thread safety is needed, configure the wait and release callback functions before initialization to enable the protection. Usually, this needs to be done only once in the application's lifetime.
|
||||||
* Call the trace initialization (`mbed_trace_init`) once before using any other APIs. It allocates the trace buffer and initializes the internal variables.
|
* Call the trace initialization (`mbed_trace_init`) once before using any other APIs. It allocates the trace buffer and initializes the internal variables.
|
||||||
* Define `TRACE_GROUP` in your source code (not in the header!) to use traces. It is a 1-4 characters long char-array (for example `#define TRACE_GROUP "APPL"`). This will be printed on every trace line.
|
* Define `TRACE_GROUP` in your source code (not in the header!) to use traces. It is a 1-4 characters long char-array (for example `#define TRACE_GROUP "APPL"`). This will be printed on every trace line.
|
||||||
|
@ -82,9 +84,9 @@ When you want to print traces, use the `tr_<level>` macros. The macros behave li
|
||||||
Available levels:
|
Available levels:
|
||||||
|
|
||||||
* debug
|
* debug
|
||||||
|
* info
|
||||||
* warning
|
* warning
|
||||||
* error
|
* error
|
||||||
* info
|
|
||||||
* cmdline (special behavior, should not be used)
|
* cmdline (special behavior, should not be used)
|
||||||
|
|
||||||
For the thread safety, set the mutex wait and release functions. You need do this before the initialization to have the functions available right away:
|
For the thread safety, set the mutex wait and release functions. You need do this before the initialization to have the functions available right away:
|
||||||
|
@ -128,7 +130,7 @@ See more in [mbed_trace.h](https://github.com/ARMmbed/mbed-trace/blob/master/mbe
|
||||||
## Usage example:
|
## Usage example:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
#define YOTTA_CFG_MBED_TRACE 1 //this can be defined also in the yotta configuration file config.json
|
#define MBED_CONF_MBED_TRACE_ENABLE 1 //this could be defined also in the mbed-cli configuration file mbed_app.json
|
||||||
#include "mbed-trace/mbed_trace.h"
|
#include "mbed-trace/mbed_trace.h"
|
||||||
#define TRACE_GROUP "main"
|
#define TRACE_GROUP "main"
|
||||||
|
|
||||||
|
@ -148,9 +150,9 @@ int main(void){
|
||||||
mbed_trace_mutex_release_function_set( my_mutex_release ); // only if thread safety is needed
|
mbed_trace_mutex_release_function_set( my_mutex_release ); // only if thread safety is needed
|
||||||
mbed_trace_init(); // initialize the trace library
|
mbed_trace_init(); // initialize the trace library
|
||||||
tr_debug("this is debug msg"); //-> "[DBG ][main]: this is a debug msg"
|
tr_debug("this is debug msg"); //-> "[DBG ][main]: this is a debug msg"
|
||||||
tr_err("this is error msg"); //-> "[ERR ][main]: this is an error msg"
|
|
||||||
tr_warn("this is warning msg"); //-> "[WARN][main]: this is a warning msg"
|
|
||||||
tr_info("this is info msg"); //-> "[INFO][main]: this is an info msg"
|
tr_info("this is info msg"); //-> "[INFO][main]: this is an info msg"
|
||||||
|
tr_warn("this is warning msg"); //-> "[WARN][main]: this is a warning msg"
|
||||||
|
tr_err("this is error msg"); //-> "[ERR ][main]: this is an error msg"
|
||||||
char arr[] = {30, 31, 32};
|
char arr[] = {30, 31, 32};
|
||||||
tr_debug("printing array: %s", mbed_trace_array(arr, 3)); //-> "[DBG ][main]: printing array: 01:02:03"
|
tr_debug("printing array: %s", mbed_trace_array(arr, 3)); //-> "[DBG ][main]: printing array: 01:02:03"
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -18,8 +18,8 @@
|
||||||
* \file mbed_trace.h
|
* \file mbed_trace.h
|
||||||
* Trace interface for MbedOS applications.
|
* Trace interface for MbedOS applications.
|
||||||
* This file provide simple but flexible way to handle software traces.
|
* This file provide simple but flexible way to handle software traces.
|
||||||
* Trace library are abstract layer, which use stdout (printf) by default,
|
* Trace library are abstract layer, which use stdout (printf) by default,
|
||||||
* but outputs can be easily redirect to custom function, for example to
|
* but outputs can be easily redirect to custom function, for example to
|
||||||
* store traces to memory or other interfaces.
|
* store traces to memory or other interfaces.
|
||||||
*
|
*
|
||||||
* usage example:
|
* usage example:
|
||||||
|
@ -30,14 +30,15 @@
|
||||||
* int main(void){
|
* int main(void){
|
||||||
* mbed_trace_init(); // initialize trace library
|
* mbed_trace_init(); // initialize trace library
|
||||||
* tr_debug("this is debug msg"); //print debug message to stdout: "[DBG]
|
* tr_debug("this is debug msg"); //print debug message to stdout: "[DBG]
|
||||||
* tr_err("this is error msg");
|
|
||||||
* tr_warn("this is warning msg");
|
|
||||||
* tr_info("this is info msg");
|
* tr_info("this is info msg");
|
||||||
|
* tr_warn("this is warning msg");
|
||||||
|
* tr_err("this is error msg");
|
||||||
* return 0;
|
* return 0;
|
||||||
* }
|
* }
|
||||||
* \endcode
|
* \endcode
|
||||||
* Activate with compiler flag: YOTTA_CFG_MBED_TRACE
|
* Activate with compiler flag: YOTTA_CFG_MBED_TRACE
|
||||||
* Configure trace line buffer size with compiler flag: YOTTA_CFG_MBED_TRACE_LINE_LENGTH. Default length: 1024.
|
* Configure trace line buffer size with compiler flag: YOTTA_CFG_MBED_TRACE_LINE_LENGTH. Default length: 1024.
|
||||||
|
* Limit the size of flash by setting MBED_TRACE_MAX_LEVEL value. Default is TRACE_LEVEL_DEBUG (all included)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef MBED_TRACE_H_
|
#ifndef MBED_TRACE_H_
|
||||||
|
@ -63,12 +64,19 @@ extern "C" {
|
||||||
|
|
||||||
#ifndef YOTTA_CFG_MBED_TRACE_FEA_IPV6
|
#ifndef YOTTA_CFG_MBED_TRACE_FEA_IPV6
|
||||||
#define YOTTA_CFG_MBED_TRACE_FEA_IPV6 1
|
#define YOTTA_CFG_MBED_TRACE_FEA_IPV6 1
|
||||||
|
#else
|
||||||
|
#warning YOTTA_CFG_MBED_TRACE_FEA_IPV6 is deprecated and will be removed in the future! Use MBED_CONF_MBED_TRACE_FEA_IPV6 instead.
|
||||||
|
#define MBED_CONF_MBED_TRACE_FEA_IPV6 YOTTA_CFG_MBED_TRACE_FEA_IPV6
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MBED_CONF_MBED_TRACE_ENABLE
|
#ifndef MBED_CONF_MBED_TRACE_ENABLE
|
||||||
#define MBED_CONF_MBED_TRACE_ENABLE 0
|
#define MBED_CONF_MBED_TRACE_ENABLE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MBED_CONF_MBED_TRACE_FEA_IPV6
|
||||||
|
#define MBED_CONF_MBED_TRACE_FEA_IPV6 1
|
||||||
|
#endif
|
||||||
|
|
||||||
/** 3 upper bits are trace modes related,
|
/** 3 upper bits are trace modes related,
|
||||||
and 5 lower bits are trace level configuration */
|
and 5 lower bits are trace level configuration */
|
||||||
|
|
||||||
|
@ -110,13 +118,39 @@ extern "C" {
|
||||||
/** special level for cmdline. Behaviours like "plain mode" */
|
/** special level for cmdline. Behaviours like "plain mode" */
|
||||||
#define TRACE_LEVEL_CMD 0x01
|
#define TRACE_LEVEL_CMD 0x01
|
||||||
|
|
||||||
|
#ifndef MBED_TRACE_MAX_LEVEL
|
||||||
|
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_DEBUG
|
||||||
|
#endif
|
||||||
|
|
||||||
//usage macros:
|
//usage macros:
|
||||||
#define tr_info(...) mbed_tracef(TRACE_LEVEL_INFO, TRACE_GROUP, __VA_ARGS__) //!< Print info message
|
#if MBED_TRACE_MAX_LEVEL >= TRACE_LEVEL_DEBUG
|
||||||
#define tr_debug(...) mbed_tracef(TRACE_LEVEL_DEBUG, TRACE_GROUP, __VA_ARGS__) //!< Print debug message
|
#define tr_debug(...) mbed_tracef(TRACE_LEVEL_DEBUG, TRACE_GROUP, __VA_ARGS__) //!< Print debug message
|
||||||
|
#else
|
||||||
|
#define tr_debug(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MBED_TRACE_MAX_LEVEL >= TRACE_LEVEL_INFO
|
||||||
|
#define tr_info(...) mbed_tracef(TRACE_LEVEL_INFO, TRACE_GROUP, __VA_ARGS__) //!< Print info message
|
||||||
|
#else
|
||||||
|
#define tr_info(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MBED_TRACE_MAX_LEVEL >= TRACE_LEVEL_WARN
|
||||||
#define tr_warning(...) mbed_tracef(TRACE_LEVEL_WARN, TRACE_GROUP, __VA_ARGS__) //!< Print warning message
|
#define tr_warning(...) mbed_tracef(TRACE_LEVEL_WARN, TRACE_GROUP, __VA_ARGS__) //!< Print warning message
|
||||||
#define tr_warn(...) mbed_tracef(TRACE_LEVEL_WARN, TRACE_GROUP, __VA_ARGS__) //!< Alternative warning message
|
#define tr_warn(...) mbed_tracef(TRACE_LEVEL_WARN, TRACE_GROUP, __VA_ARGS__) //!< Alternative warning message
|
||||||
|
#else
|
||||||
|
#define tr_warning(...)
|
||||||
|
#define tr_warn(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MBED_TRACE_MAX_LEVEL >= TRACE_LEVEL_ERROR
|
||||||
#define tr_error(...) mbed_tracef(TRACE_LEVEL_ERROR, TRACE_GROUP, __VA_ARGS__) //!< Print Error Message
|
#define tr_error(...) mbed_tracef(TRACE_LEVEL_ERROR, TRACE_GROUP, __VA_ARGS__) //!< Print Error Message
|
||||||
#define tr_err(...) mbed_tracef(TRACE_LEVEL_ERROR, TRACE_GROUP, __VA_ARGS__) //!< Alternative error message
|
#define tr_err(...) mbed_tracef(TRACE_LEVEL_ERROR, TRACE_GROUP, __VA_ARGS__) //!< Alternative error message
|
||||||
|
#else
|
||||||
|
#define tr_error(...)
|
||||||
|
#define tr_err(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define tr_cmdline(...) mbed_tracef(TRACE_LEVEL_CMD, TRACE_GROUP, __VA_ARGS__) //!< Special print for cmdline. See more from TRACE_LEVEL_CMD -level
|
#define tr_cmdline(...) mbed_tracef(TRACE_LEVEL_CMD, TRACE_GROUP, __VA_ARGS__) //!< Special print for cmdline. See more from TRACE_LEVEL_CMD -level
|
||||||
|
|
||||||
//aliases for the most commonly used functions and the helper functions
|
//aliases for the most commonly used functions and the helper functions
|
||||||
|
@ -180,7 +214,7 @@ void mbed_trace_buffer_sizes(int lineLength, int tmpLength);
|
||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
void mbed_trace_config_set(uint8_t config);
|
void mbed_trace_config_set(uint8_t config);
|
||||||
/** get trace configurations
|
/** get trace configurations
|
||||||
* @return trace configuration byte
|
* @return trace configuration byte
|
||||||
*/
|
*/
|
||||||
uint8_t mbed_trace_config_get(void);
|
uint8_t mbed_trace_config_get(void);
|
||||||
|
@ -232,7 +266,7 @@ void mbed_trace_mutex_release_function_set(void (*mutex_release_f)(void));
|
||||||
/**
|
/**
|
||||||
* When trace group contains text in filters,
|
* When trace group contains text in filters,
|
||||||
* trace print will be ignored.
|
* trace print will be ignored.
|
||||||
* e.g.:
|
* e.g.:
|
||||||
* mbed_trace_exclude_filters_set("mygr");
|
* mbed_trace_exclude_filters_set("mygr");
|
||||||
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "ougr", "This is not printed");
|
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "ougr", "This is not printed");
|
||||||
*/
|
*/
|
||||||
|
@ -294,7 +328,7 @@ void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap);
|
||||||
* Get last trace from buffer
|
* Get last trace from buffer
|
||||||
*/
|
*/
|
||||||
const char* mbed_trace_last(void);
|
const char* mbed_trace_last(void);
|
||||||
#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1
|
#if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1
|
||||||
/**
|
/**
|
||||||
* mbed_tracef helping function for convert ipv6
|
* mbed_tracef helping function for convert ipv6
|
||||||
* table to human readable string.
|
* table to human readable string.
|
||||||
|
@ -327,7 +361,7 @@ char* mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len);
|
||||||
* @param buf hex array pointer
|
* @param buf hex array pointer
|
||||||
* @param len buffer length
|
* @param len buffer length
|
||||||
* @return temporary buffer where string copied
|
* @return temporary buffer where string copied
|
||||||
* if array as string not fit to temp buffer, this function write '*' as last character,
|
* if array as string not fit to temp buffer, this function write '*' as last character,
|
||||||
* which indicate that buffer is too small for array.
|
* which indicate that buffer is too small for array.
|
||||||
*/
|
*/
|
||||||
char* mbed_trace_array(const uint8_t* buf, uint16_t len);
|
char* mbed_trace_array(const uint8_t* buf, uint16_t len);
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
"enable": {
|
"enable": {
|
||||||
"help": "Used to globally enable traces.",
|
"help": "Used to globally enable traces.",
|
||||||
"value": null
|
"value": null
|
||||||
|
},
|
||||||
|
"fea-ipv6": {
|
||||||
|
"help": "Used to globally disable ipv6 tracing features.",
|
||||||
|
"value": null
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,13 +17,16 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#ifndef YOTTA_CFG_MBED_TRACE
|
#ifdef MBED_CONF_MBED_TRACE_ENABLE
|
||||||
#define YOTTA_CFG_MBED_TRACE 1
|
#undef MBED_CONF_MBED_TRACE_ENABLE
|
||||||
#define YOTTA_CFG_MBED_TRACE_FEA_IPV6 1
|
#endif
|
||||||
|
#define MBED_CONF_MBED_TRACE_ENABLE 1
|
||||||
|
#ifndef MBED_CONF_MBED_TRACE_FEA_IPV6
|
||||||
|
#define MBED_CONF_MBED_TRACE_FEA_IPV6 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "mbed-trace/mbed_trace.h"
|
#include "mbed-trace/mbed_trace.h"
|
||||||
#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1
|
#if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1
|
||||||
#include "mbed-client-libservice/ip6string.h"
|
#include "mbed-client-libservice/ip6string.h"
|
||||||
#include "mbed-client-libservice/common_functions.h"
|
#include "mbed-client-libservice/common_functions.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -52,23 +55,42 @@
|
||||||
#define VT100_COLOR_DEBUG "\x1b[90m"
|
#define VT100_COLOR_DEBUG "\x1b[90m"
|
||||||
|
|
||||||
/** default max trace line size in bytes */
|
/** default max trace line size in bytes */
|
||||||
#ifdef YOTTA_CFG_MBED_TRACE_LINE_LENGTH
|
#ifdef MBED_TRACE_LINE_LENGTH
|
||||||
|
#define DEFAULT_TRACE_LINE_LENGTH MBED_TRACE_LINE_LENGTH
|
||||||
|
#elif defined YOTTA_CFG_MBED_TRACE_LINE_LENGTH
|
||||||
|
#warning YOTTA_CFG_MBED_TRACE_LINE_LENGTH is deprecated and will be removed in the future! Use MBED_TRACE_LINE_LENGTH instead.
|
||||||
#define DEFAULT_TRACE_LINE_LENGTH YOTTA_CFG_MBED_TRACE_LINE_LENGTH
|
#define DEFAULT_TRACE_LINE_LENGTH YOTTA_CFG_MBED_TRACE_LINE_LENGTH
|
||||||
#else
|
#else
|
||||||
#define DEFAULT_TRACE_LINE_LENGTH 1024
|
#define DEFAULT_TRACE_LINE_LENGTH 1024
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** default max temporary buffer size in bytes, used in
|
/** default max temporary buffer size in bytes, used in
|
||||||
trace_ipv6, trace_ipv6_prefix and trace_array */
|
trace_ipv6, trace_ipv6_prefix and trace_array */
|
||||||
#ifdef YOTTA_CFG_MBED_TRACE_TMP_LINE_LEN
|
#ifdef MBED_TRACE_TMP_LINE_LENGTH
|
||||||
|
#define DEFAULT_TRACE_TMP_LINE_LEN MBED_TRACE_TMP_LINE_LENGTH
|
||||||
|
#elif defined YOTTA_CFG_MBED_TRACE_TMP_LINE_LEN
|
||||||
|
#warning The YOTTA_CFG_MBED_TRACE_TMP_LINE_LEN flag is deprecated and will be removed in the future! Use MBED_TRACE_TMP_LINE_LENGTH instead.
|
||||||
#define DEFAULT_TRACE_TMP_LINE_LEN YOTTA_CFG_MBED_TRACE_TMP_LINE_LEN
|
#define DEFAULT_TRACE_TMP_LINE_LEN YOTTA_CFG_MBED_TRACE_TMP_LINE_LEN
|
||||||
#elif defined YOTTA_CFG_MTRACE_TMP_LINE_LEN
|
#elif defined YOTTA_CFG_MTRACE_TMP_LINE_LEN
|
||||||
#warning The YOTTA_CFG_MTRACE_TMP_LINE_LEN flag is deprecated! Use YOTTA_CFG_MBED_TRACE_TMP_LINE_LEN instead.
|
#warning The YOTTA_CFG_MTRACE_TMP_LINE_LEN flag is deprecated and will be removed in the future! Use MBED_TRACE_TMP_LINE_LENGTH instead.
|
||||||
#define DEFAULT_TRACE_TMP_LINE_LEN YOTTA_CFG_MTRACE_TMP_LINE_LEN
|
#define DEFAULT_TRACE_TMP_LINE_LEN YOTTA_CFG_MTRACE_TMP_LINE_LEN
|
||||||
#else
|
#else
|
||||||
#define DEFAULT_TRACE_TMP_LINE_LEN 128
|
#define DEFAULT_TRACE_TMP_LINE_LEN 128
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** default max filters (include/exclude) length in bytes */
|
/** default max filters (include/exclude) length in bytes */
|
||||||
|
#ifdef MBED_TRACE_FILTER_LENGTH
|
||||||
|
#define DEFAULT_TRACE_FILTER_LENGTH MBED_TRACE_FILTER_LENGTH
|
||||||
|
#else
|
||||||
#define DEFAULT_TRACE_FILTER_LENGTH 24
|
#define DEFAULT_TRACE_FILTER_LENGTH 24
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** default trace configuration bitmask */
|
||||||
|
#ifdef MBED_TRACE_CONFIG
|
||||||
|
#define DEFAULT_TRACE_CONFIG MBED_TRACE_CONFIG
|
||||||
|
#else
|
||||||
|
#define DEFAULT_TRACE_CONFIG TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL | TRACE_CARRIAGE_RETURN
|
||||||
|
#endif
|
||||||
|
|
||||||
/** default print function, just redirect str to printf */
|
/** default print function, just redirect str to printf */
|
||||||
static void mbed_trace_realloc( char **buffer, int *length_ptr, int new_length);
|
static void mbed_trace_realloc( char **buffer, int *length_ptr, int new_length);
|
||||||
|
@ -112,13 +134,17 @@ typedef struct trace_s {
|
||||||
} trace_t;
|
} trace_t;
|
||||||
|
|
||||||
static trace_t m_trace = {
|
static trace_t m_trace = {
|
||||||
|
.trace_config = DEFAULT_TRACE_CONFIG,
|
||||||
.filters_exclude = 0,
|
.filters_exclude = 0,
|
||||||
.filters_include = 0,
|
.filters_include = 0,
|
||||||
|
.filters_length = DEFAULT_TRACE_FILTER_LENGTH,
|
||||||
.line = 0,
|
.line = 0,
|
||||||
|
.line_length = DEFAULT_TRACE_LINE_LENGTH,
|
||||||
.tmp_data = 0,
|
.tmp_data = 0,
|
||||||
|
.tmp_data_length = DEFAULT_TRACE_TMP_LINE_LEN,
|
||||||
.prefix_f = 0,
|
.prefix_f = 0,
|
||||||
.suffix_f = 0,
|
.suffix_f = 0,
|
||||||
.printf = 0,
|
.printf = mbed_trace_default_print,
|
||||||
.cmd_printf = 0,
|
.cmd_printf = 0,
|
||||||
.mutex_wait_f = 0,
|
.mutex_wait_f = 0,
|
||||||
.mutex_release_f = 0,
|
.mutex_release_f = 0,
|
||||||
|
@ -127,17 +153,15 @@ static trace_t m_trace = {
|
||||||
|
|
||||||
int mbed_trace_init(void)
|
int mbed_trace_init(void)
|
||||||
{
|
{
|
||||||
m_trace.trace_config = TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL | TRACE_CARRIAGE_RETURN;
|
|
||||||
m_trace.line_length = DEFAULT_TRACE_LINE_LENGTH;
|
|
||||||
if (m_trace.line == NULL) {
|
if (m_trace.line == NULL) {
|
||||||
m_trace.line = MBED_TRACE_MEM_ALLOC(m_trace.line_length);
|
m_trace.line = MBED_TRACE_MEM_ALLOC(m_trace.line_length);
|
||||||
}
|
}
|
||||||
m_trace.tmp_data_length = DEFAULT_TRACE_TMP_LINE_LEN;
|
|
||||||
if (m_trace.tmp_data == NULL) {
|
if (m_trace.tmp_data == NULL) {
|
||||||
m_trace.tmp_data = MBED_TRACE_MEM_ALLOC(m_trace.tmp_data_length);
|
m_trace.tmp_data = MBED_TRACE_MEM_ALLOC(m_trace.tmp_data_length);
|
||||||
}
|
}
|
||||||
m_trace.tmp_data_ptr = m_trace.tmp_data;
|
m_trace.tmp_data_ptr = m_trace.tmp_data;
|
||||||
m_trace.filters_length = DEFAULT_TRACE_FILTER_LENGTH;
|
|
||||||
if (m_trace.filters_exclude == NULL) {
|
if (m_trace.filters_exclude == NULL) {
|
||||||
m_trace.filters_exclude = MBED_TRACE_MEM_ALLOC(m_trace.filters_length);
|
m_trace.filters_exclude = MBED_TRACE_MEM_ALLOC(m_trace.filters_length);
|
||||||
}
|
}
|
||||||
|
@ -158,29 +182,28 @@ int mbed_trace_init(void)
|
||||||
memset(m_trace.filters_include, 0, m_trace.filters_length);
|
memset(m_trace.filters_include, 0, m_trace.filters_length);
|
||||||
memset(m_trace.line, 0, m_trace.line_length);
|
memset(m_trace.line, 0, m_trace.line_length);
|
||||||
|
|
||||||
m_trace.prefix_f = 0;
|
|
||||||
m_trace.suffix_f = 0;
|
|
||||||
m_trace.printf = mbed_trace_default_print;
|
|
||||||
m_trace.cmd_printf = 0;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void mbed_trace_free(void)
|
void mbed_trace_free(void)
|
||||||
{
|
{
|
||||||
|
// release memory
|
||||||
MBED_TRACE_MEM_FREE(m_trace.line);
|
MBED_TRACE_MEM_FREE(m_trace.line);
|
||||||
m_trace.line_length = 0;
|
|
||||||
m_trace.line = 0;
|
|
||||||
MBED_TRACE_MEM_FREE(m_trace.tmp_data);
|
MBED_TRACE_MEM_FREE(m_trace.tmp_data);
|
||||||
m_trace.tmp_data = 0;
|
|
||||||
m_trace.tmp_data_ptr = 0;
|
|
||||||
MBED_TRACE_MEM_FREE(m_trace.filters_exclude);
|
MBED_TRACE_MEM_FREE(m_trace.filters_exclude);
|
||||||
m_trace.filters_exclude = 0;
|
|
||||||
MBED_TRACE_MEM_FREE(m_trace.filters_include);
|
MBED_TRACE_MEM_FREE(m_trace.filters_include);
|
||||||
|
|
||||||
|
// reset to default values
|
||||||
|
m_trace.trace_config = DEFAULT_TRACE_CONFIG;
|
||||||
|
m_trace.filters_exclude = 0;
|
||||||
m_trace.filters_include = 0;
|
m_trace.filters_include = 0;
|
||||||
m_trace.filters_length = 0;
|
m_trace.filters_length = DEFAULT_TRACE_FILTER_LENGTH;
|
||||||
|
m_trace.line = 0;
|
||||||
|
m_trace.line_length = DEFAULT_TRACE_LINE_LENGTH;
|
||||||
|
m_trace.tmp_data = 0;
|
||||||
|
m_trace.tmp_data_length = DEFAULT_TRACE_TMP_LINE_LEN;
|
||||||
m_trace.prefix_f = 0;
|
m_trace.prefix_f = 0;
|
||||||
m_trace.suffix_f = 0;
|
m_trace.suffix_f = 0;
|
||||||
m_trace.printf = mbed_trace_default_print;
|
m_trace.printf = mbed_trace_default_print;
|
||||||
m_trace.cmd_printf = 0;
|
m_trace.cmd_printf = 0;
|
||||||
m_trace.mutex_wait_f = 0;
|
m_trace.mutex_wait_f = 0;
|
||||||
m_trace.mutex_release_f = 0;
|
m_trace.mutex_release_f = 0;
|
||||||
|
@ -480,7 +503,7 @@ const char *mbed_trace_last(void)
|
||||||
}
|
}
|
||||||
/* Helping functions */
|
/* Helping functions */
|
||||||
#define tmp_data_left() m_trace.tmp_data_length-(m_trace.tmp_data_ptr-m_trace.tmp_data)
|
#define tmp_data_left() m_trace.tmp_data_length-(m_trace.tmp_data_ptr-m_trace.tmp_data)
|
||||||
#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1
|
#if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1
|
||||||
char *mbed_trace_ipv6(const void *addr_ptr)
|
char *mbed_trace_ipv6(const void *addr_ptr)
|
||||||
{
|
{
|
||||||
/** Acquire mutex. It is released before returning from mbed_vtracef. */
|
/** Acquire mutex. It is released before returning from mbed_vtracef. */
|
||||||
|
@ -524,7 +547,7 @@ char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
|
||||||
m_trace.tmp_data_ptr += ip6_prefix_tos(prefix, prefix_len, str) + 1;
|
m_trace.tmp_data_ptr += ip6_prefix_tos(prefix, prefix_len, str) + 1;
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
#endif //YOTTA_CFG_MBED_TRACE_FEA_IPV6
|
#endif //MBED_CONF_MBED_TRACE_FEA_IPV6
|
||||||
char *mbed_trace_array(const uint8_t *buf, uint16_t len)
|
char *mbed_trace_array(const uint8_t *buf, uint16_t len)
|
||||||
{
|
{
|
||||||
/** Acquire mutex. It is released before returning from mbed_vtracef. */
|
/** Acquire mutex. It is released before returning from mbed_vtracef. */
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
#include "mbed-cpputest/CppUTest/SimpleString.h"
|
#include "mbed-cpputest/CppUTest/SimpleString.h"
|
||||||
#include "mbed-cpputest/CppUTest/CommandLineTestRunner.h"
|
#include "mbed-cpputest/CppUTest/CommandLineTestRunner.h"
|
||||||
|
|
||||||
#define YOTTA_CFG_MBED_TRACE 1
|
#define MBED_CONF_MBED_TRACE_ENABLE 1
|
||||||
#define YOTTA_CFG_MBED_TRACE_FEA_IPV6 1
|
#define MBED_CONF_MBED_TRACE_FEA_IPV6 1
|
||||||
|
|
||||||
#include "mbed-trace/mbed_trace.h"
|
#include "mbed-trace/mbed_trace.h"
|
||||||
#include "ip6tos_stub.h"
|
#include "ip6tos_stub.h"
|
||||||
|
@ -118,6 +118,7 @@ TEST(trace, BufferResize)
|
||||||
{
|
{
|
||||||
uint8_t arr[20] = {0};
|
uint8_t arr[20] = {0};
|
||||||
memset(arr, '0', 20);
|
memset(arr, '0', 20);
|
||||||
|
|
||||||
mbed_trace_buffer_sizes(0, 10);
|
mbed_trace_buffer_sizes(0, 10);
|
||||||
STRCMP_EQUAL("30:30:30*", mbed_trace_array(arr, 20));
|
STRCMP_EQUAL("30:30:30*", mbed_trace_array(arr, 20));
|
||||||
mbed_trace_buffer_sizes(0, 15);
|
mbed_trace_buffer_sizes(0, 15);
|
||||||
|
@ -125,7 +126,38 @@ TEST(trace, BufferResize)
|
||||||
mbed_trace_buffer_sizes(0, 15);
|
mbed_trace_buffer_sizes(0, 15);
|
||||||
STRCMP_EQUAL("30:30:30:30", mbed_trace_array(arr, 4));
|
STRCMP_EQUAL("30:30:30:30", mbed_trace_array(arr, 4));
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "flush buffers and locks");
|
const char * expectedStr = "0123456789";
|
||||||
|
mbed_trace_buffer_sizes(11, 0);
|
||||||
|
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789");
|
||||||
|
STRCMP_EQUAL(expectedStr, buf);
|
||||||
|
expectedStr = "012345678901234";
|
||||||
|
mbed_trace_buffer_sizes(16, 0);
|
||||||
|
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789");
|
||||||
|
STRCMP_EQUAL(expectedStr, buf);
|
||||||
|
expectedStr = "012345678901234";
|
||||||
|
mbed_trace_buffer_sizes(16, 0);
|
||||||
|
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "012345678901234");
|
||||||
|
STRCMP_EQUAL(expectedStr, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(trace, PreInitConfiguration)
|
||||||
|
{
|
||||||
|
uint8_t arr[20] = {0};
|
||||||
|
memset(arr, '0', 20);
|
||||||
|
|
||||||
|
mbed_trace_free();
|
||||||
|
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL);
|
||||||
|
mbed_trace_print_function_set( myprint );
|
||||||
|
mbed_trace_buffer_sizes(11, 10);
|
||||||
|
mbed_trace_mutex_wait_function_set( my_mutex_wait );
|
||||||
|
mbed_trace_mutex_release_function_set( my_mutex_release );
|
||||||
|
mbed_trace_init();
|
||||||
|
|
||||||
|
STRCMP_EQUAL("30:30:30*", mbed_trace_array(arr, 20));
|
||||||
|
|
||||||
|
const char * expectedStr = "0123456789";
|
||||||
|
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789");
|
||||||
|
STRCMP_EQUAL(expectedStr, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1
|
#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1
|
||||||
|
|
Loading…
Reference in New Issue