1 #ifndef SUNXI_HAL_LOG_H 2 #define SUNXI_HAL_LOG_H 3 4 #ifdef __cplusplus 5 extern "C" 6 { 7 #endif 8 9 #include <stdio.h> 10 11 //#define CONFIG_KERNEL_FREERTOS 12 //#define CONFIG_RTTKERNEL 13 #ifdef CONFIG_KERNEL_FREERTOS 14 15 #include <awlog.h> 16 17 #define hal_log_err(fmt, ...) pr_err(fmt"\n", ##__VA_ARGS__) 18 #define hal_log_warn(fmt, ...) pr_warn(fmt"\n", ##__VA_ARGS__) 19 #define hal_log_info(fmt, ...) pr_info(fmt"\n", ##__VA_ARGS__) 20 #define hal_log_debug(fmt, ...) pr_debug(fmt"\n", ##__VA_ARGS__) 21 22 #elif defined CONFIG_RTTKERNEL 23 24 #include <log.h> 25 26 #define hal_log_err(fmt, ...) pr_err(fmt"\n", ##__VA_ARGS__) 27 #define hal_log_warn(fmt, ...) pr_warn(fmt"\n", ##__VA_ARGS__) 28 #define hal_log_info(fmt, ...) pr_info(fmt"\n", ##__VA_ARGS__) 29 #define hal_log_debug(fmt, ...) pr_debug(fmt"\n", ##__VA_ARGS__) 30 31 #else 32 int printk(const char *fmt, ...); 33 34 #define HAL_XPOSTO(x) "\033[" #x "D\033[" #x "C" 35 36 #define HAL_LOG_LAYOUT "%s%s%s: [%s:%04u]: %s%s" 37 #define HAL_LOG_BACKEND_CALL(log_lv, log_color, log_format, color_off, ...) \ 38 printk(HAL_LOG_LAYOUT log_format "%s""\n\r", \ 39 log_color, log_lv, color_off, __func__, __LINE__, HAL_XPOSTO(30),\ 40 log_color, ##__VA_ARGS__, color_off) 41 42 #define HAL_LOG_COLOR(log_lv, log_color, log_format, ...) \ 43 HAL_LOG_BACKEND_CALL(log_lv, log_color, log_format, \ 44 HAL_LOG_COLOR_OFF, ##__VA_ARGS__) 45 46 47 #define HAL_LOG_COLOR_OFF "\033[0m" 48 #define HAL_LOG_COLOR_RED "\033[1;40;31m" 49 #define HAL_LOG_COLOR_YELLOW "\033[1;40;33m" 50 #define HAL_LOG_COLOR_BLUE "\033[1;40;34m" 51 #define HAL_LOG_COLOR_PURPLE "\033[1;40;35m" 52 53 #define HAL_LOG_ERROR_PREFIX "[ERR]" 54 #define HAL_LOG_WARNING_PREFIX "[WRN]" 55 #define HAL_LOG_INFO_PREFIX "[INF]" 56 #define HAL_LOG_DEBUG_PREFIX "[DBG]" 57 58 #define hal_log_err(...) \ 59 do { HAL_LOG_COLOR(HAL_LOG_ERROR_PREFIX, HAL_LOG_COLOR_OFF, ##__VA_ARGS__); } while(0) 60 #define hal_log_warn(...) \ 61 do { HAL_LOG_COLOR(HAL_LOG_WARNING_PREFIX, HAL_LOG_COLOR_OFF, ##__VA_ARGS__); } while(0) 62 #define hal_log_info(...) \ 63 do { HAL_LOG_COLOR(HAL_LOG_INFO_PREFIX, HAL_LOG_COLOR_OFF, ##__VA_ARGS__); } while(0) 64 #define hal_log_debug(...) \ 65 do { HAL_LOG_COLOR(HAL_LOG_DEBUG_PREFIX, HAL_LOG_COLOR_OFF, ##__VA_ARGS__); } while(0) 66 #endif 67 68 #ifdef __cplusplus 69 } 70 #endif 71 72 #endif 73