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

📄 upsd3400_upsd_usb.lst

📁 uPSD34xx Disk driver
💻 LST
📖 第 1 页 / 共 3 页
字号:
 604          //     {
 605          //      TransmitZeroLengthEP0();
 606          //     }
 607          //    usbState = US_ADDRESSED;
 608          //   }
 609          //  else
 610          //  if (setupPacket.wValue.lo == 1)            // corresponds to configuration value
 611           //  {
C51 COMPILER V7.50   UPSD3400_UPSD_USB                                                     09/13/2005 18:00:20 PAGE 11  

 612           //   if (usbState != US_CONFIGURED)
 613            //   {
 614          // Bulk transactions are initialized to DATA0
 615          // when the endpoint is configured by an appropriate control transfer.
 616          // The host will also start the first bulk transaction with DATA0.
 617          // This recovery after STALL sets the data toggle bit to DATA0 for the endpoint
 618          // on both the host and the device.
 619          /*
 620          
 621                USEL   = OUTDIR | SELEP3;              //Select EP3 OUT
 622                UCON   = ENABLE_FIFO | EPFIFO_BSY;
 623                USIZE  = 0;
 624          
 625                USEL   = INDIR | SELEP1;               //Select EP1 IN
 626                UCON   = ENABLE_FIFO;
 627          
 628                UIE1  |= IN1IE;                        //Enable EP1 IN INT
 629                UIE2  |= OUT3IE;                       //Enable EP3 OUT INT
 630          
 631          
 632          //      USEL   = OUTDIR | SELEP3;            //Select EP0 OUT
 633          //      USIZE  = 0;                          //flush FIFO
 634          
 635                UIF1  &= ~IN1F;                        //clear INT Flag
 636                UIF2  &= ~OUT3F;                       //clear INT Flag
 637                */
 638           //     usbState  = US_CONFIGURED;
 639           //    }
 640           //   confignum = setupPacket.wValue.lo;
 641           //   TransmitZeroLengthEP0();
 642          //    OnDeviceConfigured();
 643           //  }
 644          //  else
 645          //   {
 646          //    STALL_EP0();                             // stall EP0
 647          //   }
 648          //}
 649          
 650          
 651          
 652          
 653          
 654          
 655          void OnGetInterface()
 656          /******************************************************************************
 657           Function   : void OnGetInterface()
 658           Parameters : none
 659           Description: Handler for GET_INTERFACE request
 660           ******************************************************************************/
 661           {
 662   1      
 663   1        USEL  = INDIR | SELEP0;                    //select EP0 OUT
 664   1        UCON |= TOGGLE;                            //Expect DATA1
 665   1        USIZE = 0;                                 //zero length data
 666   1       }
 667          
 668          
 669          
 670          
 671          
 672          
 673          
