CARPLAY版本整理

This commit is contained in:
2025-01-21 16:49:37 +08:00
commit f0fb64e4e6
26542 changed files with 13719676 additions and 0 deletions

View File

@ -0,0 +1,32 @@
#include <stdio.h>
#include <FreeRTOS.h>
#include "board.h"
#include "ulog.h"
#ifdef ULOG_BACKEND_USING_CONSOLE
#if defined(ULOG_ASYNC_OUTPUT_BY_THREAD) && ULOG_ASYNC_OUTPUT_THREAD_STACK < 384
#error "The thread stack size must more than 384 when using async output by thread (ULOG_ASYNC_OUTPUT_BY_THREAD)"
#endif
static struct ulog_backend console;
void ulog_console_backend_output(struct ulog_backend *backend, uint32_t level, const char *tag, int is_raw,
const char *log, size_t len)
{
int i;
for (i = 0; i < len; i++)
putchar(log[i]);
}
int ulog_console_backend_init(void)
{
console.output = ulog_console_backend_output;
ulog_backend_register(&console, "console", pdFALSE);
return 0;
}
#endif /* ULOG_BACKEND_USING_CONSOLE */

View File

@ -0,0 +1,38 @@
/*
* This file is part of the EasyFlash Library.
*
* Copyright (c) 2014-2018, Armink, <armink.ztl@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* 'Software'), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* The ulog flash plugin by EasyFlash.
* Created on: 2018-10-22
*/
#ifndef _ULOG_EASYFLASH_H_
#define _ULOG_EASYFLASH_H_
int ulog_ef_backend_init(void);
void ulog_ef_log_clean(void);
void ulog_ef_log_lvl_set(uint32_t level);
int ulog_ef_filter_cfg_load(void);
void ulog_ef_filter_cfg_save(void);
#endif /* _ULOG_EASYFLASH_H_ */

View File

@ -0,0 +1,177 @@
/*
* This file is part of the EasyFlash Library.
*
* Copyright (c) 2014-2018, Armink, <armink.ztl@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* 'Software'), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* The ulog backend implementation for EasyFlash.
* Created on: 2018-10-22
*/
#include <stdio.h>
#include <string.h>
#include <FreeRTOS.h>
#include <easyflash.h>
#include "board.h"
#define LOG_TAG "easyflash"
#include <ulog.h>
#define ALIGN_DOWN(size, align) ((size) & ~((align) - 1))
#ifdef ULOG_EASYFLASH_BACKEND_ENABLE
#if defined(ULOG_ASYNC_OUTPUT_BY_THREAD) && ULOG_ASYNC_OUTPUT_THREAD_STACK < 1024
#error "The thread stack size must more than 1024 when using async output by thread (ULOG_ASYNC_OUTPUT_BY_THREAD)"
#endif
static struct ulog_backend flash_backend;
static uint32_t log_saving_lvl = LOG_FILTER_LVL_ALL;
/**
* Read and output log to console.
*
* @param index index for saved log.
* Minimum index is 0.
* Maximum index is log used flash total size - 1.
* @param size
*/
void read_flash_log(uint8_t *logbuf, size_t index, size_t size)
{
/* 64 bytes buffer */
uint32_t buf[512] = { 0 };
size_t log_total_size = ef_log_get_used_size();
size_t buf_size = sizeof(buf);
size_t read_size = 0;
/* word alignment for index and size */
index = ALIGN_DOWN(index, 4);
size = ALIGN_DOWN(size, 4);
if (index + size > log_total_size)
{
printf("The output position and size is out of bound. The max size is %d.\n", log_total_size);
return;
}
while (1)
{
if (read_size + buf_size < size)
{
ef_log_read(index + read_size, buf, buf_size);
memcpy(logbuf + read_size, buf, buf_size);
read_size += buf_size;
}
else
{
ef_log_read(index + read_size, buf, size - read_size);
memcpy(logbuf + read_size, buf, size - read_size);
break;
}
}
}
/**
* Read and output recent log which saved in flash.
*
* @param size recent log size
*/
size_t read_recent_flash_log(void *buf, size_t size)
{
size_t max_size = ef_log_get_used_size();
if (size == 0)
{
return 0;
}
else if (size > max_size)
{
size = max_size;
}
read_flash_log(buf, max_size - size, size);
return size;
}
/**
* clean all log which in flash
*/
void ulog_ef_log_clean(void)
{
EfErrCode clean_result = EF_NO_ERR;
/* clean all log which in flash */
clean_result = ef_log_clean();
if (clean_result == EF_NO_ERR)
{
TRACE_INFO("All logs which in flash is clean OK.");
}
else
{
TRACE_ERROR("Clean logs which in flash has an error!");
}
}
static void ulog_easyflash_backend_output(struct ulog_backend *backend, uint32_t level, const char *tag, int is_raw,
const char *log, size_t len)
{
/* write some '\r' for word alignment */
char write_overage_c[4] = { '\r', '\r', '\r', '\r' };
size_t write_size_temp = 0;
EfErrCode result = EF_NO_ERR;
/* saving level filter for flash log */
if (level <= log_saving_lvl)
{
/* calculate the word alignment write size */
write_size_temp = ALIGN_DOWN(len, 4);
result = ef_log_write((uint32_t *) log, write_size_temp);
/* write last word alignment data */
if ((result == EF_NO_ERR) && (write_size_temp != len))
{
memcpy(write_overage_c, log + write_size_temp, len - write_size_temp);
ef_log_write((uint32_t *) write_overage_c, sizeof(write_overage_c));
}
}
}
/**
* Set flash log saving level. The log which level less than setting will stop saving to flash.
*
* @param level setting level
*/
void ulog_ef_log_lvl_set(uint32_t level)
{
log_saving_lvl = level;
}
int ulog_ef_backend_init(void)
{
flash_backend.output = ulog_easyflash_backend_output;
ulog_backend_register(&flash_backend, "easyflash", pdTRUE);
return 0;
}
#endif /* ULOG_EASYFLASH_BACKEND_ENABLE */

