101 lines
3.3 KiB
C
101 lines
3.3 KiB
C
|
/*******************************************************************************
|
||
|
*
|
||
|
*
|
||
|
* File: tau_log.h
|
||
|
* Description log file
|
||
|
* Version V0.1
|
||
|
* Date 2020-12-08
|
||
|
* Author linyw
|
||
|
*******************************************************************************/
|
||
|
#ifndef _TAU_LOG_H_
|
||
|
#define _TAU_LOG_H_
|
||
|
|
||
|
|
||
|
/*******************************************************************************
|
||
|
* 1.Included files
|
||
|
*******************************************************************************/
|
||
|
#include <stdint.h>
|
||
|
#include <string.h>
|
||
|
#include <stdarg.h>
|
||
|
#include "ArmCM0.h"
|
||
|
/*******************************************************************************
|
||
|
* 2.Global constant and macro definitions using #define
|
||
|
*******************************************************************************/
|
||
|
|
||
|
#ifdef LOG_TAG
|
||
|
#undef LOG_TAG
|
||
|
#endif
|
||
|
#define LOG_TAG "tau_log"
|
||
|
#define LOG_CURREN_LEVEL kLOG_LEVEL_DBG /* 配置打印等级 TODO:每个模块可配置打印等级 */
|
||
|
#define LOG_BUF_SIZE (256) /* 配置打印缓存的大小 */
|
||
|
|
||
|
/*
|
||
|
* Using the following three macros for conveniently logging.
|
||
|
*/
|
||
|
#define TAU_LOGD(format,...) \
|
||
|
do { \
|
||
|
tau_log_printf(kLOG_LEVEL_DBG, "[%s] (%04d) " format, LOG_TAG, __LINE__, ##__VA_ARGS__); \
|
||
|
} while (0)
|
||
|
|
||
|
#define TAU_LOGI(format,...) \
|
||
|
do { \
|
||
|
tau_log_printf(kLOG_LEVEL_INF, "[%s] (%04d) " format, LOG_TAG, __LINE__, ##__VA_ARGS__); \
|
||
|
} while (0)
|
||
|
|
||
|
#define TAU_LOGE(format,...) \
|
||
|
do { \
|
||
|
tau_log_printf(kLOG_LEVEL_ERR, "[%s] (%04d) " format, LOG_TAG, __LINE__, ##__VA_ARGS__); \
|
||
|
} while (0)
|
||
|
|
||
|
/*******************************************************************************
|
||
|
* 3.Global structures, unions and enumerations using typedef
|
||
|
*******************************************************************************/
|
||
|
/**
|
||
|
* @brief log打印等级枚举
|
||
|
*
|
||
|
*/
|
||
|
typedef enum
|
||
|
{
|
||
|
kLOG_LEVEL_DBG = 0,
|
||
|
kLOG_LEVEL_INF,
|
||
|
kLOG_LEVEL_ERR,
|
||
|
kLOG_LEVEL_NONE /* 不打印任何参数 */
|
||
|
} log_level_e;
|
||
|
|
||
|
/**
|
||
|
* @brief log打印端口枚举
|
||
|
*
|
||
|
*/
|
||
|
typedef enum
|
||
|
{
|
||
|
LOG_PORT_UART0, /* 使用串口输出打印 */
|
||
|
LOG_PORT_UART1, /* 使用串口输出打印 */
|
||
|
LOG_PORT_SWD, /* 使用swd输出打印 */
|
||
|
LOG_PORT_UNKNOWN
|
||
|
} log_port_e;
|
||
|
|
||
|
/*******************************************************************************
|
||
|
* 4.Global variable extern declarations
|
||
|
*******************************************************************************/
|
||
|
|
||
|
/*******************************************************************************
|
||
|
* 5.Global function prototypes
|
||
|
*******************************************************************************/
|
||
|
/**
|
||
|
* @brief 初始化log系统
|
||
|
* @param baud_rate 波特率
|
||
|
* @param log_port 打印端口选择
|
||
|
* @retval none
|
||
|
*/
|
||
|
void tau_log_init(uint32_t baud_rate, log_port_e log_port);
|
||
|
|
||
|
/**
|
||
|
* @brief 初始化log系统
|
||
|
* @param baud_rate 波特率
|
||
|
* @param log_port 打印端口选择
|
||
|
* @retval none
|
||
|
*/
|
||
|
void tau_log_printf(log_level_e log_lv, const char *fmt, ...);
|
||
|
|
||
|
#endif
|