/**************************** (C) COPYRIGHT 2018 Fortiortech shenzhen *****************************
* File Name          : Communication.h
* Author             : Cooper.fang, Fortiortech Appliction Team
* Version            : V1.0
* Date               : 10-25-2018
* Description        : This file contains all the common data types used for
*                      communication.
***************************************************************************************************
* All Rights Reserved
**************************************************************************************************/


#ifndef __COMMUNICATION_H_
#define __COMMUNICATION_H_
 
#if (Debugg==1)

#define CH_MAX			(2)				
#define LEN_TRACE		(0)				// 	n=0:128, 1:256, 2:512, 3:1024 ��TRACE DATA=128*2^n(n=0~3)
#define DEF_TRACEADDR		(0xFEDFA000)	


#define SZ_SENDRINGBUF		(128)			
#define SZ_RECVBUF		(24)			
#define SZ_SENDBUF		(32)			
#define SZ_TRACEBUF		(CH_MAX*128*(1<<LEN_TRACE))		



#define TRIG_NON		(0)
#define TRIG_EDGE_UP		(1)
#define TRIG_EDGE_DOWN		(2)
#define TRIG_LIMIT_INNER	(3)
#define TRIG_LIMIT_OUTER	(4)



#define RCVCMD6			(6)
#define RCVCMD9			(9)
#define RCVCMD11		(11)
#define RCVCMD14		(14)
#define RCVCMD16		(16)



union UNION_STATUS 
{
	unsigned int ui;
	unsigned char b[4];
	struct {
		unsigned halt_trace:	1;
		unsigned cmd_gettrace:	1;
		unsigned ch_trace:		2;
		unsigned len_trace:		2;
		unsigned trig_support: 	1;
		unsigned dummy1:	 	1;

		unsigned type_trig:		3;
		unsigned triggered:		1;
		unsigned ch_trig:		2;
		unsigned trig_en:		1;
		unsigned trig_normal: 	1;

		unsigned interval:		16;
		
		
	} bf;
};

union UNION_DWORD 
{
	unsigned int  dw;
	unsigned char b[4];
};

union UNION_INT 
{
	int32  i;
	int8 b[4];
};

union UNION_WORD {
	unsigned short w;
	unsigned char  b[2];
};

union UNION_SHORT 
{
	short s;
	unsigned char  b[2];
};


#define BIGENDIAN 0



#define	REG_RX		UT_DR
#define	REG_TX		UT_DR
#define	REG_STR		( (SCI1.SSR.BYTE >>4) &0x03)//错误状态
#define	REG_TSF		(!SCI1.SSR.BIT.TDRE)//发送查空（查询）
#define	REG_RESET()	{char i= SCI1.SSR.BYTE ; i=REG_RX; while ( 0 != (SCI1.SSR.BYTE&0x38) ) { SCI1.SSR.BYTE &= 0xc7 ; } }

extern union UNION_STATUS xdata ubf_status;

extern void  UartSend(void);

extern void  UartRecive(void);


extern void  UartDealResponse(void);
//extern void  cumfault_6(void);

extern void  PC_MONITOR_PWM(void);
extern void  PC_MONITOR_MAIN(void);
extern void  PC_MONITOR_1MS(void);
extern void  senddeal(void);
extern void  CMDMONI_WT_SENDCMD(void);
extern void  CMDMONI_WT_INIT(void);
extern void  PC_MONITOR_INTR(void);

//extern uint16 crc16_x25(uint8 * cata, uint8 length);

extern uint16 CRC16Compute(uint8 * CRCData, uint8 length);

#endif

#endif