163 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			163 lines
		
	
	
		
			5.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| 
								 | 
							
								/****************************************************************************
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
							 | 
						||
| 
								 | 
							
								be copied by any method or incorporated into another program without
							 | 
						||
| 
								 | 
							
								the express written consent of Aerospace C.Power. This Information or any portion
							 | 
						||
| 
								 | 
							
								thereof remains the property of Aerospace C.Power. The Information contained herein
							 | 
						||
| 
								 | 
							
								is believed to be accurate and Aerospace C.Power assumes no responsibility or
							 | 
						||
| 
								 | 
							
								liability for its use in any way and conveys no license or title under
							 | 
						||
| 
								 | 
							
								any patent or copyright and makes no representation or warranty that this
							 | 
						||
| 
								 | 
							
								Information is free from patent or copyright infringement.
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								****************************************************************************/
							 | 
						||
| 
								 | 
							
								#ifndef IOT_DBGLOG_H
							 | 
						||
| 
								 | 
							
								#define IOT_DBGLOG_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* os shim includes */
							 | 
						||
| 
								 | 
							
								#include "os_types.h"
							 | 
						||
| 
								 | 
							
								#include "os_lock.h"
							 | 
						||
| 
								 | 
							
								#include "os_timer.h"
							 | 
						||
| 
								 | 
							
								#include "iot_pkt_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_frame_parse_api.h"
							 | 
						||
| 
								 | 
							
								/* export includes */
							 | 
						||
| 
								 | 
							
								#include "iot_dbglog_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_utils_api.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* internal includes */
							 | 
						||
| 
								 | 
							
								#include "iot_dbglog_parser.h"
							 | 
						||
| 
								 | 
							
								#include "iot_cli_type_definition.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBGLOG_MAX_BUFFER_CNT 4
							 | 
						||
| 
								 | 
							
								#define DBGLOG_MAX_RAW_BUFFER_SIZE 950
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if (HW_PLATFORM == HW_PLATFORM_SIMU)
							 | 
						||
| 
								 | 
							
								#define DBGLOG_MAX_BUFFER_SIZE (DBGLOG_MAX_RAW_BUFFER_SIZE - \
							 | 
						||
| 
								 | 
							
								sizeof(cli_msg_hdr_t)- MAX_CLI_FRAME_HEAD - MAX_CLI_FRAME_END)
							 | 
						||
| 
								 | 
							
								#else
							 | 
						||
| 
								 | 
							
								#define DBGLOG_MAX_BUFFER_SIZE (DBGLOG_MAX_RAW_BUFFER_SIZE - \
							 | 
						||
| 
								 | 
							
								sizeof(cli_msg_hdr_t)- MAX_CLI_FRAME_HEAD - MAX_CLI_FRAME_END)
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								#define DBGLOG_DEFAULT_UPLOAD_TIME_PERIOD (2 * 1000)
							 | 
						||
| 
								 | 
							
								#define DBGLOG_MAX_ARGUMENT_NUM           (9)
							 | 
						||
| 
								 | 
							
								#define MODULEID_DEBUGLOG                 (0)
							 | 
						||
| 
								 | 
							
								#define MSGID_DEBUG_LOG_REPORT            (0)
							 | 
						||
| 
								 | 
							
								#define MAX_MODULE_GROUP_NUM              (4)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef void(*DBGLOG_DEBUG_LOG_EVENT_CB)
							 | 
						||
| 
								 | 
							
								(void* buffer, uint8_t crash_log, uint32_t buffer_len);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _dbglog_buf_context
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    /*log content*/
							 | 
						||
| 
								 | 
							
								    iot_pkt_t*           buffer;
							 | 
						||
| 
								 | 
							
								    /*the max buffer size*/
							 | 
						||
| 
								 | 
							
								    uint32_t             buf_size;
							 | 
						||
| 
								 | 
							
								    /*the next write offset of the buffer*/
							 | 
						||
| 
								 | 
							
								    uint32_t             write_offset;
							 | 
						||
| 
								 | 
							
								}dbglog_buf_context_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _dbglog_mod_info
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    uint16_t module_id;  /* module id */
							 | 
						||
| 
								 | 
							
								    uint8_t level;      /* log level */
							 | 
						||
| 
								 | 
							
								}dbglog_mod_info_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _dbglog_info {
							 | 
						||
| 
								 | 
							
								    dbglog_buf_context_t debuglog;
							 | 
						||
| 
								 | 
							
								    os_mutex_h debuglog_lock;
							 | 
						||
| 
								 | 
							
								    dbglog_mod_info_t module_info[MAX_MODULE_GROUP_NUM];
							 | 
						||
| 
								 | 
							
								    /*callback fun to upplayer*/
							 | 
						||
| 
								 | 
							
								    DBGLOG_DEBUG_LOG_EVENT_CB dbglog_send_debug_logs_cb;
							 | 
						||
| 
								 | 
							
								    uint32_t timestamp_start;
							 | 
						||
| 
								 | 
							
								    timer_id_t upload_timer;
							 | 
						||
| 
								 | 
							
								    /*time interval of uploading log buffer*/
							 | 
						||
| 
								 | 
							
								    int32_t upload_interval;
							 | 
						||
| 
								 | 
							
								    bool_t is_initialized;
							 | 
						||
| 
								 | 
							
								    uint32_t seq;        /* sequence number */
							 | 
						||
| 
								 | 
							
								    uint8_t level;       /* global level water marker*/
							 | 
						||
| 
								 | 
							
								    uint8_t live_capture;/* if work as live capture mode*/
							 | 
						||
| 
								 | 
							
								    uint8_t live_log_receiver[IOT_MAC_ADDR_LEN];
							 | 
						||
| 
								 | 
							
								} dbglog_info_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								uint32_t iot_dbglog_init();
							 | 
						||
