📄 msfunction.c
字号:
#include "DrvOTGMain.h"
//#include "uart.h"
__u32 volatile usbStillImageSts;
__u8 volatile usbTestMode;
__u8 volatile usbSetFaddr;
__u8 volatile usbClearedEP;
__u16 volatile usbGetStatusResponse;
__u8 volatile usbMyDeviceHNPSupport;
__u8 usbFunction_Load_Fifo(__s8 ep);
//__u8 pbCmdBlock[0x100];
//#define pbCmd_Addr (__u16)&pbCmdBlock[0]
extern struct devrequest usbEP0Setup;
#ifdef Enable_OTG_TestPacket_Test
__u8 volatile test_packet[53] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
0xAA, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE, 0xEE,
0xEE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xBF, 0xDF,
0xEF, 0xF7, 0xFB, 0xFD, 0xFC, 0x7E, 0xBF, 0xDF,
0xEF, 0xF7, 0xFB, 0xFD, 0x7E
};
#endif
#if 1
static code Msdfn_PictureBridge_Dscr[]=
{
/* Device Descriptor */
0x12, /* bLength */
0x01, /* DEVICE */
0x10,0x01, /* USB 1.1 */
0x00, /* CLASS */
0x00, /* Subclass */
0x00, /* Protocol */
0x40, /* bMaxPktSize0 */
0x20,0x1B, /* idVendor */
0x00,0x04, /* idProduct */
0x00,0x01, /* bcdDevice */
0x0, /* iManufacturer */
0x0, /* iProduct */
0x0, /* iSerial Number */
0x01, /* One configuration */
/* Configuration Descriptor */
0x09, /* bLength */
0x02, /* CONFIGURATION */
0x27, /* length */
0x0, /* length */
0x01, /* bNumInterfaces */
0x01, /* bConfigurationValue */
0x00, /* iConfiguration */
0xC0, /* bmAttributes */
0x01, /* power */
/* Interface Descriptor */
0x09, /* bLength */
0x04, /* INTERFACE */
0x0, /* bInterfaceNumber */
0x0, /* bAlternateSetting */
0x03, /* bNumEndpoints */
0x06, /* bInterfaceClass */
0x01, /* bInterfaceSubClass */
0x01, /* bInterfaceProtocol */
0x00, /* iInterface */
/* Endpoint Descriptor : Bulk-In */
0x07, /* bLength */
0x05, /* ENDPOINT */
0x81, /* bEndpointAddress */
0x02, /* bmAttributes */
0x40, 0x00, /* wMaxPacketSize */
0x00, /* bInterval */
/* Endpoint Descriptor : Bulk-Out */
0x07, /* bLength */
0x05, /* ENDPOINT */
0x02, /* bEndpointAddress */
0x02, /* bmAttributes */
0x40, 0x00, /* wMaxPacketSize */
0x00, /* bInterval */
/* Endpoint Descriptor : Interrupt-In */
0x07, /* bLength */
0x05, /* ENDPOINT */
0x83, /* bEndpointAddress */
0x03, /* bmAttributes */
0x40, 0x00, /* wMaxPacketSize */
0x0A, /* bInterval */
};
static code Msdfn_MassStorage_Dscr[]=
{
/* Device Descriptor */
0x12, /* bLength */
0x01, /* DEVICE */
0x10,0x01, /* USB 1.1 */
0x00, /* CLASS */
0x00, /* Subclass */
0x00, /* Protocol */
0x40, /* bMaxPktSize0 */
0x20,0x1B, /* idVendor */
0x00,0x04, /* idProduct */
0x00,0x01, /* bcdDevice */
0x00, /* iManufacturer */
0x01, /* iProduct */
0x02, /* iSerial Number */
0x01, /* One configuration */
/* Configuration Descriptor */
0x09, /* bLength */
0x02, /* CONFIGURATION */
0x20, /* length */
0x0, /* length */
0x01, /* bNumInterfaces */
0x01, /* bConfigurationValue */
0x00, /* iConfiguration */
0xC0, /* bmAttributes */
0x0, /* power */
/* Interface Descriptor */
0x09, /* bLength */
0x04, /* INTERFACE */
0x0, /* bInterfaceNumber */
0x0, /* bAlternateSetting */
0x02, /* bNumEndpoints */
0x08, /* bInterfaceClass */
0x06, /* bInterfaceSubClass */
0x50, /* bInterfaceProtocol */
0x00, /* iInterface */
/* Endpoint Descriptor : Bulk-In */
0x07, /* bLength */
0x05, /* ENDPOINT */
0x81, /* bEndpointAddress */
0x02, /* bmAttributes */
0x40, 0x00, /* wMaxPacketSize */
0x00, /* bInterval */
/* Endpoint Descriptor : Bulk-Out */
0x07, /* bLength */
0x05, /* ENDPOINT */
0x02, /* bEndpointAddress */
0x02, /* bmAttributes */
0x40, 0x00, /* wMaxPacketSize */
0x00,
/* string descritor*/
/*langID*/
0x04, 0x03, 0x09, 0x04,
/*DevID*/
0x28, 0x03, 'M', 0x00, 'a', 0x00, 's', 0x00, 's', 0x00, 0x20, 0x00, 'S', 0x00, 't', 0x00,
'o', 0x00, 'r', 0x00, 'a', 0x00, 'g', 0x00, 'e', 0x00, 0x20, 0x00, 'D', 0x00, 'e', 0x00,
'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00,
/*iserID*/
0x12, 0x03, 'C', 0x00, 'e', 0x00, 'r', 0x00,
'a', 0x00, 'm', 0x00, 'e', 0x00, 'l', 0x00,
'1', 0x00
};
#else
__u8 volatile usbMsdfn_Dscr[]=
{
/* Device Descriptor */
0x12, /* bLength */
0x01, /* DEVICE */
0x00,0x02, /* USB 2.0 */
0x00, /* CLASS */
0x00, /* Subclass */
0x00, /* Protocol */
0x40, /* bMaxPktSize0 */
0xd6,0x04, /* idVendor */
0x88,0x33, /* idProduct */
0x00,0x01, /* bcdDevice */
0x0, /* iManufacturer */
0x0, /* iProduct */
0x0, /* iSerial Number */
0x01, /* One configuration */
/* Device Qualifier */
0x0a, /* bLength */
0x06, /* DEVICE Qualifier */
0x00,0x02, /* USB 2.0 */
0x00, /* CLASS */
0x00, /* Subclass */
0x00, /* Protocol */
0x40, /* bMaxPktSize0 */
0x01, /* One configuration */
0x00, /* Reserved */
/* Other Speed Configuration Descriptor */
0x09, /* bLength */
0x07, /* Other Speed Configuration */
0x27, /* length */
0x0, /* length */
0x01, /* bNumInterfaces */
0x01, /* bConfigurationValue */
0x00, /* iConfiguration */
// 0xE0, /* bmAttributes */
0xC0, /* bmAttributes */
0x2, /* power */
/* Interface Descriptor */
0x09, /* bLength */
0x04, /* INTERFACE */
0x0, /* bInterfaceNumber */
0x0, /* bAlternateSetting */
0x02, /* bNumEndpoints */
0x06, /* bInterfaceClass */
0x01, /* bInterfaceSubClass */
0x01, /* bInterfaceProtocol */
0x00, /* iInterface */
/* Endpoint Descriptor : Bulk-In */
0x07, /* bLength */
0x05, /* ENDPOINT */
0x81, /* bEndpointAddress */
0x02, /* bmAttributes */
0x00, 0x02, /* wMaxPacketSize */
0x00, /* bInterval */
/* Endpoint Descriptor : Bulk-Out */
0x07, /* bLength */
0x05, /* ENDPOINT */
0x02, /* bEndpointAddress */
0x02, /* bmAttributes */
0x00, 0x02, /* wMaxPacketSize */
0x00, /* bInterval */
/* Endpoint Descriptor : Interrupt-In */
0x07, /* bLength */
0x05, /* ENDPOINT */
0x83, /* bEndpointAddress */
0x03, /* bmAttributes */
0x00, 0x02, /* wMaxPacketSize */
0x00, /* bInterval */
USB_DT_OTG_SIZE,
USB_DT_OTG,
USB_OTG_SRP|USB_OTG_HNP,
/* Configuration Descriptor */
0x09, /* bLength */
0x02, /* CONFIGURATION */
0x27, /* length */
0x0, /* length */
0x01, /* bNumInterfaces */
0x01, /* bConfigurationValue */
0x00, /* iConfiguration */
// 0xE0, /* bmAttributes */
0xC0, /* bmAttributes */
0x2, /* power */
/* Interface Descriptor */
0x09, /* bLength */
0x04, /* INTERFACE */
0x0, /* bInterfaceNumber */
0x0, /* bAlternateSetting */
0x03, /* bNumEndpoints */
0x06, /* bInterfaceClass */
0x01, /* bInterfaceSubClass */
0x01, /* bInterfaceProtocol */
0x00, /* iInterface */
/* Endpoint Descriptor : Bulk-In */
0x07, /* bLength */
0x05, /* ENDPOINT */
0x81, /* bEndpointAddress */
0x02, /* bmAttributes */
0x00, 0x02, /* wMaxPacketSize */
0x00, /* bInterval */
/* Endpoint Descriptor : Bulk-Out */
0x07, /* bLength */
0x05, /* ENDPOINT */
0x02, /* bEndpointAddress */
0x02, /* bmAttributes */
0x00, 0x02, /* wMaxPacketSize */
0x00, /* bInterval */
/* Endpoint Descriptor : Interrupt-In */
0x07, /* bLength */
0x05, /* ENDPOINT */
0x83, /* bEndpointAddress */
0x03, /* bmAttributes */
0x00, 0x02, /* wMaxPacketSize */
0x00, /* bInterval */
USB_DT_OTG_SIZE,
USB_DT_OTG,
USB_OTG_SRP|USB_OTG_HNP
};
#endif
#ifndef MAX
#define MAX(x, y) ((x < y)?y:x)
#endif
__u8 volatile usbMsdfn_Dscr[MAX(sizeof(Msdfn_MassStorage_Dscr),sizeof(Msdfn_PictureBridge_Dscr))] _at_ USB_MSDFN_DSCR_ADDR;//0xEE00;//USB_MSDFN_DSCR_ADDR;//0xEE00;//USB_MSDFN_DSCR_ADDR;//0xDA00;
__s32 usbParse_Received_Setup(void);
void usbFunction_Initial(void);
void usbDesInit(void)
{
__u16 i;
switch(OtgDeviceType)
{
case Device_PictureBridge:
for (i=0;i<sizeof(Msdfn_PictureBridge_Dscr);i++)
usbMsdfn_Dscr[i]=Msdfn_PictureBridge_Dscr[i];
break;
case Device_MassStorage:
for (i=0;i<sizeof(Msdfn_MassStorage_Dscr);i++)
usbMsdfn_Dscr[i]=Msdfn_MassStorage_Dscr[i];
/*
if(usbSpeed==HIGH_SPEED)
{
usbMsdfn_Dscr[2]=0x0;
usbMsdfn_Dscr[3]=0x02;
usbMsdfn_Dscr[40]=0x0;
usbMsdfn_Dscr[41]=0x02;
usbMsdfn_Dscr[47]=0x0;
usbMsdfn_Dscr[48]=0x02;
}*/
break;
}
}
void usbFunction_Initial(void)
{
if (usbSpeed==HIGH_SPEED)
{
USB_Setup_Endpoint(0,FIFO_DUAL,PIPE_CONTROL,0,0x40);
USB_Setup_Endpoint(1,EP_TX,PIPE_BULK,0,0x200);
USB_Setup_Endpoint(2,EP_RX,PIPE_BULK,0,0x200);
USB_Setup_Endpoint(3,EP_TX,PIPE_INTERRUPT,0,0x200);
}else if (usbSpeed==FULL_SPEED)
{
USB_Setup_Endpoint(0,FIFO_DUAL,PIPE_CONTROL,0,0x40);
USB_Setup_Endpoint(1,EP_TX,PIPE_BULK,0,0x40);
USB_Setup_Endpoint(2,EP_RX,PIPE_BULK,0,0x40);
USB_Setup_Endpoint(3,EP_TX,PIPE_INTERRUPT,0,0x40);
}
}
__u8 usbFunction_Load_Fifo(__s8 ep)
{
__u8 outreg;
outreg = M_CSR0_TXPKTRDY;
usbDRC_Fifo_Write_INT((__u8 *)usbEP[ep].transfer_buffer,ep);
if(usbEP[ep].LastPacket)
{
outreg |= M_CSR0_P_DATAEND;
usbEP[ep].IOState = EP_IDLE;
}
return outreg;
}
void usbParse_DRC_Int_Peripheral(drcintitem_t *dP)
{
__s8 ep;
__u8 parsestatus; /* setup parse result */
__u8 outreg; /* reset EP0 DRC regs with this */
outreg = 0;
ep = dP->IEP;
//usbIntStatus = 0xff; /* unused URB status code*/
usbDRC_Index_Select_INT(ep); /* get our idx in window */
#ifdef USB_DEBUG
//printf("\r\nep=%x ",ep);
//printf("\r\nstate=%x ",usbEP[0].IOState);
#endif
do /* while INDEX held ... */
{
if(!ep) /* commence EP0 analysis */
{
#ifdef Enable_OTG_TestPacket_Test
if (usbTestMode)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -