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

📄 upsd3400_usb_app.lst

📁 uPSD34xx Disk driver
💻 LST
📖 第 1 页 / 共 4 页
字号:
 606   1        USB_FIFO[31] = ' ';
 607   1      
 608   1        USB_FIFO[32] = '1';                        //Product Revision Level
 609   1        USB_FIFO[33] = '0';
 610   1        USB_FIFO[34] = '0';
 611   1        USB_FIFO[35] = '1';
 612   1      
 613   1        USIZE = 36;
C51 COMPILER V7.50   UPSD3400_USB_APP                                                      09/13/2005 18:00:20 PAGE 11  

 614   1      
 615   1      #else //DK3420
                USB_FIFO[ 8] = 'S';                        //Vendor Information
                USB_FIFO[ 9] = 'T';
                USB_FIFO[10] = ' ';
                USB_FIFO[11] = ' ';
                USB_FIFO[12] = ' ';
                USB_FIFO[13] = ' ';
                USB_FIFO[14] = ' ';
                USB_FIFO[15] = ' ';
              
                USB_FIFO[16] = 'D';                        //Product Identification
                USB_FIFO[17] = 'K';
                USB_FIFO[18] = '3';
                USB_FIFO[19] = '4';
                USB_FIFO[20] = '2';
                USB_FIFO[21] = '0';
                USB_FIFO[22] = ' ';
                USB_FIFO[23] = 'D';
                USB_FIFO[24] = 'e';
                USB_FIFO[25] = 'm';
                USB_FIFO[26] = 'o';
                USB_FIFO[27] = ' ';
                USB_FIFO[28] = ' ';
                USB_FIFO[29] = ' ';
                USB_FIFO[30] = ' ';
                USB_FIFO[31] = ' ';
              
                USB_FIFO[32] = '1';                        //Product Revision Level
                USB_FIFO[33] = '0';
                USB_FIFO[34] = '0';
                USB_FIFO[35] = '1';
              
                USIZE = 36;
              #endif
 649   1      
 650   1        gbBulkPipeStage = BS_CSW_PHASE;
 651   1       }
 652          
 653          void OnModeSelect6(void)
 654          /******************************************************************************
 655           Function   : void OnModeSelect6()
 656           Parameters : (void)
 657           Description: The MODE SELECT(6) command provides a means for
 658                        an initiator to specify device parameters to a RBC device.
 659                        RBC devices shall also implement the MODE SENSE(6) command.
 660           ******************************************************************************/
 661           {
 662   1        gbCSWStatus = FAIL;
 663   1        ReturnCSW();                               // return status
 664   1       }
 665          
 666          void OnModeSense6(void)
 667          /******************************************************************************
 668           Function   : void OnModeSense6()
 669           Parameters : none
 670           Description: Handler for ModeSense6 command
 671                        The MODE SENSE(6) command provides a means for a device server
 672                        to report parameters to an application client.
 673                        It is a complementary command to the MODE SELECT(6) command.
 674                        Device servers that implement the MODE SENSE(6) command
 675                        shall also implement the MODE SELECT(6) command.
C51 COMPILER V7.50   UPSD3400_USB_APP                                                      09/13/2005 18:00:20 PAGE 12  

 676           ******************************************************************************/
 677           {
 678   1        USEL  = INDIR | UMSC_IN_ENDPOINT;          //Select EP1 IN
 679   1      
 680   1        USB_FIFO[ 0] = 0x03;
 681   1        USB_FIFO[ 1] = 0x00;
 682   1        USB_FIFO[ 2] = 0x00;
 683   1        USB_FIFO[ 3] = 0x00;
 684   1      
 685   1        USIZE = 4;
 686   1      
 687   1        gbBulkPipeStage = BS_CSW_PHASE;
 688   1       }
 689          
 690          void OnModeSelect10(void)
 691          /******************************************************************************
 692           Function   : void OnModeSelect10()
 693           Parameters : (void)
 694           Description: The MODE SELECT(10) command provides a means for
 695                        the application client to specify medium,
 696                        logical unit, or peripheral device parameters to the device server.
 697                        Application clients should issue MODE SENSE(10) prior
 698                        to each MODE SELECT(10) to determine supported mode pages,
 699                        mode page lengths, and other parameters.
 700                        Device servers that implement the MODE SELECT(10) command shall
 701                        also implement the MODE SENSE(10) command.
 702           ******************************************************************************/
 703           {
 704   1        gbCSWStatus = FAIL;
 705   1        ReturnCSW();                               // return status
 706   1       }
 707          
 708          void OnModeSense10(void)
 709          /******************************************************************************
 710           Function   : void OnModeSense10()
 711           Parameters : none
 712           Description: Handler for ModeSense10 command
 713           ******************************************************************************/
 714           {
 715   1        USEL  = INDIR | UMSC_IN_ENDPOINT;          //Select EP1 IN
 716   1      
 717   1        USB_FIFO[ 0] = 0x00;
 718   1        USB_FIFO[ 1] = 0x06;
 719   1        USB_FIFO[ 2] = 0x00;
 720   1        USB_FIFO[ 3] = 0x00;
 721   1        USB_FIFO[ 4] = 0x00;
 722   1        USB_FIFO[ 5] = 0x00;
 723   1        USB_FIFO[ 6] = 0x00;
 724   1        USB_FIFO[ 7] = 0x00;
 725   1      
 726   1        USIZE = 8;
 727   1      
 728   1        gbBulkPipeStage = BS_CSW_PHASE;
 729   1       }
 730          
 731          void DoReadCapacity(void)
 732          /*--------------------------------------------------------------------
 733           Function   : void DoReadCapacity()
 734           Parameters : none
 735           Description: Handler for ReadCapacity command
 736                        This routine returns real capacity of the device-1
 737          ---------------------------------------------------------------------*/
