// -------------------------------------------------------------------- // 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_TRANSPORT_H_ #define ISP1761_TRANSPORT_H_ #include "isp1761_hal_nios2.h" #include "isp1761_register.h" #define NO_TRANSFER_ACTIVE 0xFFFFFFFF #define PTD_HEADER_SIZE 32 // 8*4 = 32 byte typedef alt_u32 PTD_HEADER[8]; #define msleep(x) usleep(x*1000) // return value of tranport function typedef enum{ PTD_RESULT_SUCCESS=0, PTD_RESULT_NACK, PTD_RESULT_STALL, PTD_RESULT_ERROR, // internal error PTD_RESULT_NLEN, // not transfer complete PTD_RESULT_NCOMP, // not complete PTD_RESULT_UNKOWN }PTD_RESULT; enum{ TOKEN_OUT = 0, TOKEN_IN, TOKEN_SETUP, TOKEN_PING }; #define MAX_EP_NUM 16 typedef enum{ USB_SPEED_HIGH=0, USB_SPEED_FULL, USB_SPEED_LOW, USB_SPEED_UNKNOWN }USB_SPEED; typedef enum{ EPType_CONTROL = 0, EPType_ISOCHRONOUS = 1, EPType_BULK = 2, EPType_INTERRUPT = 3 }ISP1761_EPType; typedef struct{ ISP1761_EPType Type; alt_u16 MaxPacketSize; }EP_CONTEXT; typedef struct{ // parent port alt_u8 HubAddr; alt_u8 Port; // this device alt_u8 Speed; // refer to enum USB_SPEED_XXX alt_u16 Addr; EP_CONTEXT EpIn[MAX_EP_NUM]; EP_CONTEXT EpOut[MAX_EP_NUM]; //alt_u16 MaxPacketSize0; //Alt_16 }USB_DEVICE; // HC_BUFFER_STATUS_REG #define NO_BUF_FILL 0x00 #define ALT_BUF_FILL 0x01 #define INT_BUF_FILL 0x02 #define ISO_BUF_FILL 0x03 // PDT status #define PTD_A_ACTIVE 0x80000000 #define PTD_H_STALL 0x40000000 #define PTD_B_BABBLE 0x20000000 #define PTD_X_ERROR 0x10000000 //=================== Transport Interface Function ========================== // CONTROL (IN & OUT) PTD_RESULT PORT_ControlOut(USB_DEVICE *pUsbDevice, alt_u8 *szData, alt_u16 DataLen, alt_u8 Token, alt_u8 DataToggle); PTD_RESULT PORT_ControlIn(USB_DEVICE *pUsbDevice, alt_u8 *szBuf, alt_u16 BufLen, alt_u8 Token, alt_u8 DataToggle, alt_u16 *pInLen); // BULK (IN & OUT) PTD_RESULT PORT_BulkOut(USB_DEVICE *pUsbDevice, alt_u8 *szData, alt_u16 DataLen, alt_u8 Token, alt_u8 EndPt, alt_u8 DataToggle); PTD_RESULT PORT_BulkIn(USB_DEVICE *pUsbDevice, alt_u8 *szBuf, alt_u16 BufLen, alt_u8 Token, alt_u8 EndPt, alt_u8 DataToggle, alt_u16 *pInLen); // INT (IN) PTD_RESULT PORT_IntIn(USB_DEVICE *pUsbDevice, alt_u8 *szBuf, alt_u16 BufLen, alt_u8 EndPt, alt_u8 DataToggle, alt_u16 *pInLen); #endif /*ISP1761_TRANSPORT_H_*/