C51 COMPILER V7.50   UPSD3400_UPSD_USB                                                     09/13/2005 18:00:20 PAGE 12  

 674          
 675          void OnSetInterface()
 676          /******************************************************************************
 677           Function   : void OnSetInterface()
 678           Parameters : none
 679           Description: Handler for SET_INTERFACE() requests.
 680           ******************************************************************************/
 681           {
 682   1        if (setupPacket.wValue.lo == 0)
 683   1         {
 684   2          TransmitZeroLengthEP0();                 //zero length data
 685   2         }
 686   1        else
 687   1         {
 688   2          STALL_EP0();
 689   2         }
 690   1       }
 691          
 692          
 693          
 694          
 695          
 696          
 697          
 698          void UsbInitialize()
 699          /******************************************************************************
 700           Function   : void UsbInitialize()
 701           Parameters : none
 702           Description: USB driver module initialization routine.
 703           ******************************************************************************/
 704           {
 705   1        data unsigned int count;
 706   1      
 707   1        UCTL &= ~VISIBLE;                          // Disable USB FIFO in RAM area
 708   1      
 709   1        CCON1  &= ~0x07;            //CPUCLK prescaler = 1; only for silicon revision #0
 710   1      
 711   1      /*                                             //Set PLL clk
 712   1        CCON0 |= 0xE0;                             //PLL enable
 713   1        CCON1 = 0x68;                              //40MHz, PLLM=22, PLLD=8
 714   1      
 715   1        CCON0 |= 0xE0;                             //PLL enable
 716   1        CCON1  = 0xE9;                             //33MHz, PLLM=30, PLLD=9
 717   1      
 718   1        CCON0 |= 0x70;                             //PLL enable
 719   1        CCON1  = 0xE3;                             //30MHz, PLLM=14, PLLD=3
 720   1      
 721   1        CCON0 |= 0xE0;                             //PLL enable
 722   1        CCON1  = 0x23;                             //24MHz, PLLM=18, PLLD=3
 723   1      
 724   1        CCON0 |= 0xE0;                             //PLL enable
 725   1        CCON1  = 0x63;                             //20MHz, PLLM=22, PLLD=3
 726   1      
 727   1        CCON0  |= 0xE0;                            //PLL enable
 728   1        CCON1   = 0xC3;                            //16MHz, PLLM=28, PLLD=3
 729   1      
 730   1        CCON0  |= 0xE0;                            //PLL enable
 731   1        CCON1   = 0xE2;                            //12MHz, PLLM=18, PLLD=2
 732   1      
 733   1        CCON0  |= 0xE0;                            //PLL enable
 734   1        CCON1   = 0xE0;                            //6MHz, PLLM=18, PLLD=0
 735   1      
C51 COMPILER V7.50   UPSD3400_UPSD_USB                                                     09/13/2005 18:00:20 PAGE 13  

 736   1        CCON0  |= 0xE0;                            //PLL enable
 737   1        CCON1   = 0xEF;                            //3MHz, PLLM=18, PLLD=-1
 738   1        */
 739   1      
 740   1      #ifdef DK3400
 741   1        CCON0 |= 0xE0;                             //PLL enable
 742   1        CCON1  = 0x68;                             //40MHz, PLLM=22, PLLD=8
 743   1      #else //DK3420)
                CCON0 |= 0xE0;                             //PLL enable
                CCON1  = 0x23;                             //24MHz, PLLM=18, PLLD=3
              #endif
 747   1      
 748   1        for (count=0; count<1000; count++)         // (wait 200us min.)
 749   1         {
 750   2          ACC = 0;                                 //now wait for PLL output is stabilized
 751   2         }
 752   1      
 753   1        IP     = 0;                                //USB interrupt has the highest priority!!!
 754   1        IPA    = 1;                                
 755   1        IEA   |= 0x01;                             // Enable USB Interrupt
 756   1        EA     = 1;
 757   1      
 758   1        UBASEH = USB_BASE_ADDR >> 8;               // Set USB FIFO base address
 759   1        UBASEL = USB_BASE_ADDR;                    // Set USB FIFO base address
 760   1        UCTL  |= VISIBLE;                          // Enable USB FIFO in RAM area
 761   1      
 762   1        remotewakeupen = 0x01;
 763   1      
 764   1        OnUsbReset();
 765   1      
 766   1        UCTL &= ~VISIBLE;                          // Disable USB FIFO in RAM area
 767   1       }
 768          
 769          
 770          
 771          
 772          
 773          
 774          
 775          
 776          
 777          
 778          
 779          
 780          
 781          
 782          
 783          void ReadSetupPacket(void)
 784          /******************************************************************************
 785           Function   : ReadSetupPacket()
 786           Parameters : none
 787           Description: Reads a setup packet from USB Setup Command Register.
 788           ******************************************************************************/
 789           {
 790   1        data unsigned char i;
 791   1        unsigned char* p = (unsigned char*) &setupPacket;
 792   1      
 793   1        USTA &= ~SETUP;                            // Clear setup bit in USTA
 794   1      
 795   1        for (i=0; i<8; i++)
 796   1         {
 797   2          USCI = i;
C51 COMPILER V7.50   UPSD3400_UPSD_USB                                                     09/13/2005 18:00:20 PAGE 14  

 798   2          *p++ = USCV;
 799   2         }
 800   1      
 801   1        return;
 802   1       }
 803          
 804          
 805          
 806          
 807          
 808          
 809          
 810          
 811          void OnSetupPacket()
 812          /******************************************************************************
 813           Function   : void OnSetupPacket()
 814           Parameters : none
 815           Description: Handler for SETUP packets received on EP0.
 816                        Handle standard request and Mass Storage class request.
 817           ******************************************************************************/
 818           {
 819   1        if ((setupPacket.bmRequestType & 0x60) == 0)               //Standard request...
 820   1         {
 821   2          switch (setupPacket.bRequest)            // Standard request
 822   2           {
 823   3            case GET_STATUS:        OnGetStatus();        break;
 824   3            case CLEAR_FEATURE:     OnClearFeature();     break;
 825   3            case SET_FEATURE:       OnSetFeature();       break;
 826   3            case SET_ADDRESS:       OnSetAddress();       break;
 827   3            case GET_DESCRIPTOR:    OnGetDescriptor();    break;
 828   3            case SET_DESCRIPTOR:    OnSetDescriptor();    break;
 829   3            case GET_CONFIGURATION: OnGetConfiguration(); break;
 830   3            case SET_CONFIGURATION: OnSetConfiguration(); break;
 831   3            case GET_INTERFACE:     OnGetInterface();     break;
 832   3            case SET_INTERFACE:     OnSetInterface();     break;
 833   3            default:
 834   3            break;
 835   3           }
 836   2         }
 837   1      
 838   1      /* Class request specific commands */
 839   1        else
 840   1        if (setupPacket.bmRequestType & 0x20)
 841   1         {
 842   2          if ((setupPacket.bmRequestType == CLASS_INTERFACE_TO_HOST)
 843   2          && (setupPacket.bRequest == 0xFE))       //Get Max LUN
 844   2           {
 845   3      /*
 846   3            Get Max LUN (class-specific request)
 847   3            The device may implement several logical units that share common device characteristics.
 848   3            The host uses bCBWLUN to designate which logical unit of the device is the
 849   3            destination of the CBW. The Get Max LUN device request is used to determine
 850   3            the number of logical units supported by the device.
 851   3            Logical Unit Numbers on the device shall be numbered contiguously starting
 852   3            from LUN 0 to a maximum LUN of 15 (Fh).
 853   3            The device shall return one byte of data that contains the maximum LUN supported
 854   3            by the device.
 855   3            We have no LUN is associated with the device, the value returned is 0.
 856   3            */
 857   3            USEL        = INDIR | SELEP0;          //select EP0 OUT
 858   3            UCON       |= TOGGLE;                  //Expect DATA1
 859   3            USB_FIFO[0] = 0x00;                    //no LUN associated with the device
C51 COMPILER V7.50   UPSD3400_UPSD_USB                                                     09/13/2005 18:00:20 PAGE 15  

 860   3            USIZE       = 1;
 861   3           }
 862   2          else
 863   2          if ((setupPacket.bmRequestType == CLASS_INTERFACE_TO_DEVICE)
 864   2          && (setupPacket.bRequest == 0xFF))       //Bulk-Only Mass Storage Reset
 865   2           {
 866   3      /*
 867   3            Bulk-Only Mass Storage Reset (class-specific request)
 868   3            This request is used to reset the mass storage device and its associated
 869   3            interface.This class-specific request shall ready the device for the next
 870   3            CBW from the host.The host shall send this request via the default pipe to
 871   3            the device. The device shall preserve the value of its bulk
 872   3            data toggle bits and endpoint STALL conditions despite the Bulk-Only Mass
 873   3            Storage Reset.
 874   3            The device shall NAK the status stage of the device request until the Bulk-Only
 875   3            Mass Storage Reset is complete.
 876   3            */
 877   3           }
 878   2         }
 879   1        else
 880   1         {
 881   2          STALL_EP0();                // It's not a request we handle, so stall endpoint
 882   2         }
 883   1      
 884   1        return;
 885   1       }
 886          
 887          
 888          /* *************************************************************************
 889            ***                                                                      ***
 890            **                         *** End of File ***                            **
 891            ***                                                                      ***
 892             *************************************************************************  */


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    905    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     18       5
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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