00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00033 #include "type.h"
00034 #include "usbstruct.h"
00035
00036
00037
00038
00039
00040 #define MAX_PACKET_SIZE0 64
00042
00043
00044
00045
00046
00047 #define EP_STATUS_DATA (1<<0)
00048 #define EP_STATUS_STALLED (1<<1)
00049 #define EP_STATUS_SETUP (1<<2)
00050 #define EP_STATUS_ERROR (1<<3)
00051 #define EP_STATUS_NACKED (1<<4)
00053 // device status sent through callback
00054 #define DEV_STATUS_CONNECT (1<<0)
00055 #define DEV_STATUS_SUSPEND (1<<2)
00056 #define DEV_STATUS_RESET (1<<4)
00058 // interrupt bits for NACK events in USBHwNakIntEnable
00059
00060 #define INACK_CI (1<<1)
00061 #define INACK_CO (1<<2)
00062 #define INACK_II (1<<3)
00063 #define INACK_IO (1<<4)
00064 #define INACK_BI (1<<5)
00065 #define INACK_BO (1<<6)
00067 void USBHwISR (void);
00068 void USBHwNakIntEnable (U8 bIntBits);
00069 void USBHwConnect (BOOL fConnect);
00070
00071
00072 int USBHwEPRead (U8 bEP, U8 *pbBuf, int iMaxLen);
00073 int USBHwEPWrite (U8 bEP, U8 *pbBuf, int iLen);
00074 void USBHwEPStall (U8 bEP, BOOL fStall);
00075 int USBHwISOCEPRead (const U8 bEP, U8 *pbBuf, const int iMaxLen);
00076
00078 typedef void (TFnEPIntHandler) (U8 bEP, U8 bEPStatus);
00079 void USBHwRegisterEPIntHandler (U8 bEP, TFnEPIntHandler *pfnHandler);
00080
00082 typedef void (TFnDevIntHandler) (U8 bDevStatus);
00083 void USBHwRegisterDevIntHandler (TFnDevIntHandler *pfnHandler);
00084
00086 typedef void (TFnFrameHandler)(U16 wFrame);
00087 void USBHwRegisterFrameHandler(TFnFrameHandler *pfnHandler);
00088
00089
00090
00091
00092
00093
00094
00095 BOOL USBInit(void);
00096
00098 typedef BOOL (TFnHandleRequest)(TSetupPacket *pSetup, int *piLen, U8 **ppbData);
00099 void USBRegisterRequestHandler(int iType, TFnHandleRequest *pfnHandler, U8 *pbDataStore);
00100 void USBRegisterCustomReqHandler(TFnHandleRequest *pfnHandler);
00101
00103 typedef BOOL (TFnGetDescriptor)(U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData);
00104
00106 BOOL USBHandleStandardRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData);
00107
00109 void USBHandleControlTransfer(U8 bEP, U8 bEPStat);
00110
00112 void USBRegisterDescriptors(const U8 *pabDescriptors);
00113 BOOL USBGetDescriptor(U16 wTypeIndex, U16 wLangID, int *piLen, U8 **ppbData);
00114
00115
00116
00117
00119 void USBSetupDMADescriptor(
00120 volatile U32 dmaDescriptor[],
00121 volatile U32 nextDdPtr[],
00122 const U8 isIsocFlag,
00123 const U16 maxPacketSize,
00124 const U16 dmaLengthIsocNumFrames,
00125 void *dmaBufferStartAddress,
00126 U32 *isocPacketSizeMemoryAddress );
00127
00128 void USBInitializeISOCFrameArray(U32 isocFrameArr[], const U32 numElements, const U16 startFrameNumber, const U16 defaultFrameLength);
00129 void USBInitializeUSBDMA(volatile U32* udcaHeadArray[32]);
00130 void USBSetHeadDDForDMA(const U8 bEp, volatile U32* udcaHeadArray[32], volatile const U32 *dmaDescriptorPtr);
00131
00132 void USBEnableDMAForEndpoint(const U8 bEndpointNumber) ;
00133 void USBDisableDMAForEndpoint(const U8 bEndpointNumber);
00134
00135
00136
00137
00138