⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb.lst

📁 make mp3 by yourself
💻 LST
📖 第 1 页 / 共 4 页
字号:
 166                                                                                  
 167                                                                                      9,
 168                                                                                      4,
 169                                                                                      0,                 //the index of the interface descriptor Number of Interface
 170                                                                                      0,                 //Value used to select alternative setting
 171                                                                                          2,                 //EndPoint Number Used in this Descriptor
 172                                                                                          8,                 //Class Code (Assigned by USB Org)
 173                                                                                          6,                     //interface subclass1=RBC,2=SFF,3=QIC,4=UFI,5=SFF,6=SCSI
 174                                                                                          0x50,              //bulk 0nly Transport
 175                                                                                          0,                 //Index of String Descriptor Describing this interface
 176          
 177                                                                                                             //Bulk-in Endpoint
 178                                                                                           0x07,             //length of this desc.   
 179                                                                                           0x05,             //ENDPOINT descriptor TYPE
 180                                                                                           0x81,             //address (IN) Endpoint 4 84
 181                                                                                           0x02,             //attributes  (BULK)    
 182                                                                                           0x40, 0x00,       //max packet size (64)  
 183                                                                                           0x0,              //Does not apply to Bulk endpoints
 184                                                                  
 185                                                                                                             //Bulk-out Endpoint
 186                                                                                           0x07,             //length of this desc.   
 187                                                                                           0x05,             //ENDPOINT descriptor TYPE
 188                                                                                           0x02,             //address (OUT) Endpoint 5 05
 189                                                                                           0x02,             //attributes  (BULK)
 190                                                                                           0x40, 0x00,       //max packet size (64)
 191                                                                                           0x0               //Does not apply to Bulk endpoints
 192                                                                                          };
 193          
 194          void Get_Descriptor(unsigned char DesType,unsigned char nLength)           //得到描述符
 195          {
 196   1              if(DesType==0x01)                                                                                                          //取设备描述符
 197   1                      WriteEp(0,18,Device_Descriptor);
 198   1      
 199   1              if((DesType==0x02)&&(nLength==0x09))                                                   //取端口描述符
 200   1                      WriteEp(0,9,Configuration_Descriptor_All);
 201   1      
 202   1              if((DesType==0x02)&&(nLength==0xff))                                                   //取端点描述符
 203   1              {
 204   2                  WriteEp(0,32,Configuration_Descriptor_All);
 205   2                  WriteEp(0,2,&Device_Descriptor[4]);
 206   2              }
 207   1      
 208   1              if((DesType==0x02)&&(nLength==0x20)) 
 209   1                      WriteEp(0,32,Configuration_Descriptor_All);                            //取配置描述符
 210   1      }
 211          
 212          void Set_Configuration(unsigned char wValue)            //设置配置
 213          {
 214   1        if(wValue == 0)
 215   1        {
 216   2                      UEPNUM=0x00;    UEPCONX=0x80;
 217   2                      UEPNUM=0x01;    UEPCONX=0x86;
 218   2                      UEPNUM=0x02;    UEPCONX=0x82;
 219   2                      USBCON&=(~CONFG);
 220   2                      WriteEp(0,0,0);                                                         //状态传送阶段之前完成指定操作
 221   2        }
 222   1        else if(wValue == 1) 
 223   1        {
 224   2                      UEPNUM=0x00;    UEPCONX=0x80;
 225   2                      UEPNUM=0x01;    UEPCONX=0x86;
 226   2                      UEPNUM=0x02;    UEPCONX=0x82;
 227   2                      USBCON|=CONFG;
C51 COMPILER V7.06   USB                                                                             03/21/2006 09:38:04 PAGE 4   

 228   2                      WriteEp(0,0,0);                                                         //状态传送阶段之前完成指定操作
 229   2        }
 230   1      }
 231          
 232          void Ep0()                                          //---端点0处理主函数
 233          {
 234   1        unsigned char data DT[32]={0,};                   //DT[]的1到31的31个数的值也是0啊
 235   1        unsigned char data i;
 236   1        i = ReadEp(0,DT);                                 //该函数的原型在上面
 237   1        if (((DT[0] & 0x60)==0) && i)
 238   1        {
 239   2          switch (DT[1])
 240   2          {
 241   3            case set_address                          :Set_Address(DT[2]);                    break;  //设置地址
 242   3            case get_descriptor                       :Get_Descriptor(DT[3],DT[6]);   break;  //取描述符
 243   3            case set_configuration        :Set_Configuration(DT[2]);          break;  //设置配置
 244   3            default                                           :;                                                  break;
 245   3              }
 246   2        }
 247   1        else if(DT[0]==0xa1)                                                          //非标准USB请求
 248   1              {
 249   2                      WriteEp(0,0,0);
 250   2              }                                                                                                       
 251   1      }
 252          
 253          /******************************************************************************/
 254          /**                   以下为利用Bulk_Only传输协议的函数部分                  **/
 255          /******************************************************************************/
 256          unsigned char data bulk_CSW[]={0x55,0x53,0x42,0x53,     // bytes 4 dCSWSignature
 257                                                        0x00,0x00,0x00,0x00,          //bytes 4  dCSWTag
 258                                                        0x00,0x00,0x00,0x00,              //bytes 4 dDataResiduce
 259                                                        0x00};                            //bCSWStatus  00=good state.
 260          
 261          typedef struct _STRUCT_CBW
 262          {
 263                  unsigned char CBWCB[12];                        //for UFI Command all have 12bit
 264          
 265          } struct_CBW;
 266          
 267          struct_CBW data bulk_CBW;
 268          
 269          void WriteEpBulk(unsigned char EpNum,unsigned char nLength,unsigned char *Data)
 270          {
 271   1              unsigned char data i;
 272   1              UEPNUM=EpNum;                                           //---设置端点号
 273   1              UEPSTAX|=DIR;                                           //...设置为In模式
 274   1              for(i=0;i<nLength;i++) UEPDATX=Data[i];         //---填缓冲区
 275   1              UEPSTAX|=TXRDY;                                     //---发送数据
 276   1      }
 277          
 278          void TransmitCSW()                                                                      //向Host返回CSW
 279          { 
 280   1        WriteEpBulk(1, sizeof(bulk_CSW), bulk_CSW);
 281   1        while(!(UEPSTAX&TXCMP)) ;
 282   1        UEPSTAX&=(~(TXCMP));                                          //清除TXCMP
 283   1        UEPINT = 0;
 284   1      }
 285          
 286          void main_txdone()                                                       //数据发送完毕给出回复
 287          {
 288   1        UEPSTAX&=(~(TXCMP));                                           //清除TXCMP
 289   1        TransmitCSW();
 290   1      }
 291          
 292          
 293          //////////////////////////////////有关输出端点的调用//////////////////////////////////////////////
 294          #define Inquiry                                                 0x12
 295          #define Mode_Sense                                              0x1A
 296          #define Read10                                                  0x28
 297          #define Read_Capacity                                   0x25 
 298          #define Read_Format_Capacities          0x23 
 299          #define Test_Unit_Ready                                 0x00 
 300          #define Verify                                                  0x2F 
 301          #define Write10                                                 0x2A 
 302          #define Medium_Removal                                  0x1E
 303          
 304          #define SCSI_MSPGCD_TPP                     0x1C
 305          #define SCSI_MSPGCD_RETALL                          0x3F
