/*
 * EP_BulkIO.h
 *
 * Created: 12.5.2013 20:08:39
 *  Author: Chenda
 */ 


#ifndef EP_TASKS_H_
#define EP_TASKS_H_

#include "config.h"
#include "lib_mcu/usb/usb_drv.h"
#include "modules/usb/descriptors/usb_tmc_descriptors.h"
//#include "conf_usb.h"

/************************************************************************/
/* PUBLIC: Bulk IN, OUT and Interrupt IN End point interface            */
/************************************************************************/
#define BULK_INT_EVENT_NO_EVENT				0
#define BULK_INT_EVENT_BUSY					1
// Bulk OUT event definition
#define BULK_INT_EVENT_DEV_MSG_OUT			2	//DEV_DEP_MSG_OUT
#define BULK_INT_EVENT_REQ_DEV_MSG_IN		3	//REQUEST_DEV_DEP_MSG_IN
#define BULK_INT_EVENT_VENDOR_OUT			4	//VENDOR_SPECIFIC_OUT
#define BULK_INT_EVENT_REQ_VENDOR_IN		5	//REQUEST_VENDOR_SPECIFIC_IN
// Bulk IN event definition
#define BULK_INT_EVENT_DEV_MSG_IN			6	//DEV_DEP_MSG_IN
#define BULK_INT_EVENT_VENDOR_IN			7	//VENDOR_SPECIFIC_IN
// Interrupt IN event definition
#define BULK_INT_EVENT_INT_IN				8

struct st_Usb_EP_Interface
{
	struct st_Bulk_Out_Interface 
	{
		uint8_t Event;
		uint8_t msgBuff[BULK_MAX_DATA_SIZE];
		uint8_t msgLength;
		uint8_t bTag;
		uint8_t bTagInvers;
		uint8_t TransferAttributes;	
	}BulkOut;
	
	struct st_Bulk_In_Interface
	{
		uint8_t Event;
		uint8_t msgBuff[BULK_MAX_DATA_SIZE];
		uint8_t msgLength;
		uint8_t bTag;
		uint8_t bTagInvers;
		uint8_t TransferAttributes;				// EOM 
	}BulkIn;
	
	struct st_Interrupt_In_Interface
	{
		uint8_t Event;
		uint8_t Notify1;
		uint8_t Notify2;
	}IntIn;	
};

/************************************************************************/
/* Public functions declaration                                         */
/************************************************************************/
struct st_Usb_EP_Interface* USB_EP_GET_INT (void);
void USB_EP_BULK_OUT_TASK (void);
void USB_EP_BULK_IN_TASK (void);

// not used - for now
void USB_EP_INT_IN_TASK (void); 

/************************************************************************/
/* PRIVATE: Bulk OUT, IN and Interrupt IN EndPoint structures definition*/
/************************************************************************/
//  USBTMC endpoint structures
//		USBTMC BULK_OUT HEADER + BulkDataStage structure
struct st_Bulk_Out
{
	//  HEADER
	uint8_t      bMsgID;							//
	uint8_t      bTag;							//
	uint8_t      bTagInverse;					//
	uint8_t      bZeroValue1;					//
	// 4 - 11 bytes USBTMC command message specific
	uint8_t      bTransferSizeLowerWordLsb;		//
	uint8_t      bTransferSizeLowerWordMsb;      //
	uint8_t      bTransferSizeUpperWordLsb;      //
	uint8_t      bTransferSizeUpperWordMsb;      //
	uint8_t      bmTransferAttributes;           //
	uint8_t      bTermChar;						// bTermChar or bZeroValue
	uint8_t      bZeroValue2;					//
	uint8_t      bZeroValue3;					//
	//  BulkDataStage
	uint8_t      bBulkData[BULK_MAX_DATA_SIZE];
};

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

//		USBTMC INTERRUPT_IN HEADER structure using by USBTMC subclass USBTMC_488
struct st_Interrupt_In
{
	uint8_t      bNotify1;						//
	uint8_t      bNotify2;						//
};

#endif /* EP_BULKIO_INTI_HANDLING_H_ */