打印

2440开发板模拟usb鼠标,hid鼠标枚举过程遇到一些问题,求教

[复制链接]
1607|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
happain|  楼主 | 2013-8-24 16:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
电脑系统win7  32位,2440开发板自带四个按键,想利用这四个按键和usbdevice控制器模拟一个鼠标的运行,但是枚举过程就出现了问题
在写ep0函数中
void WrPktEp0(U8 *buf,int num)
{
        S3C24X0_USB_DEVICE * const usbdevregs  = S3C24X0_GetBase_USB_DEVICE();
        int i;
               
        for(i=0;i<num;i++)
        {
                usbdevregs->fifo[0].EP_FIFO_REG=buf;       
                //myprintf("0x%02x ",buf);
        }

        //for(i=0;i<num;i++)
        //{
        //        myprintf("0x%02x ",buf);
        //}
        //myprintf("\n");

}

注释掉红色字体,接收到的数据是下面这样的
[RCV:80,6,0,1,0,0,40,0,]
[RCV:0,5,1,0,0,0,0,0,]
[RCV:80,6,0,1,0,0,12,0,]
[RCV:80,6,0,2,0,0,ff,0,]
[RCV:80,6,0,3,0,0,ff,0,]
[RCV:80,6,2,3,9,4,ff,0,]
[RCV:80,6,0,2,0,0,9,0,]
[RCV:80,6,0,2,0,0,22,0,]
[RCV:80,6,0,3,0,0,ff,0,]
[RCV:80,6,1,3,9,4,ff,0,]
[RCV:80,6,2,3,9,4,ff,0,]
[RCV:80,6,0,1,0,0,40,0,]
[RCV:0,5,1,0,0,0,0,0,]
[RCV:80,6,0,1,0,0,12,0,]
[RCV:80,6,0,2,0,0,ff,0,]
[RCV:80,6,0,3,0,0,ff,0,]
[RCV:80,6,2,3,9,4,ff,0,]
[RCV:80,6,0,1,0,0,12,0,]
[RCV:80,6,0,2,0,0,9,0,]
[RCV:80,6,0,2,0,0,22,0,]
[RCV:0,9,1,0,0,0,0,0,]
[RCV:80,6,0,2,0,0,9,0,]
但是为什么没有收到设置请求和请求报告描述符的请求[RCV:21,a,0,0,0,0,0,0,] [RCV:81,6,0,22,0,0,74,0,]
如果不注释掉红色区域,打印出2440传给电脑的数据
void WrPktEp0(U8 *buf,int num)
{
        S3C24X0_USB_DEVICE * const usbdevregs  = S3C24X0_GetBase_USB_DEVICE();
        int i;
               
        for(i=0;i<num;i++)
        {
                usbdevregs->fifo[0].EP_FIFO_REG=buf;       
                //myprintf("0x%02x ",buf);
        }

        for(i=0;i<num;i++)
        {
                myprintf("0x%02x ",buf);
        }
        myprintf("\n");

}

则接收到的数据是
[RCV:80,6,0,1,0,0,40,0,]
0x12 0x01 0x10 0x01 0x00 0x00 0x00 0x08
0x45 0x53 0x34 0x12 0x00 0x01 0x01 0x02
[RCV:0,5,1,0,0,0,0,0,]
[RCV:80,6,0,1,0,0,12,0,]
0x12 0x01 0x10 0x01 0x00 0x00 0x00 0x08
0x45 0x53 0x34 0x12 0x00 0x01 0x01 0x02
0x00 0x01
[RCV:80,6,0,2,0,0,ff,0,]
0x09 0x02 0x22 0x00 0x01 0x01 0x00 0xc0
0x19
0x09 0x04 0x00 0x00 0x01 0x03 0x01
0x02 0x00
0x09 0x21 0x10 0x01 0x21 0x01
0x22 0x34 0x00
0x07 0x05 0x81 0x03 0x10
0x00 0x0a
[RCV:80,6,0,3,0,0,ff,0,]
0x04 0x03 0x09 0x04
[RCV:80,6,2,3,9,4,ff,0,]
0x2c 0x03 0x53 0x00 0x45 0x00 0x43 0x00
0x20 0x00 0x53 0x00 0x33 0x00 0x43 0x00
0x32 0x00 0x34 0x00 0x31 0x00 0x30 0x00
0x58 0x00 0x20 0x00 0x54 0x00 0x65 0x00
0x73 0x00 0x74 0x00 0x20 0x00 0x42 0x00
0x2f 0x00 0x44 0x00
[RCV:80,6,0,1,0,0,40,0,]
0x12 0x01 0x10 0x01 0x00 0x00 0x00 0x08
0x45 0x53 0x34 0x12 0x00 0x01 0x01 0x02
[RCV:0,5,1,0,0,0,0,0,]
[RCV:80,6,0,1,0,0,12,0,]
0x12 0x01 0x10 0x01 0x00 0x00 0x00 0x08
0x45 0x53 0x34 0x12 0x00 0x01 0x01 0x02
0x00 0x01
[RCV:80,6,0,2,0,0,ff,0,]
0x09 0x02 0x22 0x00 0x01 0x01 0x00 0xc0
0x19
0x09 0x04 0x00 0x00 0x01 0x03 0x01
0x02 0x00
0x09 0x21 0x10 0x01 0x21 0x01
0x22 0x34 0x00
0x07 0x05 0x81 0x03 0x10
0x00 0x0a
[RCV:80,6,12,3,9,4,ff,0,]
[RCV:80,6,0,1,0,0,12,0,]
0x12 0x01 0x10 0x01 0x00 0x00 0x00 0x08
0x45 0x53 0x34 0x12 0x00 0x01 0x01 0x02
0x00 0x01
[RCV:80,6,0,2,0,0,9,0,]
0x09 0x02 0x22 0x00 0x01 0x01 0x00 0xc0
0x19
[RCV:80,6,0,2,0,0,22,0,]
0x09 0x02 0x22 0x00 0x01 0x01 0x00 0xc0
0x19
0x09 0x04 0x00 0x00 0x01 0x03 0x01
0x02 0x00
0x09 0x21 0x10 0x01 0x21 0x01
0x22 0x34 0x00
0x07 0x05 0x81 0x03 0x10
0x00 0x0a
[RCV:0,9,1,0,0,0,0,0,]