View File

@ -0,0 +1,210 @@
/*
* This file is part of the EasyFlash Library.
*
* Copyright (c) 2014-2018, Armink, <armink.ztl@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* 'Software'), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* The ulog filter configuration store implement by EasyFlash.
* Created on: 2018-11-08
*/
#include <rtthread.h>
#ifdef ULOG_EASYFLASH_CFG_SAVE_ENABLE
#include <easyflash.h>
#include <stdlib.h>
#include <string.h>
#define LOG_TAG "easyflash"
#include <ulog.h>
#define ENV_FILTER_GLOBAL_LVL_NAME "ulog.lvl"
#define ENV_FILTER_GLOBAL_TAG_NAME "ulog.tag"
#define ENV_FILTER_GLOBAL_KW_NAME "ulog.kw"
#define ENV_FILTER_TAG_LVL_NAME "ulog.tag_lvl"
extern size_t ulog_ultoa(char *s, unsigned long int n);
/**
* load the ulog configuration on flash
*
* @return result, 0 : success, else error
*
* @note don't using `&` and `##` on log tag definition when using this function.
*/
int ulog_ef_filter_cfg_load(void)
{
char *value;
/* restore the saving global level */
if ((value = ef_get_env(ENV_FILTER_GLOBAL_LVL_NAME)) != NULL)
{
ulog_global_filter_lvl_set(atoi(value));
}
/* restore the saving global tag */
if ((value = ef_get_env(ENV_FILTER_GLOBAL_TAG_NAME)) != NULL)
{
ulog_global_filter_tag_set(value);
}
/* restore the saving global kw */
if ((value = ef_get_env(ENV_FILTER_GLOBAL_KW_NAME)) != NULL)
{
ulog_global_filter_kw_set(value);
}
/* restore the saving tag level list */
if ((value = ef_get_env(ENV_FILTER_TAG_LVL_NAME)) != NULL)
{
char lvl_num[11], tag[ULOG_FILTER_TAG_MAX_LEN + 1], *lvl_pos, *next_node;
rt_size_t node_len;
/* decode every tag's level */
while (1)
{
/* find every node */
if ((next_node = strstr(value, "##")) != NULL)
{
node_len = next_node - value;
}
else
{
node_len = rt_strlen(value);
}
/* find level pos */
lvl_pos = strstr(value, "&");
if (lvl_pos != NULL && lvl_pos < value + node_len)
{
rt_strncpy(tag, value, lvl_pos - value);
rt_strncpy(lvl_num, lvl_pos + 1, value + node_len - lvl_pos - 1);
tag[lvl_pos - value] = '\0';
lvl_num[value + node_len - lvl_pos - 1] = '\0';
/* add a tag's level filter */
ulog_tag_lvl_filter_set(tag, atoi(lvl_num));
}
else
{
LOG_W("Warning: tag's level decode failed!");
break;
}
if (next_node)
{
value = next_node + 2;
}
else
{
break;
}
}
}
return 0;
}
INIT_APP_EXPORT(ulog_ef_filter_cfg_load);
/**
* save the ulog filter configuration to flash
*
* @note don't using `&` and `##` on log tag definition when using this function.
*/
void ulog_ef_filter_cfg_save(void)
{
unsigned char *cfgs = NULL;
char lvl_num[11];
/* set the global level env */
{
ulog_ultoa(lvl_num, ulog_global_filter_lvl_get());
ef_set_env(ENV_FILTER_GLOBAL_LVL_NAME, lvl_num);
}
/* set the global tag env */
if (rt_strlen(ulog_global_filter_tag_get()))
{
ef_set_env(ENV_FILTER_GLOBAL_TAG_NAME, ulog_global_filter_tag_get());
}
else if(ef_get_env(ENV_FILTER_GLOBAL_TAG_NAME))
{
ef_del_env(ENV_FILTER_GLOBAL_TAG_NAME);
}
/* set the global kw env */
if (rt_strlen(ulog_global_filter_kw_get()))
{
ef_set_env(ENV_FILTER_GLOBAL_KW_NAME, ulog_global_filter_kw_get());
}
else if(ef_get_env(ENV_FILTER_GLOBAL_KW_NAME))
{
ef_del_env(ENV_FILTER_GLOBAL_KW_NAME);
}
/* set the tag's level env */
{
rt_slist_t *node;
ulog_tag_lvl_filter_t tag_lvl = NULL;
rt_size_t node_size, tag_len, lvl_len;
int cfgs_size = 0;
for (node = rt_slist_first(ulog_tag_lvl_list_get()); node; node = rt_slist_next(node))
{
tag_lvl = rt_slist_entry(node, struct ulog_tag_lvl_filter, list);
ulog_ultoa(lvl_num, tag_lvl->level);
tag_len = rt_strlen(tag_lvl->tag);
lvl_len = rt_strlen(lvl_num);
/* env string format: tag_name1&tag_lvl1##tag_name2&tag_lvl2## */
node_size = tag_len + 1 + lvl_len + 2;
cfgs_size += node_size;
cfgs = (unsigned char *) rt_realloc(cfgs, cfgs_size);
if (cfgs == NULL)
{
LOG_W("Warning: no memory for save cfgs");
goto __exit;
}
rt_memcpy(cfgs + cfgs_size - node_size , tag_lvl->tag, tag_len);
rt_memcpy(cfgs + cfgs_size - node_size + tag_len , "&", 1);
rt_memcpy(cfgs + cfgs_size - node_size + tag_len + 1 , lvl_num, lvl_len);
rt_memcpy(cfgs + cfgs_size - node_size + tag_len + 1 + lvl_len, "##", 2);
}
if((cfgs)&&(cfgs_size>2))
{
cfgs[cfgs_size - 2] = '\0';
ef_set_env(ENV_FILTER_TAG_LVL_NAME, (char *)cfgs);
}
else if(ef_get_env(ENV_FILTER_TAG_LVL_NAME))
{
ef_del_env(ENV_FILTER_TAG_LVL_NAME);
}
}
__exit:
/* save the ulog filter env */
ef_save_env();
if (cfgs)
{
rt_free(cfgs);
}
}
#endif /* ULOG_EASYFLASH_CFG_SAVE_ENABLE */

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-01-07 ChenYong first version
*/
#ifndef _ULOG_FILE_H_
#define _ULOG_FILE_H_
#define ULOG_FILE_SW_VERSION "1.0.0"
#define ULOG_FILE_SW_VERSION_NUM 0x0100000
int ulog_file_backend_init(void);
int ulog_file_backend_deinit(void);
#endif /* _ULOG_FILE_H_ */