C51 COMPILER V7.06   USB                                                                             03/21/2006 09:38:04 PAGE 5   

 306          
 307          //SCSI-Inquiry命令的返回数据  
 308          code unsigned char B_InquiryData[] = {
 309                                                                  0x00,                          //Direct Access Device
 310                                                                  0x80,                          //RMB
 311                                                                  0x00,                          //ISO/ECMA/ANSI
 312                                                                  0x01,                          //Response Data Format
 313                                                                  0x1f,                          //Additional Length
 314                                                                  0x00,                          //Reserved
 315                                                                  0x00,                          //Reserved
 316                                                                  0x00,                          //Reserved 
 317                                                                  'U', 'P', '-', 'T', 'E', 'C', 'H', ' ',        //Vendor Information
 318                                                                  'M', 'P', '3', ' ', 'P', 'l', 'a', 'y', 'e', 'r', ' ', 'V', '3', '.', '0', '0',//Product Identification
 319                                                                  0, 0, 0, 0};                   //Product Revision Level n.nn
 320          
 321          //SCSI-Read_Format_capacities命令的返回数据      
 322          code unsigned char B_Read_Format_capacities[] = {0x00, 0x00, 0x00, 0x10,                //capacity list header
 323                                                                                  0x00, 0x00, 0x07, 0xf5, 0x01, 0x00, 0x02, 0x00, //capacity descriptor
 324                                                                              //Number of Blocks =2037,unformatted media,blocklength = 512Bytes
 325                                                                                  0x00, 0x00, 0x07, 0xfd, 0x00, 0x00, 0x02, 0x00  //Formattable Capacity Descriptors
 326                                                                                  };
 327          //SCSI-Read_Capacity命令的返回数据
 328          code unsigned char B_Read_Capacity[] = {
 329                                                                          0x00, 0x00, 0xfe, 0xa0,    //Last  Logical Block Address for 32MB 
 330                                                                          0x00, 0x00, 0x02, 0x00     //block length in bytes
 331                                                                          };
 332          //SCSI-Mode_Sense命令的返回数据                         
 333          code unsigned char B_Mode_Sense_ALL[] = {0x0b, 0x00,       //Mode Data Length
 334                                                                  0x00, 0x08, 0x00, 0x00,
 335                                                                  0x7d, 0, 0, 0, 0x02, 0x00
 336                                                                  };
 337          //SCSI-Mode_Sense命令的返回数据                 
 338          code unsigned char B_Mode_Sense_TPP[] = {0xf0, 0x00,       //Mode Data Length
 339                                                                  05, 00, 00, 00, 00, 0x0b, 00, 00, 00, 00, 0x24, 00, 00, 00, 00, 00

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -