
#ifndef     _MY_HEAD_FILE_H_
#define     _MY_HEAD_FILE_H_

#include    "string.h"
#include    "gen_linklist.h"
#include    "gen_queue.h"
//#include    "base_config.h"


//获取cnt个连续的bit1
#define 	CNT_2_BIT(cnt) ( (1<<(cnt))-1)

#define     ABS(a,b)    (a)>=(b)?((a)-(b)):((b)-(a))

#define     HBYTEL_COMB_INT(byte)   (((byte)[0]<<24)+ ((byte)[1]<<16)+ ((byte)[2]<<8)+ ((byte)[3]<<0) )  
//#define     LBYTEH_COMB_INT         (((byte)[3]<<24)+ ((byte)[2]<<16)+ ((byte)[1]<<8)+ ((byte)[0]<<0) ) 
#define     HBYTEL_COMB_SHORT(byte)   (((byte)[0]<<8)+ ((byte)[1]<<0) )  

typedef union{
    unsigned int u32b;
    unsigned char u8b[4];
}u32_8_union;

typedef union{
    unsigned short u16b;
    unsigned char u8b[2];   
}u16_8_union;

//crc 
unsigned short crc16(const unsigned char *ptr,unsigned short len);

//变量和常量比对 0-相等
unsigned char memcmp_constant(const unsigned char *var,unsigned char cst,unsigned char len);


#define 	name2str(name)		(#name)		//变量名转换成字符串
//__FUNCTION__  函数名转换成字符串

//将字符转换成16进制数
unsigned char char_conver_hex(char s);


//typedef struct kp_ele_STR{
//	unsigned char status;
//	unsigned char id_sn[4];	
//	unsigned char index;
//	
//	#if (MON_KP_VOTE)	
//	unsigned short rxkp_cnt; 				//收到键盘数据包的个数,
//	unsigned short ackkp_cnt;				//基站应答键盘的次数， 语音状态不应答!	
//	unsigned short cfmed_cnt;
//	unsigned short rpt_cnt;
//	#endif
//}kp_ele_str;

//#define 	LIST_MGNT_CNT			100

//void mon__rx_kp(const unsigned char *rxkp);
//void mon__ack_kp(const unsigned char *sn);

//extern unsigned char check_down_permit(void);
//extern void set_tx_beacon7(void);




//---------------------- debug -----------------------------------------

typedef enum {
    DBGIO_NUMB0=0,
    DBGIO_NUMB1,
    DBGIO_NUMB2,
    DBGIO_NUMB3,    
}dbgIO_nmb_enum;

typedef enum {
    DBGIO_STAT_OFF=0,
    DBGIO_STAT_ON,
    DBGIO_STAT_TRIG,   
}dbgIO_stat_enum;



typedef struct {
	unsigned char b0:1;
	unsigned char b1:1;	
	unsigned char b2:1;	
	unsigned char b3:1;
	unsigned char b4:1;
	unsigned char b5:1;	
	unsigned char b6:1;	
	unsigned char b7:1;	
	
	unsigned char b8:1;
	unsigned char b9:1;	
	unsigned char b10:1;	
	unsigned char b11:1;
	unsigned char b12:1;
	unsigned char b13:1;	
	unsigned char b14:1;	
	unsigned char b15:1;

	unsigned char b16:1;
	unsigned char b17:1;	
	unsigned char b18:1;	
	unsigned char b19:1;
	unsigned char b20:1;
	unsigned char b21:1;	
	unsigned char b22:1;	
	unsigned char b23:1;	
	
	unsigned char b24:1;
	unsigned char b25:1;	
	unsigned char b26:1;	
	unsigned char b27:1;
	unsigned char b28:1;
	unsigned char b29:1;	
	unsigned char b30:1;	
	//unsigned char b31:1;		
}BIT32;
extern unsigned int PRINT_DBG_CTRL;




#define 	PRINT_DBG_WARN				(((BIT32*)&PRINT_DBG_CTRL) -> b0) 
#define 	PRINT_DBG_ERROR				(((BIT32*)&PRINT_DBG_CTRL) -> b1) 
#define 	PRINT_DBG_SYSTEM			(((BIT32*)&PRINT_DBG_CTRL) -> b2) 
#define 	PRINT_DBG_PLAT_INIT		(((BIT32*)&PRINT_DBG_CTRL) -> b3) 				
#define 	PRINT_DBG_MULTI				(((BIT32*)&PRINT_DBG_CTRL) -> b4) 
#define 	PRINT_DBG_HDTEST			(((BIT32*)&PRINT_DBG_CTRL) -> b5) 


//keypad
#define 	PRINT_DBG_KP					(((BIT32*)&PRINT_DBG_CTRL) -> b8) 
#define 	PRINT_DBG_KP_ONLINE		(((BIT32*)&PRINT_DBG_CTRL) -> b9)
#define   PRINT_DBG_58GRX   		(((BIT32*)&PRINT_DBG_CTRL) -> b10)
#define   PRINT_DBG_58GTX   		(((BIT32*)&PRINT_DBG_CTRL) -> b11)
#define   PRINT_DBG_24GRX   		(((BIT32*)&PRINT_DBG_CTRL) -> b10)
#define   PRINT_DBG_24GTX   		(((BIT32*)&PRINT_DBG_CTRL) -> b11)
#define   PRINT_DBG_ONLINE   		(((BIT32*)&PRINT_DBG_CTRL) -> b12)

//pc/sdk
#define 	PRINT_DBG_PC					(((BIT32*)&PRINT_DBG_CTRL) -> b16)
#define   PRINT_DBG_VOTE_RPT    (((BIT32*)&PRINT_DBG_CTRL) -> b17)
//#define   PRINT_MON_VOTE    		(((BIT32*)&PRINT_DBG_CTRL) -> b18)		//monitor vote info



//func
#define     PRINT_DBG_NFC   		(((BIT32*)&PRINT_DBG_CTRL) -> b24)
#define     PRINT_DBG_JOINNET   (((BIT32*)&PRINT_DBG_CTRL) -> b25)
#define     PRINT_DBG_BLKLIST   (((BIT32*)&PRINT_DBG_CTRL) -> b26)	//blacklist
#define     PRINT_DBG_LGPKT     (((BIT32*)&PRINT_DBG_CTRL) -> b26)	//longpkt

//-----------------------------------------------------------
extern void rx_rtt_process(void);

struct debug_STR{
    void(*init)(void);
    void (*ctrl_io)(dbgIO_nmb_enum , dbgIO_stat_enum );
    int (*printf)(unsigned char modual, const char * sFormat, ...);
    void (*print_buf)(unsigned char md,const char * sFormat,const unsigned char *buf,unsigned char len);
		void(*process_input)(void);
	
		void (*printf_warn)(const char * sFormat, ...);
		void (*printf_error)(const char * sFormat, ...);	
};
extern struct debug_STR  my_debug;




#endif
