/****************************************************************************** * Shanghai ChipON Micro-Electronic Co.,Ltd ****************************************************************************** * @File Name : kflog.h * @Syntax : GNU99 * @Author : ChipON AE/FAE Group * @Date : 2022-09-06 * @Version : V1.0 * @Description : This document describes the C language document template. ****************************************************************************** * Copyright (C) by Shanghai ChipON Micro-Electronic Co.,Ltd * All rights reserved. * * This software is copyrght protected and proprietary to * Shanghai ChipON Micro-Electronic Co.,Ltd. ****************************************************************************** * REVISON HISTORY ****************************************************************************** * |Date |Version |Author |Description ****************************************************************************** * |2022-09-06 |V1.0 |wangning |New creat *****************************************************************************/ #ifndef _KF_PRINTF_H #define _KF_PRINTF_H /*PRQA S 3412 EOF #Macro defines an unrecognized code-fragment. */ /*PRQA S 1038 EOF #The sequence ", ##__VA_ARGS__" is a language extension. */ /*PRQA S 3410 EOF #Macro parameter not enclosed in (). */ #ifdef __cplusplus extern "C" { #endif /****************************************************************************** ** MISRA-C Rules Violations ******************************************************************************/ /** * @page misra_violations MISRA-C:2004 violations * * @section */ /****************************************************************************** ** QAC Warnings ******************************************************************************/ /** * @page QAC Warnings * */ /****************************************************************************** ** Include Files ******************************************************************************/ /* Add or remove header files on your request, REMOVE THIS COMMENT LINE */ #include /****************************************************************************** ** File Version Check ******************************************************************************/ /****************************************************************************** ** Macro Definitions ******************************************************************************/ #define KF_INTERNAL_PRINT #ifdef KF_INTERNAL_PRINT /** * @brief:log level */ #ifndef KF_LOG_LEVEL #define KF_LOG_LEVEL 0u #endif #define KF_LOG_DEBUG (1u << 0u) #define KF_LOG_INFO (1u << 1u) #define KF_LOG_WARN (1u << 2u) #define KF_LOG_ERROR (1u << 3u) /** * @brief:The properties printed when the log module is registered */ #define KF_LOG_OPT_FUNC ((uint32_t)1u << 0u) #define KF_LOG_OPT_LINE ((uint32_t)1u << 1u) #define KF_LOG_OPT_FILE ((uint32_t)1u << 2u) #define KF_LOG_OPT_TICK ((uint32_t)1u << 3u) /** * @brief:Registering the Log module */ #define KF_REF_LOG(TAG) extern Log_PrintfType log_##TAG##_module; #define KF_REG_LOG(TAG, OPT) \ Log_PrintfType log_##TAG##_module = {.name = #TAG, .opt = OPT}; /** * @brief:Log output, including debugging, information, alarm, and error, is * generated by calling different interfaces */ #if (KF_LOG_DEBUG > KF_LOG_LEVEL) #define KFLOG_D(TAG, MSG, ...) \ kfLog_Printf((Log_PrintfType *)&log_##TAG##_module, __func__, __LINE__, \ __FILE__, MSG, ##__VA_ARGS__) #else #define KFLOG_D(TAG, MSG, ...) #endif #if (KF_LOG_INFO > KF_LOG_LEVEL) #define KFLOG_I(TAG, MSG, ...) \ kfLog_Printf((Log_PrintfType *)&log_##TAG##_module, __func__, __LINE__, \ __FILE__, MSG, ##__VA_ARGS__) #else #define KFLOG_I(TAG, MSG, ...) #endif #if (KF_LOG_WARN > KF_LOG_LEVEL) #define KFLOG_W(TAG, MSG, ...) \ kfLog_Printf((Log_PrintfType *)&log_##TAG##_module, __func__, __LINE__, \ __FILE__, MSG, ##__VA_ARGS__) #else #define KFLOG_W(TAG, MSG, ...) #endif #if (KF_LOG_ERROR > KF_LOG_LEVEL) #define KFLOG_E(TAG, MSG, ...) \ kfLog_Printf((Log_PrintfType *)&log_##TAG##_module, __func__, __LINE__, \ __FILE__, MSG, ##__VA_ARGS__) #else #define KFLOG_E(TAG, MSG, ...) #endif /** * @brief:Pure output (pure), without the registration module header */ #define kf_printf(MSG, ...) \ kfLog_Printf(NULL, __func__, __LINE__, __FILE__, MSG, ##__VA_ARGS__) /****************************************************************************** ** Typedef Definitions ******************************************************************************/ /** * @brief:log输出模块信息 * name:模块名称 * opt:打印信息属性 */ typedef struct { char *name; uint32_t opt; } Log_PrintfType; /****************************************************************************** ** Export Variables ******************************************************************************/ /****************************************************************************** ** Export Functions ******************************************************************************/ /** * @brief:send data * @param in:pSendData-send data point * SendLen-send data length * @param out:None * @retval:None */ extern void kfLog_UartSend(const uint8_t *const pSendData, const uint16_t SendLen); /** * @brief:Log information output * @param in:plog_module-Information about the registered module * LogLevel-Print level * pfun-function name * line-line num * pfile-The file path * format,...-varargs * @param out:None * @retval:None */ extern void kfLog_Printf(const Log_PrintfType *const plog_module, const char *const pfun, const int line, const char *const pfile, const char *format, ...); /** * @brief:Log output initialization * 1.The default value is UART0. If you need to change the value, change the * KFLOG_UART * 2.The default baud rate is 230400 * 3.8bits Data , 1 start bit, 1 stop bit, no flow control, parity none * @param in:None * @param out:None * @retval:None */ extern void kfLog_Init(void); #else #define KF_REF_LOG(TAG) #define KF_REG_LOG(TAG, OPT) #define KFLOG_D(TAG, MSG, ...) #define KFLOG_I(TAG, MSG, ...) #define KFLOG_W(TAG, MSG, ...) #define KFLOG_E(TAG, MSG, ...) #define kf_printf(MSG, ...) #define kfLog_Init() #define kfLog_UartSend(pSendData, SendLen) #endif #ifdef __cplusplus } #endif #endif /* EOF */