You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
5.2 KiB
128 lines
5.2 KiB
3 years ago
|
/*
|
||
3 years ago
|
* Copyright : (C) 2022 Phytium Information Technology, Inc.
|
||
|
* All Rights Reserved.
|
||
|
*
|
||
|
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
|
||
|
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
|
||
|
* either version 1.0 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
|
||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||
|
* See the Phytium Public License for more details.
|
||
|
*
|
||
|
*
|
||
2 years ago
|
* FilePath: fdebug.h
|
||
3 years ago
|
* Date: 2021-04-07 09:53:07
|
||
|
* LastEditTime: 2022-02-17 18:04:58
|
||
|
* Description: This files is for debug functions
|
||
|
*
|
||
|
* Modify History:
|
||
3 years ago
|
* Ver Who Date Changes
|
||
|
* ----- ------ -------- --------------------------------------
|
||
|
*/
|
||
|
|
||
|
#ifndef BSP_COMMON_FT_DEBUG_H
|
||
|
#define BSP_COMMON_FT_DEBUG_H
|
||
|
#include <stdio.h>
|
||
3 years ago
|
#include "sdkconfig.h"
|
||
2 years ago
|
#include "ftypes.h"
|
||
3 years ago
|
|
||
|
typedef enum
|
||
|
{
|
||
3 years ago
|
FT_LOG_NONE, /* No log output */
|
||
|
FT_LOG_ERROR, /* Critical errors, software module can not recover on its own */
|
||
|
FT_LOG_WARN, /* Error conditions from which recovery measures have been taken */
|
||
|
FT_LOG_INFO, /* Information messages which describe normal flow of events */
|
||
|
FT_LOG_DEBUG, /* Extra information which is not necessary for normal use (values, pointers, sizes, etc). */
|
||
|
FT_LOG_VERBOSE /* Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */
|
||
3 years ago
|
} ft_log_level_t;
|
||
|
|
||
|
#define LOG_COLOR_BLACK "30"
|
||
|
#define LOG_COLOR_RED "31"
|
||
|
#define LOG_COLOR_GREEN "32"
|
||
|
#define LOG_COLOR_BROWN "33"
|
||
|
#define LOG_COLOR_BLUE "34"
|
||
|
#define LOG_COLOR_PURPLE "35"
|
||
|
#define LOG_COLOR_CYAN "36"
|
||
|
#define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
|
||
|
#define LOG_BOLD(COLOR) "\033[1;" COLOR "m"
|
||
|
#define LOG_RESET_COLOR "\033[0m"
|
||
|
#define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
|
||
|
#define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
|
||
|
#define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
|
||
2 years ago
|
#define LOG_COLOR_D LOG_COLOR(LOG_COLOR_CYAN)
|
||
|
#define LOG_COLOR_V LOG_COLOR(LOG_COLOR_PURPLE)
|
||
3 years ago
|
|
||
3 years ago
|
/* select debug log level */
|
||
3 years ago
|
#ifdef CONFIG_LOG_VERBOS
|
||
|
#define LOG_LOCAL_LEVEL FT_LOG_VERBOSE
|
||
3 years ago
|
#endif
|
||
3 years ago
|
|
||
|
#ifdef CONFIG_LOG_ERROR
|
||
3 years ago
|
#define LOG_LOCAL_LEVEL FT_LOG_ERROR
|
||
|
#endif
|
||
|
|
||
|
#ifdef CONFIG_LOG_WARN
|
||
|
#define LOG_LOCAL_LEVEL FT_LOG_WARN
|
||
|
#endif
|
||
|
|
||
|
#ifdef CONFIG_LOG_INFO
|
||
|
#define LOG_LOCAL_LEVEL FT_LOG_INFO
|
||
|
#endif
|
||
|
|
||
|
#ifdef CONFIG_LOG_DEBUG
|
||
|
#define LOG_LOCAL_LEVEL FT_LOG_DEBUG
|
||
3 years ago
|
#endif
|
||
|
|
||
|
#define LOG_FORMAT(letter, format) LOG_COLOR_##letter " %s: " format LOG_RESET_COLOR "\r\n"
|
||
|
|
||
|
#define PORT_KPRINTF printf
|
||
|
|
||
3 years ago
|
#ifndef CONFIG_LOG_EXTRA_INFO
|
||
3 years ago
|
#define LOG_EARLY_IMPL(tag, format, log_level, log_tag_letter, ...) \
|
||
|
do \
|
||
|
{ \
|
||
|
if (LOG_LOCAL_LEVEL < log_level) \
|
||
|
break; \
|
||
|
PORT_KPRINTF(LOG_FORMAT(log_tag_letter, format), tag, ##__VA_ARGS__); \
|
||
|
} while (0)
|
||
3 years ago
|
#else
|
||
2 years ago
|
#include <string.h>
|
||
|
#define __FILENAME__ (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1):__FILE__)
|
||
3 years ago
|
/* print debug information with source file name and source code line num. */
|
||
|
#define LOG_EARLY_IMPL(tag, format, log_level, log_tag_letter, ...) \
|
||
|
do \
|
||
|
{ \
|
||
|
if (LOG_LOCAL_LEVEL < log_level) \
|
||
|
break; \
|
||
|
PORT_KPRINTF(LOG_FORMAT(log_tag_letter, format" @%s:%d"), tag, ##__VA_ARGS__, __FILENAME__, __LINE__); \
|
||
|
} while (0)
|
||
|
#endif
|
||
3 years ago
|
|
||
|
#define EARLY_LOGE(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_ERROR, E, ##__VA_ARGS__)
|
||
|
#define EARLY_LOGI(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_INFO, I, ##__VA_ARGS__)
|
||
|
#define EARLY_LOGD(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_DEBUG, D, ##__VA_ARGS__)
|
||
|
#define EARLY_LOGW(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_WARN, W, ##__VA_ARGS__)
|
||
|
#define EARLY_LOGV(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_VERBOSE, W, ##__VA_ARGS__)
|
||
|
|
||
3 years ago
|
/* do not compile log if define CONFIG_LOG_NONE */
|
||
|
#ifndef CONFIG_LOG_NONE
|
||
3 years ago
|
#define FT_DEBUG_PRINT_I(TAG, format, ...) EARLY_LOGI(TAG, format, ##__VA_ARGS__)
|
||
|
#define FT_DEBUG_PRINT_E(TAG, format, ...) EARLY_LOGE(TAG, format, ##__VA_ARGS__)
|
||
|
#define FT_DEBUG_PRINT_D(TAG, format, ...) EARLY_LOGD(TAG, format, ##__VA_ARGS__)
|
||
|
#define FT_DEBUG_PRINT_W(TAG, format, ...) EARLY_LOGW(TAG, format, ##__VA_ARGS__)
|
||
|
#define FT_DEBUG_PRINT_V(TAG, format, ...) EARLY_LOGV(TAG, format, ##__VA_ARGS__)
|
||
3 years ago
|
#else
|
||
|
#define FT_DEBUG_PRINT_I(TAG, format, ...)
|
||
|
#define FT_DEBUG_PRINT_E(TAG, format, ...)
|
||
|
#define FT_DEBUG_PRINT_D(TAG, format, ...)
|
||
|
#define FT_DEBUG_PRINT_W(TAG, format, ...)
|
||
|
#define FT_DEBUG_PRINT_V(TAG, format, ...)
|
||
|
#endif
|
||
3 years ago
|
|
||
|
#define FT_RAW_PRINTF(format, ...) PORT_KPRINTF(format, ##__VA_ARGS__)
|
||
|
|
||
|
void FtDumpHexWord(const u32 *ptr, u32 buflen);
|
||
|
void FtDumpHexByte(const u8 *ptr, u32 buflen);
|
||
|
#endif // !
|