/**
******************************************************************************************************************************************************************************************
*@file                       debug.h
*@author         
*@data                       
*@version                    v1.0
*@par Copyright(c):
*
*@par History:
*     version:author,date,desc
*     v1.0   :create this file
*
*******************************************************************************************************************************************************************************************
*/
#ifndef _DEBUG_H
#define _DEBUG_H

#define DBG_TRACE_ON		0x00080000L/* Display ENTER/TRACE/LEAVE messages */
#define DBG_DATA_ON 		0x20000000L/* Enable packet print */

#ifdef CONFIG_DEBUG

	typedef void (DbgPrintFunc)(UINT32 length, UINT8 *data);

	extern INT32 dbg_flags;
	extern DbgPrintFunc *dbg_func;

	int DBG_PRINTFunc(const char *fmt, ...);
	void DbgPrintData(UINT8 *data, UINT16 num_bytes, UINT16 offset);
	void DbgEnter(int A, const char *func);
	void DbgLeave(int A, const char *func);
	void SetDbgPrint(DbgPrintFunc *p);

	#define DBG_OUT(d_, a_)		sprintf(&((char *)(d_))[strlen((char *)(d_))], a_/* DEBUG tool functions */
	#define DBG_STR(d_, a_)		strcat((char *)(d_), a_);/* other head file is better? */
	#define DBG_BACK(d_)		((char *)(d_))[strlen((char *)(d_)) - 1] = 0;/* As a backspace, this may cause crash, becareful */

	void DBG_RemoveLastComma(UINT8 *dbg_str);
	void DBG_SpaceAlign(UINT8 *s, UINT8 num);
	void DBG_RawData(UINT8 *p, UINT8 *end);
	void DBG_AutoWarpPrint(UINT8 *name, UINT8 *prompt, UINT8 *param);
	UINT8 *DBG_GetBuf(void);

	#define DBG_PRINT				DBG_PRINTFunc
	#define DBG_FUNC(F)      		static const char __FUNC__[] = F;/* WARNING DBG_PRINT(A,S)   (A) can be NULL!!! */
	#define DBG_PRINT_DATA(B, S)   	{if (dbg_flags & B) DBG_PRINT S;}
	#define DBG_ENTER(A) 			DbgEnter(A, __FUNC__);
	#define DBG_LEAVE(A) 			DbgLeave(A, __FUNC__);
	#define DBG_ERROR(S)   			{DBG_PRINT("%s: ERROR: ", __FUNC__); DBG_PRINT S;}
	#define DBG_WARNING(S) 			{DBG_PRINT("%s: WARNING: ", __FUNC__); DBG_PRINT S;}

#else/* CONFIG_DEBUG undefed */
#ifdef CONFIG_MICROSOFT
	#define DBG_PRINT
#else
	#define DBG_PRINT(fmt, ...)
#endif
	#define DBG_OUT(d_, a_)
	#define DBG_STR(d_, a_)
	#define DBG_BACK(d_)	
	#define DBG_FUNC(F)
	#define DBG_PRINT_DATA(B, S);
	#define DBG_ENTER(A)	STK_EnterFunc(A);
	#define DBG_LEAVE(A)	STK_LeaveFunc(A);
	#define DBG_ERROR(S)
	#define DBG_WARNING(S)
	#define DbgPrintData(a, b, c)
#endif/* CONFIG_DEBUG */
#endif/* _DEBUG_H */