| 
								 | 
							
								uint32_t iot_dbglog_deinit();
							 | 
						||
| 
								 | 
							
								uint32_t register_dbglog_callback(DBGLOG_DEBUG_LOG_EVENT_CB callback);
							 | 
						||
| 
								 | 
							
								void iot_dbglog_config_module_level(uint16_t module_id, uint8_t level);
							 | 
						||
| 
								 | 
							
								void iot_dbglog_config_level(uint8_t level);
							 | 
						||
| 
								 | 
							
								uint8_t iot_dbglog_get_level();
							 | 
						||
| 
								 | 
							
								uint8_t iot_dbglog_get_module_level(uint16_t module_id);
							 | 
						||
| 
								 | 
							
								void iot_dbglog_start_stop_live_capture(uint8_t enable, uint8_t* receiver);
							 | 
						||
| 
								 | 
							
								uint8_t iot_dbglog_live_capture_enabled();
							 | 
						||
| 
								 | 
							
								uint8_t *iot_dbglog_live_log_receiver();
							 | 
						||
| 
								 | 
							
								dbglog_info_t *get_dbglog_instance();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBGLOG_SET_DBUF_INFO(dbuf, _buffer, _buf_size, _writeoffset) \
							 | 
						||
| 
								 | 
							
								do { \
							 | 
						||
| 
								 | 
							
								    (dbuf).buffer  = _buffer; \
							 | 
						||
| 
								 | 
							
								    (dbuf).buf_size = _buf_size;\
							 | 
						||
| 
								 | 
							
								    (dbuf).write_offset = _writeoffset; \
							 | 
						||
| 
								 | 
							
								} while (0)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBGLOG_GET_LOG_LVL(cfg_s,mod_id)       \
							 | 
						||
| 
								 | 
							
								          (cfg_s)->module_info[(mod_id)].level
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DEBUGLOG_BUFFER_IS_EMPTY(dbuf) \
							 | 
						||
| 
								 | 
							
								    ((dbuf)->buffer == NULL)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBGLOG_BUFFER_SPACE_AVAILABLE(dbuf, args) \
							 | 
						||
| 
								 | 
							
								    ((dbuf)->write_offset < ((dbuf)->buf_size - (args << 2)))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBGLOG_UPDATE_SEQ(dbglog) \
							 | 
						||
| 
								 | 
							
								(++dbglog->seq)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBG_MODULE_ID_OFFSET 0
							 | 
						||
| 
								 | 
							
								#define DBG_MODULE_ID_MASK 0x0000FFFF
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBG_MSG_ID_OFFSET 16
							 | 
						||
| 
								 | 
							
								#define DBG_MSG_ID_MASK 0xFFFF0000
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBG_LOG_RESVD_OFFSET 0
							 | 
						||
| 
								 | 
							
								#define DBG_LOG_RESVD_MASK 0x0000FFFF
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBG_PAYLOAD_LEN_OFFSET 16
							 | 
						||
| 
								 | 
							
								#define DBG_PAYLOAD_LEN_MASK 0xFFFF0000
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBGLOG_SET_MSG_ID(module_id, msg_id) \
							 | 
						||
| 
								 | 
							
								(((module_id << DBG_MODULE_ID_OFFSET) & DBG_MODULE_ID_MASK) | \
							 | 
						||
| 
								 | 
							
								((msg_id << DBG_MSG_ID_OFFSET) & DBG_MSG_ID_MASK))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBGLOG_SET_MSG_HDR(payload_len, resvd) \
							 | 
						||
| 
								 | 
							
								(((payload_len << DBG_PAYLOAD_LEN_OFFSET) & DBG_PAYLOAD_LEN_MASK) | \
							 | 
						||
| 
								 | 
							
								((resvd << DBG_LOG_RESVD_OFFSET) & DBG_LOG_RESVD_MASK))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define RAW_DATA_MSG_ID 0
							 | 
						||
| 
								 | 
							
								#define SUPPORT_RAW_DATA_LOG 1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if SUPPORT_RAW_DATA_LOG
							 | 
						||
| 
								 | 
							
								#define MAX_RAW_DATA_MSG_LEN 36
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBGLOG_PAYLOAD_OFFSET (sizeof(uint32_t) * 5)
							 | 
						||
| 
								 | 
							
								#define DBGLOG_MODULE_GROUP_NAME_LEN 20
							 | 
						||
| 
								 | 
							
								typedef struct _module_group_config {
							 | 
						||
| 
								 | 
							
								    uint8_t group_id;
							 | 
						||
| 
								 | 
							
								    uint16_t group_start_module_id;
							 | 
						||
| 
								 | 
							
								    uint16_t group_end_module_id;
							 | 
						||
| 
								 | 
							
								    uint8_t group_name[DBGLOG_MODULE_GROUP_NAME_LEN];
							 | 
						||
| 
								 | 
							
								}module_group_config;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define DBGLOG_HEAD_SIZE  (MAX_FRAME_CODE_LEN + CLI_MSG_HEADER_LEN \
							 | 
						||
| 
								 | 
							
								            + DBGLOG_PAYLOAD_OFFSET)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif // !IOT_DBGLOG_H
							 |