C51 COMPILER V7.50   UPSD3400_USB_APP                                                      09/13/2005 18:00:20 PAGE 13  

 738           {
 739   1        USEL  = INDIR | UMSC_IN_ENDPOINT;          //Select EP1 IN
 740   1      
 741   1        USB_FIFO[ 0] = 0x00;                       //Last logical block
 742   1        USB_FIFO[ 1] = 0x00;
 743   1        USB_FIFO[ 2] = 0x01;
 744   1        USB_FIFO[ 3] = 0xBF;                       //7*32768B
 745   1      
 746   1        USB_FIFO[ 4] = 0x00;                       //block length
 747   1        USB_FIFO[ 5] = 0x00;
 748   1        USB_FIFO[ 6] = 0x02;                       //512B
 749   1        USB_FIFO[ 7] = 0x00;
 750   1      
 751   1        USIZE = 8;
 752   1      
 753   1        gbBulkPipeStage = BS_CSW_PHASE;
 754   1       }
 755          
 756          void DoReadFormatCapacity(void)
 757          /*--------------------------------------------------------------------
 758           Function   : void DoReadFormatCapacity()
 759           Parameters : none
 760           Description: Handler for ReadFormatCapacity command
 761          ---------------------------------------------------------------------*/
 762           {
 763   1        USEL  = INDIR | UMSC_IN_ENDPOINT;          //Select EP1 IN
 764   1      
 765   1        USB_FIFO[ 0] = 0x00;
 766   1        USB_FIFO[ 1] = 0x00;
 767   1        USB_FIFO[ 2] = 0x00;
 768   1        USB_FIFO[ 3] = 0x08;                       //capacity list length
 769   1      
 770   1      /* The following values are used during disk format */
 771   1        USB_FIFO[ 4] = 0x00;                       //block count
 772   1        USB_FIFO[ 5] = 0x00;
 773   1        USB_FIFO[ 6] = 0x01;
 774   1        USB_FIFO[ 7] = 0xBB;
 775   1        USB_FIFO[ 8] = 0x00;                       //block length
 776   1        USB_FIFO[ 9] = 0x00;
 777   1        USB_FIFO[10] = 0x02;                       //512B
 778   1        USB_FIFO[11] = 0x00;
 779   1      
 780   1        USIZE = 12;
 781   1      
 782   1        gbBulkPipeStage = BS_CSW_PHASE;
 783   1       }
 784          
 785          void CheckReceiveCBW(void)
 786          /******************************************************************************
 787            Function   : void CheckReceiveCBW()
 788            Parameters : none
 789            Description: Handle CBW package.
 790                         Command Block Wrapper (CBW) shall start on a packet boundary
 791                         and shall end as a short packet with exactly 31 (1Fh)
 792                         bytes transferred. Fields appear aligned to byte offsets equal to
 793                         a multiple of their byte size. All subsequent data and the CSW
 794                         shall start at a new packet boundary.
 795                         All CBW transfers shall be ordered with the LSB (byte 0) first
 796                         (little endian). 
 797            ******************************************************************************/
 798           {
 799   1        data unsigned char i;                      // FOR variable
C51 COMPILER V7.50   UPSD3400_USB_APP                                                      09/13/2005 18:00:20 PAGE 14  

 800   1      
 801   1        USEL     = OUTDIR | UMSC_OUT_ENDPOINT;     // Select EP OUT
 802   1      
 803   1      /* dCBWSignature:
 804   1        Signature that helps identify this data packet as a CBW. The signature field
 805   1        shall contain the value 43425355h (little endian), indicating a CBW.*/
 806   1        if((USB_FIFO[0]==0x55) && (USB_FIFO[1]==0x53) &&
 807   1        (USB_FIFO[2]==0x42) && (USB_FIFO[3]==0x43))
 808   1         {
 809   2      /* dCBWTag:
 810   2          A Command Block Tag sent by the host. The device shall echo the contents of
 811   2          this field back to the host in the dCSWTag field of the associated CSW. The
 812   2          dCSWTag positively associates a CSW with the corresponding CBW.*/
 813   2          *((uchar *)&gdwCBWTag+3) = USB_FIFO[4];  // LSB first
 814   2          *((uchar *)&gdwCBWTag+2) = USB_FIFO[5];
 815   2          *((uchar *)&gdwCBWTag+1) = USB_FIFO[6];
 816   2          *((uchar *)&gdwCBWTag+0) = USB_FIFO[7];
 817   2      /* dCBWDataTransferLength:
 818   2          The number of bytes of data that the host expects to transfer on the Bulk-In
 819   2          or Bulk-Out endpoint (as indicated by the Direction bit) during the execution
 820   2          of this command. If this field is zero, the device and the host shall transfer
 821   2          no data between the CBW and the associated CSW, and the device shall ignore
 822   2          the value of the Direction bit in bmCBWFlags.*/
 823   2          *((uchar *)&gdwCBWDataTransferLength+3) = USB_FIFO[ 8];           // LSB first
 824   2          *((uchar *)&gdwCBWDataTransferLength+2) = USB_FIFO[ 9];
 825   2          *((uchar *)&gdwCBWDataTransferLength+1) = USB_FIFO[10];
 826   2          *((uchar *)&gdwCBWDataTransferLength+0) = USB_FIFO[11];
 827   2      /* bmCBWFlags:
 828   2          The bits of this field are defined as follows:
 829   2          Bit 7 Direction - the device shall ignore this bit if the dCBWDataTransferLength
 830   2          field is zero, otherwise:
 831   2          0 = Data-Out from host to the device, 1 = Data-In from the device to the host.
 832   2          Bit 6 Obsolete. The host shall set this bit to zero.
 833   2          Bits 5..0 Reserved - the host shall set these bits to zero.*/
 834   2          gbCBWFlags = USB_FIFO[12];
 835   2      /* bCBWLUN:
 836   2          The device Logical Unit Number (LUN) to which the command block is being sent.
 837   2          For devices that support multiple LUNs, the host shall place into this field
 838   2          the LUN to which this command block is addressed. Otherwise, the host shall
 839   2          set this field to zero. */
 840   2          gbCBWLUN  = USB_FIFO[13];
 841   2      /* bCBWCBLength:
 842   2          The valid length of the CBWCB in bytes. This defines the valid length of the
 843   2          command block. The only legal values are 1 through 16 (01h through 10h). All
 844   2          other values are reserved. */
 845   2          gbCBWCBLength = USB_FIFO[14];
 846   2      
 847   2          if (gbCBWCBLength>16)
 848   2           {
 849   3            gbCBWCBLength = 16;
 850   3           }
 851   2      /* CBWCB:
 852   2          The command block to be executed by the device. The device shall interpret
 853   2          the first bCBWCBLength bytes in this field as a command block as defined by
 854   2          the command set identified by bInterfaceSubClass. If the command set supported
 855   2          by the device uses command blocks of fewer than 16 (10h) bytes in
 856   2          length, the significant bytes shall be transferred first, beginning with the
 857   2          byte at offset 15 (Fh). The device shall ignore the content of the CBWCB field
 858   2          past the byte at offset (15 + bCBWCBLength - 1).
 859   2          */
 860   2          for(i = 0; i<gbCBWCBLength; i++)
 861   2           {
C51 COMPILER V7.50   UPSD3400_USB_APP                                                      09/13/2005 18:00:20 PAGE 15  

 862   3            gbCBWCB[i] = USB_FIFO[15+i];
 863   3           }
 864   2      
 865   2          UCON |= EPFIFO_BSY;
 866   2      
 867   2      
 868   2      
 869   2          gbCSWStatus     = PASS;                  // default CSW Status
 870   2          gbBulkPipeStage = BS_DATA_PHASE;
 871   2      
 872   2          if (gbCBWCBLength>0)
 873   2           {
 874   3      /* Now decode the CBWCB; the command block to be executed by the device. */
 875   3            switch (gbCBWCB[0])
 876   3             {
 877   4              case OP_READ10:
 878   4               {
 879   5                DoReadWrite();
 880   5                break;
 881   5               }
 882   4      
 883   4              case OP_WRITE10:
 884   4               {
 885   5                DoReadWrite();
 886   5                break;
 887   5               }
 888   4      
 889   4              case OP_TEST_UNIT_READY:
 890   4               {
 891   5      /* This is called by WinXP typ. every 1 second to check the unit */
 892   5      /* default: all OK */
 893   5                ReturnCSW();                       // return status
 894   5                break;
 895   5               }
 896   4      
 897   4              case OP_REQUEST_SENSE:
 898   4               {
 899   5                OnRequestSense();
 900   5                break;
 901   5               }
 902   4      
 903   4              case OP_INQUIRY:
 904   4               {
 905   5                OnInquiry();
 906   5                break;
 907   5               }
 908   4      
 909   4              case OP_MODE_SENSE10:
 910   4               {
 911   5                OnModeSense10();

⌨️ 快捷键说明

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