View File

@ -0,0 +1,154 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-01-07 ChenYong first version
*/
#include <FreeRTOS.h>
#include <ff_stdio.h>
#include "board.h"
#include "ulog.h"
#include "ulog_file.h"
#define ULOG_FILE_BE_NAME "file"
#ifndef ULOG_FILE_ROOT_PATH
#define ULOG_FILE_ROOT_PATH "/logs"
#endif
#ifndef ULOG_FILE_NAME_BASE
#define ULOG_FILE_NAME_BASE "ulog.log"
#endif
#ifndef ULOG_FILE_MAX_NUM
#define ULOG_FILE_MAX_NUM 5
#endif
#ifndef ULOG_FILE_MAX_SIZE
#define ULOG_FILE_MAX_SIZE (1024 * 512)
#endif
#define ULOG_FILE_PATH_LEN 128
#ifdef ULOG_FILE_BACKEND_ENABLE
#if defined(ULOG_ASYNC_OUTPUT_THREAD_STACK) && (ULOG_ASYNC_OUTPUT_THREAD_STACK < 2048)
#error "The value of ULOG_ASYNC_OUTPUT_THREAD_STACK must be greater than 2048."
#endif
static struct ulog_backend ulog_file;
static char g_file_path[ULOG_FILE_PATH_LEN] = {0};
static FF_FILE *g_file_fd = NULL;
/* rotate the log file xxx.log.n-1 => xxx.log.n, and xxx.log => xxx.log.0 */
static int ulog_file_rotate(void)
{
#define SUFFIX_LEN 10
/* mv xxx.log.n-1 => xxx.log.n, and xxx.log => xxx.log.0 */
static char old_path[ULOG_FILE_PATH_LEN], new_path[ULOG_FILE_PATH_LEN];
int index = 0, err = 0;
FF_FILE *file_fd = NULL;
size_t base_len = 0;
int result = pdTRUE;
memcpy(old_path, g_file_path, ULOG_FILE_PATH_LEN);
memcpy(new_path, g_file_path, ULOG_FILE_PATH_LEN);
base_len = strlen(ULOG_FILE_ROOT_PATH) + strlen(ULOG_FILE_NAME_BASE) + 1;
if (g_file_fd)
{
ff_fclose(g_file_fd);
}
for (index = ULOG_FILE_MAX_NUM - 2; index >= 0; --index)
{
snprintf(old_path + base_len, SUFFIX_LEN, index ? ".%d" : "", index - 1);
snprintf(new_path + base_len, SUFFIX_LEN, ".%d", index);
/* remove the old file */
if ((file_fd = ff_fopen(new_path, "rb")) != NULL)
{
ff_fclose(file_fd);
ff_remove(new_path);
}
/* change the new log file to old file name */
if ((file_fd = ff_fopen(old_path , "rb")) != NULL)
{
ff_fclose(file_fd);
err = ff_rename(old_path, new_path, 1);
}
if (err < 0)
{
result = pdFALSE;
goto __exit;
}
}
__exit:
/* reopen the file */
g_file_fd = ff_fopen(g_file_path, "a+");
return result;
}
static void ulog_file_backend_output(struct ulog_backend *backend, uint32_t level,
const char *tag, int is_raw, const char *log, size_t len)
{
size_t file_size = 0;
/* check log file directory */
if (ff_finddir(ULOG_FILE_ROOT_PATH) == pdFALSE)
{
ff_mkdir(ULOG_FILE_ROOT_PATH);
}
if (g_file_fd == NULL)
{
snprintf(g_file_path, ULOG_FILE_PATH_LEN, "%s/%s", ULOG_FILE_ROOT_PATH, ULOG_FILE_NAME_BASE);
g_file_fd = ff_fopen(g_file_path, "a+");
if (g_file_fd == NULL)
{
printf("ulog file(%s) open failed.", g_file_path);
return;
}
}
ff_fseek(g_file_fd, 0, FF_SEEK_END);
file_size = ff_filelength(g_file_fd);
if (file_size > ULOG_FILE_MAX_SIZE)
{
if (!ulog_file_rotate())
{
return;
}
}
ff_fwrite(log, 1, len, g_file_fd);
/* flush file cache */
ff_fclose(g_file_fd);
g_file_fd = ff_fopen(g_file_path, "a+");
}
/* initialize the ulog file backend */
int ulog_file_backend_init(void)
{
ulog_file.output = ulog_file_backend_output;
ulog_backend_register(&ulog_file, ULOG_FILE_BE_NAME, pdFALSE);
return 0;
}
/* uninitialize the ulog file backend */
int ulog_file_backend_deinit(void)
{
if (g_file_fd)
{
ff_fclose(g_file_fd);
g_file_fd = NULL;
}
ulog_backend_unregister(&ulog_file);
return 0;
}
#endif /* ULOG_FILE_BACKEND_ENABLE */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,97 @@
#ifndef _ULOG_H_
#define _ULOG_H_
#include <stdarg.h>
#include <FreeRTOS.h>
#include "list.h"
#include "board.h"
#include "ulog_def.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ULOG_VERSION_STR "0.1.1"
/*
* ulog init and deint
*/
int ulog_init(void);
void ulog_deinit(void);
/*
* output different level log by LOG_X API
*
* NOTE: The `LOG_TAG` and `LOG_LVL` must be defined before including the <ulog.h> when you want to use LOG_X API.
*
* #define LOG_TAG "example"
* #define LOG_LVL LOG_LVL_DBG
* #include <ulog.h>
*
* Then you can using LOG_X API to output log
*
* TRACE_DEBUG("this is a debug log!");
* TRACE_ERROR("this is a error log!");
*/
#define TRACE_FATAL(...) ulog_f(LOG_TAG, __VA_ARGS__)
#define TRACE_ERROR(...) ulog_e(LOG_TAG, __VA_ARGS__)
#define TRACE_WARNING(...) ulog_w(LOG_TAG, __VA_ARGS__)
#define TRACE_INFO(...) ulog_i(LOG_TAG, __VA_ARGS__)
#define TRACE_DEBUG(...) ulog_d(LOG_TAG, __VA_ARGS__)
#define LOG_RAW(...) ulog_raw(__VA_ARGS__)
#define LOG_HEX(name, width, buf, size) ulog_hex(name, width, buf, size)
/*
* backend register and unregister
*/
int ulog_backend_register(ulog_backend_t backend, const char *name, int support_color);
int ulog_backend_unregister(ulog_backend_t backend);
#ifdef ULOG_USING_FILTER
/*
* log filter setting
*/
int ulog_tag_lvl_filter_set(const char *tag, uint32_t level);
uint32_t ulog_tag_lvl_filter_get(const char *tag);
List_t *ulog_tag_lvl_list_get(void);
void ulog_global_filter_lvl_set(uint32_t level);
uint32_t ulog_global_filter_lvl_get(void);
void ulog_global_filter_tag_set(const char *tag);
const char *ulog_global_filter_tag_get(void);
void ulog_global_filter_kw_set(const char *keyword);
const char *ulog_global_filter_kw_get(void);
#endif /* ULOG_USING_FILTER */
/*
* flush all backends's log
*/
void ulog_flush(void);
#ifdef ULOG_USING_ASYNC_OUTPUT
/*
* asynchronous output API
*/
void ulog_async_output(void);
void ulog_async_waiting_log(uint32_t time);
#endif
/*
* dump the hex format data to log
*/
void ulog_hexdump(const char *tag, size_t width, uint8_t *buf, size_t size);
/*
* Another log output API. This API is more difficult to use than LOG_X API.
*/
void ulog_voutput(uint32_t level, const char *tag, int newline, const char *format, va_list args);
void ulog_output(uint32_t level, const char *tag, int newline, const char *format, ...);
void ulog_raw(const char *format, ...);
void read_flash_log(uint8_t *logbuf, size_t index, size_t size);
size_t read_recent_flash_log(void *buf, size_t size);
#ifdef __cplusplus
}
#endif
#endif /* _ULOG_H_ */

