// -------------------------------------------------------------------- // Copyright (c) 2007 by Terasic Technologies Inc. // -------------------------------------------------------------------- // // Permission: // // Terasic grants permission to use and modify this code for use // in synthesis for all Terasic Development Boards and Altera Development // Kits made by Terasic. Other use of this code, including the selling // ,duplication, or modification of any portion is strictly prohibited. // // Disclaimer: // // This VHDL/Verilog or C/C++ source code is intended as a design reference // which illustrates how these types of functions can be implemented. // It is the user's responsibility to verify their design for // consistency and functionality through the use of formal // verification methods. Terasic provides no warranty regarding the use // or functionality of this code. // // -------------------------------------------------------------------- // // Terasic Technologies Inc // 356 Fu-Shin E. Rd Sec. 1. JhuBei City, // HsinChu County, Taiwan // 302 // // web: http://www.terasic.com/ // email: support@terasic.com // // -------------------------------------------------------------------- // Author: Richard Chang #ifndef ISP1761_DEVICE_CONTROL_H_ #define ISP1761_DEVICE_CONTROL_H_ #include "device_control.h" #define DC_HIGH_SPEED 1 #define DC_FULL_SPEED 0 /* * Values of various operations and notifications */ #define DC_PIPE_STALL 0x0001 /* Pipe stall (status, request)*/ #define DC_PIPE_UNSTALL 0x0002 /* Pipe unstall (status, request)*/ #define DC_GET_PIPE_STATUS 0x0004 /* Get pipe status (request) */ #define DC_SETUP_COMMAND 0x0008 /* setup command notification */ #define DC_ENABLE 0x0040 /* USB device enable */ #define DC_DISABLE 0x0080 /* USB device disable */ #define DC_RESET 0x0100 /* USB bus reset */ #define DC_RESUME 0x0200 /* USB bus resume */ #define DC_SUSPEND 0x0400 /* USB bus suspend */ #define DC_SET_HNP 0x0800 /* USB HNP feature setting */ #define DC_CONNECT 0x1000 /* Connect to USB bus */ #define DC_DISCONNECT 0x2000 /* disconnect from USB bus */ #define DC_BUSTATUS 0x4000 /* USB initial Bus status (SUSPEND) */ #define DC_USB_TO_EPREG(ep,dir) (((ep==0) && (dir==0)) ? 0 : (ep+1)) #define DC_PIPE_TO_EPREG(pipe) (pipe) typedef enum{ DC_OPR_READ= 0x00, DC_OPR_WRITE= 0x01 }PIPE_OP; typedef enum{ DC_PIPE_CONTROL=DC_EP_CONTROL, DC_PIPE_ISOCHRONOUS=DC_EP_ISOCHRONOUS, DC_PIPE_BULK=DC_EP_BULK, DC_PIPE_INTERRUPT=DC_EP_INTERRUPT }DC_PIPE_TYPE; // Endpint Type typedef enum{ DC_PIPE_UNCONFIG=0, DC_PIPE_CONFIG, DC_PIPE_OPEN }DC_PIPE_STATE; typedef enum{ DC_URB_COMPLETE = 1, DC_URB_PENDING, DC_EP_STALLED, DC_SHORT_PACKET, DC_SETUP_OVERRITE }URB_STATUS; typedef struct{ alt_u8 Number; /* pipe number 0~15 */ DC_PIPE_STATE State; /* State of the endpoint */ bool bTxRxIdle; /* tx, rx idle flag */ alt_u8 BufStatus; // struct DC_URB *pUrb; /* USB request block list */ DC_EP_DESC *pEpDesc; /* End Point descriptor */ DC_PIPE_DESC *pPipeDesc; /* Pipe descriptor */ }DC_PIPE; struct DC_URB{ struct DC_URB *pNext; DC_PIPE_HANDLE Pipe; DC_PIPE_TYPE PipeType; /* transfer type control, bulk, int, iso */ PIPE_OP Operation; /* read, write */ URB_STATUS Status; void *pTransferBuffer; /* associated data buffer */ alt_u32 TransferBufferLength; /* data buffer length */ alt_u32 ActualLength; /* actual data buffer length */ void (*Complete)(struct DC_URB *pUrb); void *pReqPriv; /* requester private data */ }; //typedef struct{ //}ISP1761_DEVICE; /* USB device: one in, one out, and various stats */ typedef struct{ /* Transmit buffer for this endpoint */ //ISP1761_DEVICE *pDevice; /* Configuration driver information */ DC_CONFIG_DEVICE *pDcFunc; /* pdc pipe data structure */ DC_PIPE *pEpPipes; /* device speed */ alt_u8 HS_Dev_flag; }DC_DEVICE; typedef struct pdc_pipe_opr { DC_PIPE_HANDLE Handle; /* Pipe handle correpsonding to the */ alt_u32 Context; /* pipe requester */ alt_u16 Operation; /* Pipe operation */ alt_u16 PipeStatus; /* Pipe status stall, unstall */ }DC_PIPE_OPERATION; /*-----------------------------------------------------------------* * pipe data structure * *-----------------------------------------------------------------*/ #define DC_MAX_EPS 0x10 typedef enum{ DC_STATUS_URB_COMPLETE = 0x01, DC_STATUS_URB_PENDING, DC_STATUS_EP_STALLED, DC_STATUS_SHORT_PACKET, DC_STATUS_SETUP_OVERRITE }USB_STATUS; bool DC_Init(DC_CONFIG_DEVICE *pDcConfig); bool DC_ConfigDevice(DC_CONFIG_DEVICE *pDcConfig); DC_PIPE_HANDLE DC_OpenPipe(DC_PIPE_DESC *pPipeDesc); void DC_ClosePipe(DC_PIPE_HANDLE PipeHandle); bool DC_SetDeviceAddress(alt_u32 Context,alt_u16 Address); bool DC_SubmitUrb(struct DC_URB *pUrbReq); bool DC_CancelUrb(struct DC_URB *pUrbReq); void DC_Run(void); bool DC_PipeOperation(DC_PIPE_OPERATION *pPipeOpr); #endif /*ISP1761_DEVICE_CONTROL_H_*/