[RCV:21,a,0,0,0,0,0,0,]
set idle
[RCV:81,6,0,22,0,0,74,0,]
0x05 0x01 0x09 0x02 0xa1 0x01 0x09 0x01
0xa1 0x00 0x05 0x09 0x19 0x01 0x29 0x03
0x15 0x00 0x25 0x01 0x95 0x03 0x75 0x01
0x81 0x02 0x95 0x01 0x75 0x05 0x81 0x03
0x05 0x01 0x09 0x30 0x09 0x31 0x09 0x38
0x15 0x81 0x25 0x7f 0x75 0x08 0x95 0x03
0x81 0x06 0xc0 0xc0

但是中间为什么出现了[RCV:80,6,12,3,9,4,ff,0,],并且设备未能识别,驱动没有安装成功,一个黄色的叹号

相关帖子

沙发
happain|  楼主 | 2013-8-24 16:19 | 只看该作者
下面把建立过程的整个代码发上面
void Ep0Handler(void)
{
        S3C24X0_USB_DEVICE * const usbdevregs  = S3C24X0_GetBase_USB_DEVICE();

        static int ep0SubState;
        //int i;
        U8 ep0_csr;

        //writeb(0, &usbdevregs->index_reg);
        usbdevregs->INDEX_REG = 0;
        ep0_csr =        usbdevregs->EP0_CSR_IN_CSR1_REG;
       
        DbgPrintf("<0:%x]\n",ep0_csr);

        //DATAEND interrupt(ep0_csr==0x0) will be ignored
        //because ep0State==EP0_STATE_INIT when the DATAEND interrupt is issued.

       
        if(ep0_csr & EP0_SETUP_END)
        {       
                 // Host may end GET_DESCRIPTOR operation without completing the IN data stage.
                 // If host does that, SETUP_END bit will be set.
                 // OUT_PKT_RDY has to be also cleared because status stage sets OUT_PKT_RDY to 1.
                DbgPrintf("[SETUPEND]");
                CLR_EP0_SETUP_END();
                if(ep0_csr & EP0_OUT_PKT_READY)
                {

                        FLUSH_EP0_FIFO(); //(???)
                                //I think this isn't needed because EP0 flush is done automatically.   
                        CLR_EP0_OUT_PKT_RDY();
                }

       
                ep0State=EP0_STATE_INIT;
                return;
        }       


        //I think that EP0_SENT_STALL will not be set to 1.
        if(ep0_csr & EP0_SENT_STALL)
        {       
                DbgPrintf("[STALL]");
                CLR_EP0_SENT_STALL();
                if(ep0_csr & EP0_OUT_PKT_READY)
                {
                        CLR_EP0_OUT_PKT_RDY();

                }
               
                ep0State=EP0_STATE_INIT;
                return;

        }       




        if((ep0_csr & EP0_OUT_PKT_READY)) // && (ep0State==EP0_STATE_INIT))
        {       
                RdPktEp0((U8 *)&descSetup,EP0_PKT_SIZE);

                PrintEp0Pkt((U8 *)(&descSetup)); //DEBUG

                if((descSetup.bmRequestType&0x80)==0x80)
                {
                        switch((descSetup.bmRequestType>>5)&0x03)
                        {
                                case 0://标准请求
                                        switch(descSetup.bRequest)
                                        {
                                               
                                                case GET_CONFIGURATION:

                                                        CLR_EP0_OUT_PKT_RDY();
                                                        ep0State=EP0_CONFIG_SET;

                                                break;
                                                case GET_DESCRIPTOR:
                                                        switch(descSetup.bValueH)                 
                                                        {
                                                                        case DEVICE_TYPE:
                                                                                DbgPrintf("[GDD]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                ep0State=EP0_STATE_GD_DEV_0;                       
                                                                        break;       
                                                                        case CONFIGURATION_TYPE:
                                                                                DbgPrintf("[GDC]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                        if((descSetup.bLengthL+(descSetup.bLengthH<<8))>0x9)
                                                                                          //bLengthH should be used for bLength=0x209 at WIN2K.        
                                                                                                ep0State=EP0_STATE_GD_CFG_0; //for WIN98,WIN2K
                                                                                        else                               
                                                                                                ep0State=EP0_STATE_GD_CFG_ONLY_0; //for WIN2K
                                                                         break;
                                                                        case STRING_TYPE:
                                                                                DbgPrintf("[GDS]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                switch(descSetup.bValueL)
                                                                                {
                                                                                        case 0:
                                                                                                ep0State=EP0_STATE_GD_STR_I0;
                                                                                                break;
                                                                                        case 1:
                                                                                                        ep0State=EP0_STATE_GD_STR_I1;
                                                                                                break;
                                                                                        case 2:
                                                                                                ep0State=EP0_STATE_GD_STR_I2;
                                                                                                break;
                                                                                        case 12:
                                                                                                ep0State=EP0_STATE_GD_STR_I0;
                                                                                                break;
                                                                                        default:
                                                                                        DbgPrintf("[UE:STRI?]");
                                                                                        //ep0State=EP0_STATE_INIT;
                                                                                        break;
                                                                                }
                                                                                ep0SubState=0;
                                                                        break;
                                                                        case INTERFACE_TYPE:
                                                                                DbgPrintf("[GDI]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                ep0State=EP0_STATE_GD_IF_ONLY_0; //for WIN98
                                                                        break;
                                                                        case REPORT_DESCRIPTOR:  //REPORT_DESCRIPTOR
                                                                                DbgPrintf("[GDRE]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                ep0State=EP0_REPORTOR_GD_0;
                                                                        break;
                                                                        case ENDPOINT_TYPE:                
                                                                                DbgPrintf("[GDE]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                switch(descSetup.bValueL&0xf)
                                                                                {
                                                                                        case 0:
                                                                                                ep0State=EP0_STATE_GD_EP0_ONLY_0;
                                                                                                break;
                                                                                        //case 1:
                                                                                                        //ep0State=EP0_STATE_GD_EP1_ONLY_0;
                                                                                                //break;
                                                                                        default:
                                                                                                DbgPrintf("[UE:GDE?]");
                                                                                                break;
                                                                                }
                                                                        break;
                                                                        default:
                                                                                DbgPrintf("[UE:GD?]");
                                                                        break;
                                                        }       
                                                break;
                                                case GET_INTERFACE:
                               
                                                        CLR_EP0_OUT_PKT_RDY();
                                                        ep0State=EP0_INTERFACE_GET;
                                  
                                                break;
                                                case GET_STATUS:

                                                        switch(descSetup.bmRequestType)
                                                        {
                                                                case  (0x80):

                                                                        CLR_EP0_OUT_PKT_RDY();
                                                                        StatusGet.Device=((U8)Rwuen<<1)|(U8)Selfpwr;
                                                                        ep0State=EP0_GET_STATUS0;
                                                                                               
                                                                break;

                                                                case  (0x81):
                                                                        CLR_EP0_OUT_PKT_RDY();
                                                                        StatusGet.Interface=0;
                                                                        ep0State=EP0_GET_STATUS1;
                                                                break;

                                                                case  (0x82):

                                                                        CLR_EP0_OUT_PKT_RDY();
                                                                        if((descSetup.bIndexL & 0x7f) == 0x00){
                                                                        ep0State=EP0_GET_STATUS2;
                                                                        }

                                                                        if((descSetup.bIndexL & 0x8f) == 0x81){
                                                                        ep0State=EP0_GET_STATUS3;
                                                                        }

                                                                        if((descSetup.bIndexL & 0x8f) == 0x03){
                                                                        ep0State=EP0_GET_STATUS4;
                                                                        }
                                                                break;

                                                                default:
                                                                break;
                                                        }
                                          
                                                break;
                                                case SYNCH_FRAME:
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                  
                                                default:
                                                        DbgPrintf("[UE:SETUP=%x]",descSetup.bRequest);
                                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                        }
                                break;
                                default:
                                        CLR_EP0_OUTPKTRDY_DATAEND();
                                        ep0State=EP0_STATE_INIT;
                                break;
                        }
                }
                else//标准输入请求
                {
                        switch((descSetup.bmRequestType>>5)&0x03)
                        {
                                case 0://标准请求
                                        switch(descSetup.bRequest)
                                        {
                                                case CLEAR_FEATURE:                
                                                        switch (descSetup.bmRequestType)
                                                        {
                                                                case DEVICE_RECIPIENT:
                                                                        if (descSetup.bValueL == 1)
                                                                                Rwuen = FALSE;

                                                                break;

                                                                case ENDPOINT_RECIPIENT:
                                                                        if (descSetup.bValueL == 0)
                                                                        {
                                                                                if((descSetup.bIndexL & 0x7f) == 0x00){
                                                                                StatusGet.Endpoint0= 0;   
                                                                                }
                                                                                if((descSetup.bIndexL & 0x8f) == 0x81){                   // IN  Endpoint 1
                                                                                StatusGet.Endpoint1= 0;                   
                                                                                }
                                                                                if((descSetup.bIndexL & 0x8f) == 0x03){                  // OUT Endpoint 3
                                                                                StatusGet.Endpoint3= 0;          
                                                                                }
                                                                        }
                                                                break;

                                                                default:
                                                                break;
                                                        }
                                                        CLR_EP0_OUTPKTRDY_DATAEND();
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                                case SET_ADDRESS:
                                                        DbgPrintf("[SA:%d]",descSetup.bValueL);
                                                        usbdevregs->FUNC_ADDR_REG=descSetup.bValueL | 0x80;
                                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                                case SET_CONFIGURATION:
                                                        DbgPrintf("[SC]");
                                                        ConfigSet.ConfigurationValue=descSetup.bValueL;
                                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                                        ep0State=EP0_SET_CFG;

                                                        isUsbdSetConfiguration=1;
                                                break;
                                                case SET_DESCRIPTOR:
                                                        CLR_EP0_OUTPKTRDY_DATAEND();
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                                case SET_FEATURE:
                                 
                                                        switch (descSetup.bmRequestType)
                                                        {
                                                                case DEVICE_RECIPIENT:
                                                                        if (descSetup.bValueL == 1)
                                                                                Rwuen = TRUE;
                                                                break;

                                                                case ENDPOINT_RECIPIENT:
                                                                        if (descSetup.bValueL == 0)
                                                                        {
                                                                                if((descSetup.bIndexL & 0x7f) == 0x00){
                                                                                        StatusGet.Endpoint0= 1;
                                                                                }
                                                                                if((descSetup.bIndexL & 0x8f) == 0x81){
                                                                                        StatusGet.Endpoint1= 1;
                                                                                }
                                                                                if((descSetup.bIndexL & 0x8f) == 0x03){
                                                                                        StatusGet.Endpoint3= 1;
                                                                                }
                                                                        }
                                                                break;

                                                                default:
                                                                break;
                                                        }
                                                        CLR_EP0_OUTPKTRDY_DATAEND();
                                                        ep0State=EP0_STATE_INIT;
                          
                                                break;
                                                case SET_INTERFACE:
                                                        InterfaceGet.AlternateSetting= descSetup.bValueL;
                                                        CLR_EP0_OUTPKTRDY_DATAEND();
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                                default:
                                                        DbgPrintf("[UE:SETUP=%x]",descSetup.bRequest);
                                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                        }
                                break;
                                case 1:
                                        switch(descSetup.bRequest)
                                        {
                                                case SET_IDLE:
                                                        myprintf("set idle\n");
                                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                                        ep0State=EP0_STATE_INIT;
                                                               
                                                break;
                                                default:
                                                        DbgPrintf("[UE:SETUP=%x]",descSetup.bRequest);
                                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                        }
                                break;
                                default:
                                        DbgPrintf("[UE:SETUP=%x]",descSetup.bRequest);
                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                        ep0State=EP0_STATE_INIT;
                                break;
                        }
                }
        }
        switch(ep0State)
        {       
                case EP0_STATE_INIT:
                break;

        //=== GET_DESCRIPTOR:DEVICE ===
                case EP0_STATE_GD_DEV_0:
                        DbgPrintf("[GDD0]");
                        WrPktEp0((U8 *)&descDev+0,8); //EP0_PKT_SIZE
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_DEV_1;
                break;
                       
                case EP0_STATE_GD_DEV_1:
                        DbgPrintf("[GDD1]");
                        WrPktEp0((U8 *)&descDev+0x8,8);
                        SET_EP0_IN_PKT_RDY();
                       
                        ep0State=EP0_STATE_GD_DEV_2;
                break;

                case EP0_STATE_GD_DEV_2:
                        DbgPrintf("[GDD2]");
                        WrPktEp0((U8 *)&descDev+0x10,2);   //8+8+2=0x12
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;
                break;
       

                //=== GET_DESCRIPTOR:CONFIGURATION+INTERFACE+ENDPOINT0+ENDPOINT1 ===
                //Windows98 gets these 4 descriptors all together by issuing only a request.
                //Windows2000 gets each descriptor seperately.
                case EP0_STATE_GD_CFG_0:
                        DbgPrintf("[GDC0]");
                        WrPktEp0((U8 *)&descConf+0,8); //EP0_PKT_SIZE
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_CFG_1;
                break;
       
                case EP0_STATE_GD_CFG_1:
                        DbgPrintf("[GDC1]");
                        WrPktEp0((U8 *)&descConf+8,1);
                        WrPktEp0((U8 *)&descIf+0,7);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_CFG_2;
                break;

                case EP0_STATE_GD_CFG_2:
                        DbgPrintf("[GDC2]");
                        WrPktEp0((U8 *)&descIf+7,2);
                        WrPktEp0((U8 *)&descHID+0,6);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_CFG_3;
                break;

                case EP0_STATE_GD_CFG_3:
                        DbgPrintf("[GDC3]");
                        WrPktEp0((U8 *)&descHID+6,3);
                        WrPktEp0((U8 *)&descEndpt0+0,5);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_CFG_4;                       
                break;

                case EP0_STATE_GD_CFG_4:
                        DbgPrintf("[GDC4]");
                         //zero length data packit
                         WrPktEp0((U8 *)&descEndpt0+5,2);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;

                //=== GET_DESCRIPTOR:CONFIGURATION ONLY===
                case EP0_STATE_GD_CFG_ONLY_0:
                        DbgPrintf("[GDCO0]");
                        WrPktEp0((U8 *)&descConf+0,8); //EP0_PKT_SIZE
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_CFG_ONLY_1;
                break;
       
                case EP0_STATE_GD_CFG_ONLY_1:
                        DbgPrintf("[GDCO1]");
                        WrPktEp0((U8 *)&descConf+8,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;

                //=== GET_DESCRIPTOR:INTERFACE ONLY===
                case EP0_STATE_GD_IF_ONLY_0:
                        DbgPrintf("[GDI0]");
                        WrPktEp0((U8 *)&descIf+0,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_IF_ONLY_1;
                break;
                case EP0_STATE_GD_IF_ONLY_1:
                        DbgPrintf("[GDI1]");
                        WrPktEp0((U8 *)&descIf+8,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;

#if 0       
        //=== GET_DESCRIPTOR:HID ONLY===

                case EP0_HID_GD_0:
                        DbgPrintf("[GDH0]");
                        WrPktEp0((U8 *)&descHID+0,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_HID_GD_1;
                break;
                case EP0_HID_GD_1:
                        DbgPrintf("[GDH1]");
                        WrPktEp0((U8 *)&descHID+8,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;
#endif
                //=== GET_DESCRIPTOR:ENDPOINT 0 ONLY===
                case EP0_STATE_GD_EP0_ONLY_0:
                        DbgPrintf("[GDE00]");
                        WrPktEp0((U8 *)&descEndpt0+0,7);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;
                       
                //=== GET_DESCRIPTOR:ENDPOINT 1 ONLY===
                case EP0_STATE_GD_EP1_ONLY_0:
                        DbgPrintf("[GDE10]");
                        WrPktEp0((U8 *)&descEndpt1+0,7);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;
                       
////////////////////////////////////////////

                case EP0_REPORTOR_GD_0:
                        DbgPrintf("[GDRE0]");
                        WrPktEp0((U8 *)ReportDescriptor+0,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_REPORTOR_GD_1;                       
                break;
               
                case EP0_REPORTOR_GD_1:
                        DbgPrintf("[GDRE1]");
                        WrPktEp0((U8 *)ReportDescriptor+8,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_REPORTOR_GD_2;                       
                break;
                case EP0_REPORTOR_GD_2:
                        DbgPrintf("[GDRE2]");
                        WrPktEp0((U8 *)ReportDescriptor+16,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_REPORTOR_GD_3;                       
                break;
                case EP0_REPORTOR_GD_3:
                        DbgPrintf("[GDRE3]");
                        WrPktEp0((U8 *)ReportDescriptor+24,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_REPORTOR_GD_4;                       
                break;
                case EP0_REPORTOR_GD_4:
                        DbgPrintf("[GDRE4]");
                        WrPktEp0((U8 *)ReportDescriptor+32,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_REPORTOR_GD_5;                       
                break;
                case EP0_REPORTOR_GD_5:
                        DbgPrintf("[GDRE5]");
                        WrPktEp0((U8 *)ReportDescriptor+40,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_REPORTOR_GD_6;                       
                break;
                case EP0_REPORTOR_GD_6:
                        DbgPrintf("[GDRE6]");
                        WrPktEp0((U8 *)ReportDescriptor+48,4);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;
////////////////////////////////////////////


                 case EP0_INTERFACE_GET:
                        WrPktEp0((U8 *)&InterfaceGet+0,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;


                //=== GET_DESCRIPTOR:STRING ===

                case EP0_STATE_GD_STR_I0:
                        DbgPrintf("[GDS0_0]");
                        WrPktEp0((U8 *)descStr0, 4 );  
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;         
                        ep0SubState=0;
                break;

                case EP0_STATE_GD_STR_I1:
                        DbgPrintf("[GDS1_%d]",ep0SubState);
                         if( (ep0SubState*EP0_PKT_SIZE+EP0_PKT_SIZE)<sizeof(descStr1) )
                        {
                                WrPktEp0((U8 *)descStr1+(ep0SubState*EP0_PKT_SIZE),EP0_PKT_SIZE);
                                SET_EP0_IN_PKT_RDY();
                                ep0State=EP0_STATE_GD_STR_I1;
                                ep0SubState++;
                        }
                        else
                        {
                                WrPktEp0((U8 *)descStr1+(ep0SubState*EP0_PKT_SIZE),
                                sizeof(descStr1)-(ep0SubState*EP0_PKT_SIZE));
                                SET_EP0_INPKTRDY_DATAEND();
                                ep0State=EP0_STATE_INIT;         
                                ep0SubState=0;
                        }
                break;

                case EP0_STATE_GD_STR_I2:
                        DbgPrintf("[GDS2_%d]",ep0SubState);
                         if( (ep0SubState*EP0_PKT_SIZE+EP0_PKT_SIZE)<sizeof(descStr2) )
                        {
                                WrPktEp0((U8 *)descStr2+(ep0SubState*EP0_PKT_SIZE),EP0_PKT_SIZE);
                                SET_EP0_IN_PKT_RDY();
                                ep0State=EP0_STATE_GD_STR_I2;
                                ep0SubState++;
                        }
                        else
                        {
                                DbgPrintf("[E]");
                                WrPktEp0((U8 *)descStr2+(ep0SubState*EP0_PKT_SIZE),
                                sizeof(descStr2)-(ep0SubState*EP0_PKT_SIZE));
                                SET_EP0_INPKTRDY_DATAEND();
                                ep0State=EP0_STATE_INIT;         
                                ep0SubState=0;
                        }
                break;

                case EP0_CONFIG_SET:
                        WrPktEp0((U8 *)&ConfigSet+0,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                        break;

                case EP0_GET_STATUS0:
                         WrPktEp0((U8 *)&StatusGet+0,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;

                 case EP0_GET_STATUS1:
                         WrPktEp0((U8 *)&StatusGet+1,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;

                 case EP0_GET_STATUS2:
                         WrPktEp0((U8 *)&StatusGet+2,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;

                 case EP0_GET_STATUS3:
                         WrPktEp0((U8 *)&StatusGet+3,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;

                 case EP0_GET_STATUS4:
                         WrPktEp0((U8 *)&StatusGet+4,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;

                  case EP0_SET_CFG:
                         WrPktEp0((U8 *)&descEndpt1,0);
                        //myprintf("dadadadada\n");
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;
               
                default:
                DbgPrintf("UE:G?D");

                break;
        }
}

使用特权

评论回复
板凳
happain|  楼主 | 2013-8-24 16:19 | 只看该作者
下面把建立过程的整个代码发上面void Ep0Handler(void)
{
        S3C24X0_USB_DEVICE * const usbdevregs  = S3C24X0_GetBase_USB_DEVICE();

        static int ep0SubState;
        //int i;
        U8 ep0_csr;

        //writeb(0, &usbdevregs->index_reg);
        usbdevregs->INDEX_REG = 0;
        ep0_csr =        usbdevregs->EP0_CSR_IN_CSR1_REG;
       
        DbgPrintf("<0:%x]\n",ep0_csr);

        //DATAEND interrupt(ep0_csr==0x0) will be ignored
        //because ep0State==EP0_STATE_INIT when the DATAEND interrupt is issued.

       
        if(ep0_csr & EP0_SETUP_END)
        {       
                 // Host may end GET_DESCRIPTOR operation without completing the IN data stage.
                 // If host does that, SETUP_END bit will be set.
                 // OUT_PKT_RDY has to be also cleared because status stage sets OUT_PKT_RDY to 1.
                DbgPrintf("[SETUPEND]");
                CLR_EP0_SETUP_END();
                if(ep0_csr & EP0_OUT_PKT_READY)
                {

                        FLUSH_EP0_FIFO(); //(???)
                                //I think this isn't needed because EP0 flush is done automatically.   
                        CLR_EP0_OUT_PKT_RDY();
                }

       
                ep0State=EP0_STATE_INIT;
                return;
        }       


        //I think that EP0_SENT_STALL will not be set to 1.
        if(ep0_csr & EP0_SENT_STALL)
        {       
                DbgPrintf("[STALL]");
                CLR_EP0_SENT_STALL();
                if(ep0_csr & EP0_OUT_PKT_READY)
                {
                        CLR_EP0_OUT_PKT_RDY();

                }
               
                ep0State=EP0_STATE_INIT;
                return;

        }       




        if((ep0_csr & EP0_OUT_PKT_READY)) // && (ep0State==EP0_STATE_INIT))
        {       
                RdPktEp0((U8 *)&descSetup,EP0_PKT_SIZE);

                PrintEp0Pkt((U8 *)(&descSetup)); //DEBUG

                if((descSetup.bmRequestType&0x80)==0x80)
                {
                        switch((descSetup.bmRequestType>>5)&0x03)
                        {
                                case 0://标准请求
                                        switch(descSetup.bRequest)
                                        {
                                               
                                                case GET_CONFIGURATION:

                                                        CLR_EP0_OUT_PKT_RDY();
                                                        ep0State=EP0_CONFIG_SET;

                                                break;
                                                case GET_DESCRIPTOR:
                                                        switch(descSetup.bValueH)                 
                                                        {
                                                                        case DEVICE_TYPE:
                                                                                DbgPrintf("[GDD]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                ep0State=EP0_STATE_GD_DEV_0;                       
                                                                        break;       
                                                                        case CONFIGURATION_TYPE:
                                                                                DbgPrintf("[GDC]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                        if((descSetup.bLengthL+(descSetup.bLengthH<<8))>0x9)
                                                                                          //bLengthH should be used for bLength=0x209 at WIN2K.        
                                                                                                ep0State=EP0_STATE_GD_CFG_0; //for WIN98,WIN2K
                                                                                        else                               
                                                                                                ep0State=EP0_STATE_GD_CFG_ONLY_0; //for WIN2K
                                                                         break;
                                                                        case STRING_TYPE:
                                                                                DbgPrintf("[GDS]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                switch(descSetup.bValueL)
                                                                                {
                                                                                        case 0:
                                                                                                ep0State=EP0_STATE_GD_STR_I0;
                                                                                                break;
                                                                                        case 1:
                                                                                                        ep0State=EP0_STATE_GD_STR_I1;
                                                                                                break;
                                                                                        case 2:
                                                                                                ep0State=EP0_STATE_GD_STR_I2;
                                                                                                break;
                                                                                        case 12:
                                                                                                ep0State=EP0_STATE_GD_STR_I0;
                                                                                                break;
                                                                                        default:
                                                                                        DbgPrintf("[UE:STRI?]");
                                                                                        //ep0State=EP0_STATE_INIT;
                                                                                        break;
                                                                                }
                                                                                ep0SubState=0;
                                                                        break;
                                                                        case INTERFACE_TYPE:
                                                                                DbgPrintf("[GDI]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                ep0State=EP0_STATE_GD_IF_ONLY_0; //for WIN98
                                                                        break;
                                                                        case REPORT_DESCRIPTOR:  //REPORT_DESCRIPTOR
                                                                                DbgPrintf("[GDRE]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                ep0State=EP0_REPORTOR_GD_0;
                                                                        break;
                                                                        case ENDPOINT_TYPE:                
                                                                                DbgPrintf("[GDE]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                switch(descSetup.bValueL&0xf)
                                                                                {
                                                                                        case 0:
                                                                                                ep0State=EP0_STATE_GD_EP0_ONLY_0;
                                                                                                break;
                                                                                        //case 1:
                                                                                                        //ep0State=EP0_STATE_GD_EP1_ONLY_0;
                                                                                                //break;
                                                                                        default:
                                                                                                DbgPrintf("[UE:GDE?]");
                                                                                                break;
                                                                                }
                                                                        break;
                                                                        default:
                                                                                DbgPrintf("[UE:GD?]");
                                                                        break;
                                                        }       
                                                break;
                                                case GET_INTERFACE:
                               
                                                        CLR_EP0_OUT_PKT_RDY();
                                                        ep0State=EP0_INTERFACE_GET;
                                  
                                                break;
                                                case GET_STATUS:

                                                        switch(descSetup.bmRequestType)
                                                        {
                                                                case  (0x80):

                                                                        CLR_EP0_OUT_PKT_RDY();
                                                                        StatusGet.Device=((U8)Rwuen<<1)|(U8)Selfpwr;
                                                                        ep0State=EP0_GET_STATUS0;
                                                                                               
                                                                break;

                                                                case  (0x81):
                                                                        CLR_EP0_OUT_PKT_RDY();
                                                                        StatusGet.Interface=0;
                                                                        ep0State=EP0_GET_STATUS1;
                                                                break;

                                                                case  (0x82):

                                                                        CLR_EP0_OUT_PKT_RDY();
                                                                        if((descSetup.bIndexL & 0x7f) == 0x00){
                                                                        ep0State=EP0_GET_STATUS2;
                                                                        }

                                                                        if((descSetup.bIndexL & 0x8f) == 0x81){
                                                                        ep0State=EP0_GET_STATUS3;
                                                                        }

                                                                        if((descSetup.bIndexL & 0x8f) == 0x03){
                                                                        ep0State=EP0_GET_STATUS4;
                                                                        }
                                                                break;

                                                                default:
                                                                break;
                                                        }
                                          
                                                break;
                                                case SYNCH_FRAME:
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                  
                                                default:
                                                        DbgPrintf("[UE:SETUP=%x]",descSetup.bRequest);
                                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                        }
                                break;
                                default:
                                        CLR_EP0_OUTPKTRDY_DATAEND();
                                        ep0State=EP0_STATE_INIT;
                                break;
                        }
                }
                else//标准输入请求
                {
                        switch((descSetup.bmRequestType>>5)&0x03)
                        {
                                case 0://标准请求
                                        switch(descSetup.bRequest)
                                        {
                                                case CLEAR_FEATURE:                
                                                        switch (descSetup.bmRequestType)
                                                        {
                                                                case DEVICE_RECIPIENT:
                                                                        if (descSetup.bValueL == 1)
                                                                                Rwuen = FALSE;

                                                                break;

                                                                case ENDPOINT_RECIPIENT:
                                                                        if (descSetup.bValueL == 0)
                                                                        {
                                                                                if((descSetup.bIndexL & 0x7f) == 0x00){
                                                                                StatusGet.Endpoint0= 0;   
                                                                                }
                                                                                if((descSetup.bIndexL & 0x8f) == 0x81){                   // IN  Endpoint 1
                                                                                StatusGet.Endpoint1= 0;                   
                                                                                }
                                                                                if((descSetup.bIndexL & 0x8f) == 0x03){                  // OUT Endpoint 3
                                                                                StatusGet.Endpoint3= 0;          
                                                                                }
                                                                        }
                                                                break;

                                                                default:
                                                                break;
                                                        }
                                                        CLR_EP0_OUTPKTRDY_DATAEND();
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                                case SET_ADDRESS:
                                                        DbgPrintf("[SA:%d]",descSetup.bValueL);
                                                        usbdevregs->FUNC_ADDR_REG=descSetup.bValueL | 0x80;
                                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                                case SET_CONFIGURATION:
                                                        DbgPrintf("[SC]");
                                                        ConfigSet.ConfigurationValue=descSetup.bValueL;
                                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                                        ep0State=EP0_SET_CFG;

                                                        isUsbdSetConfiguration=1;
                                                break;
                                                case SET_DESCRIPTOR:
                                                        CLR_EP0_OUTPKTRDY_DATAEND();
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                                case SET_FEATURE:
                                 
                                                        switch (descSetup.bmRequestType)
                                                        {
                                                                case DEVICE_RECIPIENT:
                                                                        if (descSetup.bValueL == 1)
                                                                                Rwuen = TRUE;
                                                                break;

                                                                case ENDPOINT_RECIPIENT:
                                                                        if (descSetup.bValueL == 0)
                                                                        {
                                                                                if((descSetup.bIndexL & 0x7f) == 0x00){
                                                                                        StatusGet.Endpoint0= 1;
                                                                                }
                                                                                if((descSetup.bIndexL & 0x8f) == 0x81){
                                                                                        StatusGet.Endpoint1= 1;
                                                                                }
                                                                                if((descSetup.bIndexL & 0x8f) == 0x03){
                                                                                        StatusGet.Endpoint3= 1;
                                                                                }
                                                                        }
                                                                break;

                                                                default:
                                                                break;
                                                        }
                                                        CLR_EP0_OUTPKTRDY_DATAEND();
                                                        ep0State=EP0_STATE_INIT;
                          
                                                break;
                                                case SET_INTERFACE:
                                                        InterfaceGet.AlternateSetting= descSetup.bValueL;
                                                        CLR_EP0_OUTPKTRDY_DATAEND();
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                                default:
                                                        DbgPrintf("[UE:SETUP=%x]",descSetup.bRequest);
                                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                        }
                                break;
                                case 1:
                                        switch(descSetup.bRequest)
                                        {
                                                case SET_IDLE:
                                                        myprintf("set idle\n");
                                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                                        ep0State=EP0_STATE_INIT;
                                                               
                                                break;
                                                default:
                                                        DbgPrintf("[UE:SETUP=%x]",descSetup.bRequest);
                                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                                        ep0State=EP0_STATE_INIT;
                                                break;
                                        }
                                break;
                                default:
                                        DbgPrintf("[UE:SETUP=%x]",descSetup.bRequest);
                                        CLR_EP0_OUTPKTRDY_DATAEND(); //Because of no data control transfers.
                                        ep0State=EP0_STATE_INIT;
                                break;
                        }
                }
        }
        switch(ep0State)
        {       
                case EP0_STATE_INIT:
                break;

        //=== GET_DESCRIPTOR:DEVICE ===
                case EP0_STATE_GD_DEV_0:
                        DbgPrintf("[GDD0]");
                        WrPktEp0((U8 *)&descDev+0,8); //EP0_PKT_SIZE
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_DEV_1;
                break;
                       
                case EP0_STATE_GD_DEV_1:
                        DbgPrintf("[GDD1]");
                        WrPktEp0((U8 *)&descDev+0x8,8);
                        SET_EP0_IN_PKT_RDY();
                       
                        ep0State=EP0_STATE_GD_DEV_2;
                break;

                case EP0_STATE_GD_DEV_2:
                        DbgPrintf("[GDD2]");
                        WrPktEp0((U8 *)&descDev+0x10,2);   //8+8+2=0x12
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;
                break;
       

                //=== GET_DESCRIPTOR:CONFIGURATION+INTERFACE+ENDPOINT0+ENDPOINT1 ===
                //Windows98 gets these 4 descriptors all together by issuing only a request.
                //Windows2000 gets each descriptor seperately.
                case EP0_STATE_GD_CFG_0:
                        DbgPrintf("[GDC0]");
                        WrPktEp0((U8 *)&descConf+0,8); //EP0_PKT_SIZE
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_CFG_1;
                break;
       
                case EP0_STATE_GD_CFG_1:
                        DbgPrintf("[GDC1]");
                        WrPktEp0((U8 *)&descConf+8,1);
                        WrPktEp0((U8 *)&descIf+0,7);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_CFG_2;
                break;

                case EP0_STATE_GD_CFG_2:
                        DbgPrintf("[GDC2]");
                        WrPktEp0((U8 *)&descIf+7,2);
                        WrPktEp0((U8 *)&descHID+0,6);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_CFG_3;
                break;

                case EP0_STATE_GD_CFG_3:
                        DbgPrintf("[GDC3]");
                        WrPktEp0((U8 *)&descHID+6,3);
                        WrPktEp0((U8 *)&descEndpt0+0,5);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_CFG_4;                       
                break;

                case EP0_STATE_GD_CFG_4:
                        DbgPrintf("[GDC4]");
                         //zero length data packit
                         WrPktEp0((U8 *)&descEndpt0+5,2);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;

                //=== GET_DESCRIPTOR:CONFIGURATION ONLY===
                case EP0_STATE_GD_CFG_ONLY_0:
                        DbgPrintf("[GDCO0]");
                        WrPktEp0((U8 *)&descConf+0,8); //EP0_PKT_SIZE
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_CFG_ONLY_1;
                break;
       
                case EP0_STATE_GD_CFG_ONLY_1:
                        DbgPrintf("[GDCO1]");
                        WrPktEp0((U8 *)&descConf+8,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;

                //=== GET_DESCRIPTOR:INTERFACE ONLY===
                case EP0_STATE_GD_IF_ONLY_0:
                        DbgPrintf("[GDI0]");
                        WrPktEp0((U8 *)&descIf+0,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_STATE_GD_IF_ONLY_1;
                break;
                case EP0_STATE_GD_IF_ONLY_1:
                        DbgPrintf("[GDI1]");
                        WrPktEp0((U8 *)&descIf+8,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;

#if 0       
        //=== GET_DESCRIPTOR:HID ONLY===

                case EP0_HID_GD_0:
                        DbgPrintf("[GDH0]");
                        WrPktEp0((U8 *)&descHID+0,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_HID_GD_1;
                break;
                case EP0_HID_GD_1:
                        DbgPrintf("[GDH1]");
                        WrPktEp0((U8 *)&descHID+8,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;
#endif
                //=== GET_DESCRIPTOR:ENDPOINT 0 ONLY===
                case EP0_STATE_GD_EP0_ONLY_0:
                        DbgPrintf("[GDE00]");
                        WrPktEp0((U8 *)&descEndpt0+0,7);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;
                       
                //=== GET_DESCRIPTOR:ENDPOINT 1 ONLY===
                case EP0_STATE_GD_EP1_ONLY_0:
                        DbgPrintf("[GDE10]");
                        WrPktEp0((U8 *)&descEndpt1+0,7);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;
                       
////////////////////////////////////////////

                case EP0_REPORTOR_GD_0:
                        DbgPrintf("[GDRE0]");
                        WrPktEp0((U8 *)ReportDescriptor+0,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_REPORTOR_GD_1;                       
                break;
               
                case EP0_REPORTOR_GD_1:
                        DbgPrintf("[GDRE1]");
                        WrPktEp0((U8 *)ReportDescriptor+8,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_REPORTOR_GD_2;                       
                break;
                case EP0_REPORTOR_GD_2:
                        DbgPrintf("[GDRE2]");
                        WrPktEp0((U8 *)ReportDescriptor+16,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_REPORTOR_GD_3;                       
                break;
                case EP0_REPORTOR_GD_3:
                        DbgPrintf("[GDRE3]");
                        WrPktEp0((U8 *)ReportDescriptor+24,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_REPORTOR_GD_4;                       
                break;
                case EP0_REPORTOR_GD_4:
                        DbgPrintf("[GDRE4]");
                        WrPktEp0((U8 *)ReportDescriptor+32,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_REPORTOR_GD_5;                       
                break;
                case EP0_REPORTOR_GD_5:
                        DbgPrintf("[GDRE5]");
                        WrPktEp0((U8 *)ReportDescriptor+40,8);
                        SET_EP0_IN_PKT_RDY();
                        ep0State=EP0_REPORTOR_GD_6;                       
                break;
                case EP0_REPORTOR_GD_6:
                        DbgPrintf("[GDRE6]");
                        WrPktEp0((U8 *)ReportDescriptor+48,4);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;                       
                break;
////////////////////////////////////////////


                 case EP0_INTERFACE_GET:
                        WrPktEp0((U8 *)&InterfaceGet+0,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;


                //=== GET_DESCRIPTOR:STRING ===

                case EP0_STATE_GD_STR_I0:
                        DbgPrintf("[GDS0_0]");
                        WrPktEp0((U8 *)descStr0, 4 );  
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;         
                        ep0SubState=0;
                break;

                case EP0_STATE_GD_STR_I1:
                        DbgPrintf("[GDS1_%d]",ep0SubState);
                         if( (ep0SubState*EP0_PKT_SIZE+EP0_PKT_SIZE)<sizeof(descStr1) )
                        {
                                WrPktEp0((U8 *)descStr1+(ep0SubState*EP0_PKT_SIZE),EP0_PKT_SIZE);
                                SET_EP0_IN_PKT_RDY();
                                ep0State=EP0_STATE_GD_STR_I1;
                                ep0SubState++;
                        }
                        else
                        {
                                WrPktEp0((U8 *)descStr1+(ep0SubState*EP0_PKT_SIZE),
                                sizeof(descStr1)-(ep0SubState*EP0_PKT_SIZE));
                                SET_EP0_INPKTRDY_DATAEND();
                                ep0State=EP0_STATE_INIT;         
                                ep0SubState=0;
                        }
                break;

                case EP0_STATE_GD_STR_I2:
                        DbgPrintf("[GDS2_%d]",ep0SubState);
                         if( (ep0SubState*EP0_PKT_SIZE+EP0_PKT_SIZE)<sizeof(descStr2) )
                        {
                                WrPktEp0((U8 *)descStr2+(ep0SubState*EP0_PKT_SIZE),EP0_PKT_SIZE);
                                SET_EP0_IN_PKT_RDY();
                                ep0State=EP0_STATE_GD_STR_I2;
                                ep0SubState++;
                        }
                        else
                        {
                                DbgPrintf("[E]");
                                WrPktEp0((U8 *)descStr2+(ep0SubState*EP0_PKT_SIZE),
                                sizeof(descStr2)-(ep0SubState*EP0_PKT_SIZE));
                                SET_EP0_INPKTRDY_DATAEND();
                                ep0State=EP0_STATE_INIT;         
                                ep0SubState=0;
                        }
                break;

                case EP0_CONFIG_SET:
                        WrPktEp0((U8 *)&ConfigSet+0,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                        break;

                case EP0_GET_STATUS0:
                         WrPktEp0((U8 *)&StatusGet+0,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;

                 case EP0_GET_STATUS1:
                         WrPktEp0((U8 *)&StatusGet+1,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;

                 case EP0_GET_STATUS2:
                         WrPktEp0((U8 *)&StatusGet+2,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;

                 case EP0_GET_STATUS3:
                         WrPktEp0((U8 *)&StatusGet+3,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;

                 case EP0_GET_STATUS4:
                         WrPktEp0((U8 *)&StatusGet+4,1);
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;

                  case EP0_SET_CFG:
                         WrPktEp0((U8 *)&descEndpt1,0);
                        //myprintf("dadadadada\n");
                        SET_EP0_INPKTRDY_DATAEND();
                        ep0State=EP0_STATE_INIT;          
                 break;
               
                default:
                DbgPrintf("UE:G?D");

                break;
        }
}


使用特权

评论回复
地板
happain|  楼主 | 2013-8-24 16:19 | 只看该作者
case STRING_TYPE:
                                                                                DbgPrintf("[GDS]");
                                                                                CLR_EP0_OUT_PKT_RDY();
                                                                                switch(descSetup.bValueL)
                                                                                {
                                                                                        case 0:
                                                                                                ep0State=EP0_STATE_GD_STR_I0;
                                                                                                break;
                                                                                        case 1:
                                                                                                        ep0State=EP0_STATE_GD_STR_I1;
                                                                                                break;
                                                                                        case 2:
                                                                                                ep0State=EP0_STATE_GD_STR_I2;
                                                                                                break;
                                                                                        case 12:
                                                                                                ep0State=EP0_STATE_GD_STR_I0;
                                                                                                break;
                                                                                        default:

                                                                                        DbgPrintf("[UE:STRI?]");
                                                                                        //ep0State=EP0_STATE_INIT;
                                                                                        break;
                                                                                }
                                                                                ep0SubState=0;
                                                                        break;
如果自己添加了这个case12 还能接受字符串申请,如果不加,字符串申请时接收不到的

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

4

帖子

0

粉丝