1 /*
2  * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0.
5  *
6  * @Date: 2021-04-07 09:53:07
7  * @LastEditTime: 2021-04-25 17:19:03
8  * @Description:  This files is for debug functions
9  *
10  * @Modify History:
11  *  Ver   Who        Date         Changes
12  * ----- ------     --------    --------------------------------------
13  */
14 
15 #ifndef FT_DEBUG_H
16 #define FT_DEBUG_H
17 
18 #include "ft_printf.h"
19 
20 typedef enum
21 {
22     FT_LOG_NONE,   /*!< No log output */
23     FT_LOG_ERROR,  /*!< Critical errors, software module can not recover on its own */
24     FT_LOG_WARN,   /*!< Error conditions from which recovery measures have been taken */
25     FT_LOG_INFO,   /*!< Information messages which describe normal flow of events */
26     FT_LOG_DEBUG,  /*!< Extra information which is not necessary for normal use (values, pointers, sizes, etc). */
27     FT_LOG_VERBOSE /*!< Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */
28 } ft_log_level_t;
29 
30 #define LOG_COLOR_BLACK "30"
31 #define LOG_COLOR_RED "31"
32 #define LOG_COLOR_GREEN "32"
33 #define LOG_COLOR_BROWN "33"
34 #define LOG_COLOR_BLUE "34"
35 #define LOG_COLOR_PURPLE "35"
36 #define LOG_COLOR_CYAN "36"
37 #define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
38 #define LOG_BOLD(COLOR) "\033[1;" COLOR "m"
39 #define LOG_RESET_COLOR "\033[0m"
40 #define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
41 #define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
42 #define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
43 #define LOG_COLOR_D
44 #define LOG_COLOR_V
45 
46 #ifndef LOG_LOCAL_LEVEL
47 #define LOG_LOCAL_LEVEL FT_LOG_VERBOSE
48 #endif
49 
50 #define LOG_FORMAT(letter, format) LOG_COLOR_##letter " %s: " format LOG_RESET_COLOR "\r\n"
51 
52 #define PORT_KPRINTF Ft_printf
53 
54 #define LOG_EARLY_IMPL(tag, format, log_level, log_tag_letter, ...)           \
55     do                                                                        \
56     {                                                                         \
57         if (LOG_LOCAL_LEVEL < log_level)                                      \
58             break;                                                            \
59         PORT_KPRINTF(LOG_FORMAT(log_tag_letter, format), tag, ##__VA_ARGS__); \
60     } while (0)
61 
62 #define EARLY_LOGE(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_ERROR, E, ##__VA_ARGS__)
63 #define EARLY_LOGI(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_INFO, I, ##__VA_ARGS__)
64 #define EARLY_LOGD(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_DEBUG, D, ##__VA_ARGS__)
65 #define EARLY_LOGW(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_WARN, W, ##__VA_ARGS__)
66 #define EARLY_LOGV(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_VERBOSE, W, ##__VA_ARGS__)
67 
68 #define FT_DEBUG_PRINT_I(TAG, format, ...) EARLY_LOGI(TAG, format, ##__VA_ARGS__)
69 #define FT_DEBUG_PRINT_E(TAG, format, ...) EARLY_LOGE(TAG, format, ##__VA_ARGS__)
70 #define FT_DEBUG_PRINT_D(TAG, format, ...) EARLY_LOGD(TAG, format, ##__VA_ARGS__)
71 #define FT_DEBUG_PRINT_W(TAG, format, ...) EARLY_LOGW(TAG, format, ##__VA_ARGS__)
72 #define FT_DEBUG_PRINT_V(TAG, format, ...) EARLY_LOGV(TAG, format, ##__VA_ARGS__)
73 
74 #define FT_RAW_PRINTF(format, ...) PORT_KPRINTF(format, ##__VA_ARGS__)
75 
76 void Ft_DumpHexWord(const u32 *ptr, ft_base_t buflen);
77 void Ft_DumpHexByte(const u8 *ptr, ft_base_t buflen);
78 #endif // !
79