View File

@ -0,0 +1,187 @@
#ifndef _ULOG_DEF_H_
#define _ULOG_DEF_H_
#ifdef __cplusplus
extern "C" {
#endif
/* logger level, the number is compatible for syslog */
#define LOG_LVL_ASSERT 0
#define LOG_LVL_FATAL 1
#define LOG_LVL_ERROR 3
#define LOG_LVL_WARNING 4
#define LOG_LVL_INFO 6
#define LOG_LVL_DBG 7
/* the output silent level and all level for filter setting */
#ifndef ULOG_USING_SYSLOG
#define LOG_FILTER_LVL_SILENT 0
#define LOG_FILTER_LVL_ALL 7
#else
#define LOG_FILTER_LVL_SILENT 1
#define LOG_FILTER_LVL_ALL 255
#endif /* ULOG_USING_SYSLOG */
/* compatible for trace */
#undef TRACE_DEBUG
#undef TRACE_INFO
#undef TRACE_WARNING
#undef TRACE_ERROR
#undef TRACE_FATAL
#undef TRACE_LEVEL_DEBUG
#undef TRACE_LEVEL_INFO
#undef TRACE_LEVEL_WARNING
#undef TRACE_LEVEL_ERROR
#undef TRACE_LEVEL_FATAL
#define TRACE_LEVEL_FATAL LOG_LVL_FATAL
#define TRACE_LEVEL_ERROR LOG_LVL_ERROR
#define TRACE_LEVEL_WARNING LOG_LVL_WARNING
#define TRACE_LEVEL_INFO LOG_LVL_INFO
#define TRACE_LEVEL_DEBUG LOG_LVL_DBG
#define dbg_log(level, ...) \
if ((level) <= LOG_LVL) \
{ \
ulog_output(level, LOG_TAG, pdFALSE, __VA_ARGS__);\
}
#if !defined(LOG_TAG)
/* compatible for trace */
#if defined(TRACE_TAG)
#define LOG_TAG TRACE_TAG
#else
#define LOG_TAG "NO_TAG"
#endif
#endif /* !defined(LOG_TAG) */
#if !defined(TRACE_LEVEL)
#define TRACE_LEVEL TRACE_LEVEL_INFO
#endif
/* setting static output log level */
#ifndef ULOG_OUTPUT_LVL
#define ULOG_OUTPUT_LVL LOG_LVL_INFO
#endif
#if !defined(LOG_LVL)
/* compatible for trace */
#if defined(TRACE_LEVEL)
#define LOG_LVL TRACE_LEVEL
#else
#define LOG_LVL LOG_LVL_DBG
#endif
#endif /* !defined(LOG_LVL) */
#if (LOG_LVL >= LOG_LVL_DBG) && (ULOG_OUTPUT_LVL >= LOG_LVL_DBG)
#define ulog_d(TAG, ...) ulog_output(LOG_LVL_DBG, TAG, pdTRUE, __VA_ARGS__)
#else
#define ulog_d(TAG, ...)
#endif /* (LOG_LVL >= LOG_LVL_DBG) && (ULOG_OUTPUT_LVL >= LOG_LVL_DBG) */
#if (LOG_LVL >= LOG_LVL_INFO) && (ULOG_OUTPUT_LVL >= LOG_LVL_INFO)
#define ulog_i(TAG, ...) ulog_output(LOG_LVL_INFO, TAG, pdTRUE, __VA_ARGS__)
#else
#define ulog_i(TAG, ...)
#endif /* (LOG_LVL >= LOG_LVL_INFO) && (ULOG_OUTPUT_LVL >= LOG_LVL_INFO) */
#if (LOG_LVL >= LOG_LVL_WARNING) && (ULOG_OUTPUT_LVL >= LOG_LVL_WARNING)
#define ulog_w(TAG, ...) ulog_output(LOG_LVL_WARNING, TAG, pdTRUE, __VA_ARGS__)
#else
#define ulog_w(TAG, ...)
#endif /* (LOG_LVL >= LOG_LVL_WARNING) && (ULOG_OUTPUT_LVL >= LOG_LVL_WARNING) */
#if (LOG_LVL >= LOG_LVL_ERROR) && (ULOG_OUTPUT_LVL >= LOG_LVL_ERROR)
#define ulog_e(TAG, ...) ulog_output(LOG_LVL_ERROR, TAG, pdTRUE, __VA_ARGS__)
#else
#define ulog_e(TAG, ...)
#endif /* (LOG_LVL >= LOG_LVL_ERROR) && (ULOG_OUTPUT_LVL >= LOG_LVL_ERROR) */
#if (LOG_LVL >= LOG_LVL_FATAL) && (ULOG_OUTPUT_LVL >= LOG_LVL_FATAL)
#define ulog_f(TAG, ...) {ulog_output(LOG_LVL_FATAL, TAG, pdTRUE, __VA_ARGS__); while(1);}
#else
#define ulog_f(TAG, ...)
#endif /* (LOG_LVL >= LOG_LVL_FATAL) && (ULOG_OUTPUT_LVL >= LOG_LVL_FATAL) */
#if (LOG_LVL >= LOG_LVL_DBG) && (ULOG_OUTPUT_LVL >= LOG_LVL_DBG)
#define ulog_hex(TAG, width, buf, size) ulog_hexdump(TAG, width, buf, size)
#else
#define ulog_hex(TAG, width, buf, size)
#endif /* (LOG_LVL >= LOG_LVL_DBG) && (ULOG_OUTPUT_LVL >= LOG_LVL_DBG) */
/* assert for developer. */
#ifdef ULOG_ASSERT_ENABLE
#define ULOG_ASSERT(EXPR) \
if (!(EXPR)) \
{ \
ulog_output(LOG_LVL_ASSERT, LOG_TAG, pdTRUE, "(%s) has assert failed at %s:%ld.", #EXPR, __FUNCTION__, __LINE__); \
ulog_flush(); \
while (1); \
}
#else
#define ULOG_ASSERT(EXPR)
#endif
/* ASSERT API definition */
#if !defined(ASSERT)
#define ASSERT ULOG_ASSERT
#endif
/* buffer size for every line's log */
#ifndef ULOG_LINE_BUF_SIZE
#define ULOG_LINE_BUF_SIZE 128
#endif
/* output filter's tag max length */
#ifndef ULOG_FILTER_TAG_MAX_LEN
#define ULOG_FILTER_TAG_MAX_LEN 23
#endif
/* output filter's keyword max length */
#ifndef ULOG_FILTER_KW_MAX_LEN
#define ULOG_FILTER_KW_MAX_LEN 15
#endif
#ifndef ULOG_NEWLINE_SIGN
#define ULOG_NEWLINE_SIGN "\r\n"
#endif
#define ULOG_FRAME_MAGIC 0x10
/* tag's level filter */
struct ulog_tag_lvl_filter
{
char tag[ULOG_FILTER_TAG_MAX_LEN + 1];
uint32_t level;
ListItem_t list;
};
typedef struct ulog_tag_lvl_filter *ulog_tag_lvl_filter_t;
struct ulog_frame
{
/* magic word is 0x10 ('lo') */
uint32_t magic:8;
uint32_t is_raw:1;
uint32_t log_len:23;
uint32_t level;
const char *log;
const char *tag;
};
typedef struct ulog_frame *ulog_frame_t;
struct ulog_backend
{
char name[ULOG_NAME_MAX];
int support_color;
void (*init) (struct ulog_backend *backend);
void (*output)(struct ulog_backend *backend, uint32_t level, const char *tag, int is_raw, const char *log, size_t len);
void (*flush) (struct ulog_backend *backend);
void (*deinit)(struct ulog_backend *backend);
ListItem_t list;
};
typedef struct ulog_backend *ulog_backend_t;
#ifdef __cplusplus
}
#endif
#endif /* _ULOG_DEF_H_ */