
#ifndef _USB_COMMUN_TMC_H_
#define _USB_COMMUN_TMC_H_

#define  APPLICATION_CLASS                  0xFE  // Application class
#define  TMC_SUBCLASS						0x03  // Test and Measurement Class
#define  PROTOCOL_USBTMC_ONLY				0x00  // USBTMC Interface
#define  PROTOCOL_USBTMC_USB488				0x01  // USBTMC  + USB488 Interface

#define  BULK_MAX_DATA_SIZE					BULK_MAX_TRANSFER_LENGTH - BULK_HEADER_LENGTH	  //  size of BULK_IN, BULK_OUT buffers
#define  BULK_HEADER_LENGTH					12
#define  BULK_MAX_TRANSFER_LENGTH			128


//  USBTMC bRequest values
#define  INITIATE_ABORT_BULK_OUT			1
#define  CHECK_ABORT_BULK_OUT_STATUS		2
#define  INITIATE_ABORT_BULK_IN				3
#define  CHECK_ABORT_BULK_IN_STATUS			4
#define  INITIATE_CLEAR						5
#define  CHECK_CLEAR_STATUS					6
#define  GET_CAPABILITIES					7
#define  INDICATOR_PULSE					64


//  USBTMC_status values
#define  STATUS_SUCCESS						0x01
#define  STATUS_PENDING						0x02
#define  STATUS_FAILED						0x80
#define  STATUS_TRANSFER_NOT_IN_PROGRESS	0x81
#define  STATUS_SPLIT_NOT_IN_PROGRESS		0x82
#define  STATUS_SPLIT_IN_PROGRESS			0x83



#define  BYTE_NULL_VAL						0x00
#define  WORD_NULL_VAL						0X0000
#define  EOL_R								13		// \r
#define  EOL_N								10		// \n
#define  EOM								(1<<0)

// USBTMC Interface capabilities 
#define  ACCEPT_INDICATOR_PULSE				0x04
#define  NOT_ACCEPT_INDICATOR_PULSE			0x00
#define  TALK_ONLY							0x02
#define  NOT_TALK_ONLY						0x00
#define  LISTEN_ONLY						0x01
#define  NOT_LISTEN_ONLY					0x00
#define  SUPPORT_SPEC_BULK_IN_ENDING		0X01
#define  NOT_SUPPORT_SPEC_BULK_IN_ENDING	0X00
#define  USBTMC_INTERFACE_CAPABILITIES		(NOT_ACCEPT_INDICATOR_PULSE|NOT_TALK_ONLY|NOT_LISTEN_ONLY)
#define  USBTMC_DEVICE_CAPABILITIES			(NOT_SUPPORT_SPEC_BULK_IN_ENDING)	


//  MsgID values
#define  DEV_DEP_MSG_OUT					1
#define  REQUEST_DEV_DEP_MSG_IN				2
#define  DEV_DEP_MSG_IN						2
#define  VENDOR_SPECIFIC_OUT				126
#define  REQUEST_VENDOR_SPECIFIC_IN			127
#define  VENDOR_SPECIFIC_IN					127


// zakomentovat az budou struktury nadefinovany v EP_BulkIO.h

//  USBTMC endpoint structures
//		USBTMC BULK_OUT HEADER + BulkDataStage structure
typedef struct
{
	//  HEADER
	U8      bMsgID;							//
	U8      bTag;							//
	U8      bTagInverse;					//
	U8      bZeroValue1;					//
	// 4 - 11 bytes USBTMC command message specific
	U8      bTransferSizeLowerWordLsb;		//
	U8      bTransferSizeLowerWordMsb;      //
	U8      bTransferSizeUpperWordLsb;      //
	U8      bTransferSizeUpperWordMsb;      //
	U8      bmTransferAttributes;           //
	U8      bTermChar;						// bTermChar or bZeroValue 
	U8      bZeroValue2;					//
	U8      bZeroValue3;					//
	//  BulkDataStage
	U8      bBulkData[BULK_MAX_DATA_SIZE];
}  S_UsbTmcBulkOutMessage;

//		USBTMC BULK_IN HEADER + BulkDataStage structure
typedef struct
{
	//  HEADER
	U8      bMsgID;							//
	U8      bTag;							//
	U8      bTagInverse;					//
	U8      bZeroValue1;					//
	// 4 - 11 bytes USBTMC command message specific
	U8      bTransferSizeLowerWordLsb;		//
	U8      bTransferSizeLowerWordMsb;      //  Probably never be used
	U8      bTransferSizeUpperWordLsb;      //	Probably never be used
	U8      bTransferSizeUpperWordMsb;      //	Probably never be used
	U8      bmTransferAttributes;           //  bmTransferAttributes or bZeroValue
	U8      bZeroValue2;					// 
	U8      bZeroValue3;					//
	U8      bZeroValue4;					//
	//  BulkDataStage
	U8      bBulkData[BULK_MAX_DATA_SIZE];
}  S_UsbTmcBulkInMessage;

//		USBTMC INTERRUPT_IN HEADER structure using by USBTMC subclass USBTMC_488
typedef struct
{
	U8      bNotify1;						//
	U8      bNotify2;						//
}  S_UsbTmcInterruptInHeader;

typedef struct
{
	U8     *pBulkData;						//
	U8      bBulkData[BULK_MAX_DATA_SIZE];	//

}  S_UsbTmcBulkDataStageContainer;

//  
typedef struct
{
	Bool	blUnprocessedInboundMessage;		//  unprocessed inbound message 		
	Bool	blReadyToOutboundMessage;			//  Ready to transmit outbound message
	Bool	blNewOutboundMessage;				//
}  S_UsbTmcStatusOfMessage;




#endif   // _USB_COMMUN_TMC_H_

