unsigned char get_descr_ex() { unsigned char descr_len; unsigned char *p=data_buf; endp7_mode=0x80;//unsigned char endp6_mode=0x80, endp7_mode=0x80;//同步標(biāo)志位初值 toggle_send(); wr_usb_data(8,Request.Req_buf); //void issue_token( unsigned char endp_and_pid ) { /* 執(zhí)行USB事務(wù) */ //CH375_WR_CMD_PORT( CMD_ISSUE_TOKEN ); //CH375_WR_DAT_PORT( endp_and_pid ); /* 高4位目的端點(diǎn)號(hào), 低4位令牌PID */ //status=0xff;} //#define DEF_USB_PID_SETUP 0x0D USB的包標(biāo)識(shí)PID, 主機(jī)方式可能用到 issue_token(( 0 << 4 ) | DEF_USB_PID_SETUP); //unsigned char wait_interrupt() { /* 主機(jī)端等待操作完成, 返回操作狀態(tài) */ //while( CH375_INT_WIRE ); /* 查詢(xún)等待CH375操作完成中斷(INT#低電平) */ //CH375_WR_CMD_PORT( CMD_GET_STATUS ); /* 產(chǎn)生操作完成中斷, 獲取中斷狀態(tài) */ //return( CH375_RD_DAT_PORT() );}
status=wait_interrupt(); if(status==USB_INT_SUCCESS)/* SETUP階段操作成功 */ { endp6_mode=0xc0; toggle_recv(); } else return(0); issue_token(( 0 << 4 ) | DEF_USB_PID_IN);status=wait_interrupt(); if(status==USB_INT_SUCCESS)/* DATA階段操作成功 */ { if(flag_config_2)descr_len=data_buf[2]-rd_usb_data(data_buf); else descr_len=data_buf[0]-rd_usb_data(data_buf); while(descr_len>0) { toggle_recv(); p+=0x08; issue_token(( 0 << 4 ) | DEF_USB_PID_IN);status=wait_interrupt(); if(status==USB_INT_SUCCESS) /* DATA階段操作成功 */ descr_len-=rd_usb_data(p); else return(0); } } else return(0); endp7_mode=0xc0; toggle_send(); wr_usb_data(0,Request.Req_buf); issue_token(( 0 << 4 ) | DEF_USB_PID_OUT);status=wait_interrupt(); if(status==USB_INT_SUCCESS)/* 狀態(tài)階段操作成功 */ return(1); else return(0); } 為什么要進(jìn)行兩次DATA階段操作