/******************************************************************************
* file include/common.h
* author YuLiang
* version 1.0.0
* date 10-Sep-2021
* brief This file provides all the headers of the debug functions.
******************************************************************************
* Attention
*
*
© COPYRIGHT(c) 2021 LandPower
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of LandPower nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#ifndef _DBG_H_
#define _DBG_H_
/* Includes ------------------------------------------------------------------*/
#include "debug.h"
/* Define --------------------------------------------------------------------*/
#define DBG_HELP_STR_MAX 32
#define DBG_INVALID_MODULE 0xffffffff
/* Exported types ------------------------------------------------------------*/
/* debug模块. */
typedef enum
{
DBG_M_DBG = 0,
DBG_M_CLI,
DBG_M_MTIMER,
DBG_M_PROCESS,
DBG_M_GPIO,
DBG_M_FIFO,
DBG_M_FIFO_ERR,
DBG_M_CA,
DBG_M_CA_ERR,
DBG_M_CA_CSG,
DBG_M_CA_CSG_ERR,
DBG_M_CA_CAU,
DBG_M_CA_CAU_ERR,
DBG_M_CA_NETWORK,
DBG_M_CA_NETWORK_ERR,
DBG_M_CA_MQTT,
DBG_M_CA_MQTT_ERR,
DBG_M_DEBUG,
DBG_M_COUNT
} DBG_MODULE_E;
/* debug命令字. */
typedef enum
{
DBG_CMD_ON = 0,
DBG_CMD_OFF,
DBG_CMD_ALL_OFF
} DBG_CMD_E;
/* debug结构体,每个结构体代表一个模块. */
typedef struct
{
int32_t num;
int32_t stat;
char desc[DBG_HELP_STR_MAX];
} dbg_module_t;
/* Exported macro ------------------------------------------------------------*/
#ifdef CFG_DBG_ON
#define DBG(_MODULE_, _format_, _msg_...) \
do { \
if (dbg_stat_get(_MODULE_)) printh("%s(%d): " _format_, __FUNCTION__, __LINE__, ##_msg_); \
} while(0)
#define DBG_Q(_MODULE_, _format_, _msg_...) \
do { \
if (_dbg_module[_MODULE_].stat) printh(_format_, ##_msg_); \
} while(0)
#define DBG_ARRAY(_MODULE_, _data_, _len_) \
do { \
if (dbg_stat_get(_MODULE_)) print_raw_data(_data_, _len_); \
} while(0)
#else
#define DBG(_MODULE_, _msg_...)
#define DBG(_MODULE_, _format_, _msg_...)
#define DBG_ARRAY(_MODULE_, _data_, _len_)
#endif
/* Extern global variables ---------------------------------------------------*/
#ifdef CFG_DBG_ON
extern dbg_module_t _dbg_module[DBG_M_COUNT];
#endif
/* Extern functions ----------------------------------------------------------*/
extern int32_t dbg_stat_get(DBG_MODULE_E module);
extern int dbg_cmd_hander(DBG_CMD_E cmd, int32_t module);
extern void dbg_init(void);
#endif
/************************ (C) COPYRIGHT LandPower ***** END OF FILE ****************/