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

📄 usb_lib.c

📁 使用ETOM芯片进行无线收发
💻 C
📖 第 1 页 / 共 4 页
字号:
/////////////////////////////////////////////////////////////////  USB Library main file Version 2.0//  You can revise the sub function in the prjName.c//  Revise this file may cause usb error!///////////////////////////////////////////////////////////////                                                                                                                                                                                                                                                                                                                           void UsbIntPre() using USBBANK{#if _USB_AUTO_SET_BANK   M_BANK(USB_BANK);#endif #if _USB_AUTO_STORE_IAP0   STACK_IAP0 = IAP0;#endif  }////////////////////////////////////////////////////////////////// fun: UsbInitial// Initial usb register.// If you want to add code when usb initial,revise AddUsbInitialWorkSub(),// Call Function: AddUsbInitialWorkSub();///////////////////////////////////////////////////////////////// UsbInital() revised by USB_INITALvoid UsbInitial() using USBBANK{    //     IAPADR = 0x05;    // enable usb function    M_BS6(PRIE);    //    M_BANK(USB_BANK);    //hub endpoint transmit: 0: not transmit yet  1:transmit ok,     M_BC3(HUB_STATUS);	USB_STATUS = 0;	STATUS_BUF = 0;	A_INTERFACE = 0;// enable embedd function interrupt    EPINTE = 0x3f;	M_NOP;//_ENABLE USB Bus Reset Event 	STAINTE = 0x01;	M_NOP;//Hub initilize: interrupt INT__ENABLE	HINTE = 0xCF;	M_NOP;//Address clear  	ADDRESS_BUFh = 0;	ADDRESS_BUFf = 0;			FAR = 0xFF;	M_NOP;	HAR = 0xFF;	M_NOP;	//USB SPEED setting#if _USB_FULL_SPEED    M_BS7(GCNTR);#else    M_BC7(GCNTR);#endif            M_NOP;    //Start transmition: plug-in        M_BS1(GCNTR);            M_NOP;        //. call macro  _ADD_USB_INITIAL_WORK_SUB          AddUsbInitialWorkSub();        return;  }/////////////////////////////////////////////////////////////. RST_ISR interrupt function,interrupt vector 0x98//  run when USB Bus Reset Event Detect//  If you want to add code when usb reset,revise AddUsbBusResetSub(),//  Call Function: AddUsbBusResetSub();///////////////////////////////////////////////////////////void Int_RstInte() interrupt INT_RSTINTE using USBBANK{#if(_USB_AUTO_SET_BANK ||_USB_AUTO_STORE_IAP0)   UsbIntPre();#endif   // software reset usb device    M_BS0(GCNTR);   M_NOP;   // clear usb bus reset event detect//**Remote-wakeup disable,power switch disable         //HGSR = 0;   _asm     MOV A,#0x00     MOV _HGSR,A   _endasm;     // set Hub address//   HAR = 0x00;   M_NOP;      // usb device address   HAR = 0;   M_NOP;   FAR = 0;   M_NOP;      STAINTR = 0xFE;//#0b11111110   M_NOP;     nAddrBuf = 0;   HEP1_CNT = 0;   USB_STATUS = 0;   STATUS_BUF = 0;   #if !_USB_HUB   {      HAR = 127;      M_NOP;      M_BS5(HGSR);      M_NOP;      HPCONR = 145;//#0b10010001      M_NOP;      M_BC0(HPSCR1);                  M_NOP;      M_BS5(GCNTR);      M_NOP;      HPCONR = 137; //#0b10001001      M_NOP;      M_BC4(HPSCR1);         M_NOP;   }#endif      //. call macro _ADD_USB_BUS_RESET_SUB   AddUsbBusResetSub(); Back_To_Mloop: #if(_USB_AUTO_STORE_IAP0)   {      IAP0=STACK_IAP0;      M_NOP;           }#endif   #if(_USB_DIS_ANO_INT)      M_ENI;#endif         return;  }/////////////////////////////////////////////////////////////. RX0_ISR interrupt function,interrupt vector 0x88//  run when USB EP0 RX Event//  If you want to add code when USB EP0 RX Event occur ,revise AddUsbSetReportSub(),//  Call Function:AddUsbSetReportSub();/////////////////////////////////////////////////////////////RX0_ISR 2004/01/27 Create by Brooklinvoid Int_Int0Rxe(void) interrupt INT_INT0RXE using USBBANK{	#if(_USB_AUTO_SET_BANK ||_USB_AUTO_STORE_IAP0)    UsbIntPre();#endif        if(M_ISBS0(EP0RXTR))    // JBS	EP0RXTR,OUT,f_out_package    {//. f_out_package        EP0RXTR = 0xFE; //#0b11111110        M_NOP;        //. JBC 	FC_STATUS,DATA_OUT,next_f_inout   					        if(M_ISBC2(FC_STATUS))            goto Next_F_Inout;        else        {            M_BC2(FC_STATUS);               //macro  _ADD_USB_SET_REPORT_SUB            AddUsbSetReportSub();                          nwLength = 0;                 //wLengthL = 0;            //wLengthH = 0;                        //. next_f_inout        }    }    //. f_setup_package    else    {        if(M_ISBS1(EP0RXTR))        {            EP0RXTR = 0xFD; //#0b11111101                }        else        {            EP0RXTR = 0xFB; //#0b11111011        }        _asm           NOP          MOV A,#_bmRequestType          MOV _IAP0,A          NOP        _endasm;                while(M_ISBC3(IAP0))        {           IAC0 = EP0RXDAR;        }// replace wLengthH and wLengthL by nwLength //        if(!wLengthH && !wLengthL)        if(!nwLength)        {           EP0TXCTR = 0;           M_NOP;        }                    M_BC1(USB_STATUS);        M_BC0(USB_STATUS);        M_BC2(USB_STATUS);        M_BC5(USB_STATUS);        //        _asm//          MOV A,#_bmRequestType//        _endasm;        StageOne();                 if(M_ISBS0(USB_STATUS))         {//.f_stall           M_BS1(EP0RXCSR);           M_NOP;           M_BS1(EP0TXCSR);            M_NOP;           goto Back_To_Mloop;               }        }   Next_F_Inout:      M_BC1(EP0RXCSR);   M_NOP;   M_BC1(EP0TXCSR);   M_NOP;   M_BS0(EP0RXCSR);   M_NOP;   M_BS0(EP0TXCSR);   // BACK_TO_MLOOPBack_To_Mloop: #if(_USB_AUTO_STORE_IAP0)   {      IAP0=STACK_IAP0;      M_NOP;           }#endif   #if(_USB_DIS_ANO_INT)      M_ENI;#endif   return;        }/////////////////////////////////////////////////////////////. IN0_ISR interrupt function,interrupt vector 0x88//  run when EP0 USB IN Token Event occur//  //  Call Function: ///////////////////////////////////////////////////////////void Int_Int0Ine(void) interrupt INT_INT0INE using USBBANK{	#if(_USB_AUTO_SET_BANK ||_USB_AUTO_STORE_IAP0)   UsbIntPre();#endif       //Clear interrupt flag      EPINTR = 251;//#0b11111011   M_NOP;#if(_USB_AUTO_STORE_IAP0)   {      IAP0=STACK_IAP0;      M_NOP;           }#endif   #if(_USB_DIS_ANO_INT)      M_ENI;#endif   return;  }//////////////////////////////////////////////////////////////////////////////////////////. TX0_ISR interrupt function,interrupt vector 0x88//  run when USB EP0 TX Event//  If you want to add code when USB EP0 TX Event occur ,revise AddUsbGetReportExpSub(),//  Call Function:AddUsbGetReportExpSub();////////////////////////////////////////////////////////////////////////////////////////void Int_Int0Txe(void) interrupt INT_INT0TXE using USBBANK{#if(_USB_AUTO_SET_BANK ||_USB_AUTO_STORE_IAP0)   UsbIntPre();#endif //Clear interrupt INT_flag      EPINTR = 253;//#0b11111101   M_NOP;      FAR = ADDRESS_BUFf;   M_NOP;   if(!TBLL)   {//. exit_tx01      EP0TXCTR=0;      M_NOP;   }   else if(wLengthH)   {//. TX0_ISR1      if(M_ISBS5(FC_STATUS))      {//. USB_GET_REPORT_SUB       //. call macro  _ADD_USB_GET_REPORT_EXP_SUB         AddUsbGetReportExpSub();      }      else      {         nTable = nRomAdr;         //HTBL = ROMADRH;         //LTBL = ROMADRL;         M_NOP;         fTransmitTable();      }     } Next_F_Inout:      M_BC1(EP0RXCSR);   M_NOP;   M_BC1(EP0TXCSR);   M_NOP;   M_BS0(EP0RXCSR);   M_NOP;   M_BS0(EP0TXCSR); }//////////////////////////////////////////////////////////////////////////////////////////. EP1_ISR interrupt function,interrupt vector 0x90//  run when EP1 Interrupt occur//  If you want to add code when EP1 Interrupt occur ,revise AddUsbEp1Sub(),//  Call Function:AddUsbEp1Sub();////////////////////////////////////////////////////////////////////////////////////////void Int_Int1e() interrupt INT_INT1E using USBBANK{   //UsbIntPre();   //M_BC1(PORTB);   EPINTR = 247; // #0b11110111   M_NOP;   //. call macro _ADD_USB_EP1_SUB   AddUsbEp1Sub(); Back_To_Mloop: #if(_USB_AUTO_STORE_IAP0)   {      IAP0=STACK_IAP0;      M_NOP;           }#endif   #if(_USB_DIS_ANO_INT)      M_ENI;      #endif         return;  }//////////////////////////////////////////////////////////////////////////////////////////. EP2_ISR interrupt function,interrupt vector 0x90//  run when EP2 Interrupt occur//  If you want to add code when EP2 Interrupt occur ,revise AddUsbEp2Sub(),//  Call Function:AddUsbEp2Sub();////////////////////////////////////////////////////////////////////////////////////////void Int_Int2e() interrupt INT_INT2E using USBBANK{   UsbIntPre();   EPINTR = 239; // #0b11101111   M_NOP;   //. call macro _ADD_USB_EP2_SUB   AddUsbEp2Sub(); Back_To_Mloop: #if(_USB_AUTO_STORE_IAP0)   {      IAP0=STACK_IAP0;      M_NOP;           }#endif   #if(_USB_DIS_ANO_INT)      M_ENI;#endif   return; }//////////////////////////////////////////////////////////////////////////////////////////. EP3_ISR interrupt function,interrupt vector 0x90//  run when EP3 Interrupt occur//  If you want to add code when EP3 Interrupt occur ,revise AddUsbEp3Sub(),//  Call Function:AddUsbEp3Sub();////////////////////////////////////////////////////////////////////////////////////////void Int_Int3e() interrupt INT_INT3E using USBBANK{   UsbIntPre();   EPINTR = 223; // #0b11011111   M_NOP;   //. call macro _ADD_USB_EP3_SUB   AddUsbEp3Sub();Back_To_Mloop: #if(_USB_AUTO_STORE_IAP0)   {      IAP0=STACK_IAP0;      M_NOP;           }#endif   #if(_USB_DIS_ANO_INT)      M_ENI;#endif   return; }//////////////////////////////////////////////////////////////////////////////////////////. IDLE_ISR interrupt function,interrupt vector 0x98//  run when USB Bus Suspend Event Detect//  If you want to add code when USB Bus Suspend Event Detect//  ,revise AddUsbIdleIntSub().//  Call Function:AddUsbIdleIntSub();////////////////////////////////////////////////////////////////////////////////////////void Int_IdleInte() interrupt INT_IDLEINTE using USBBANK{#if(_USB_AUTO_SET_BANK ||_USB_AUTO_STORE_IAP0)   UsbIntPre();#endif   STAINTE = 0x0F;   M_NOP;   STAINTR = 253; //#0b11111101   M_NOP;     M_BS2(GCNTR);   M_NOP;      //. call macro _ADD_USB_IDLE_INT_SUB   AddUsbIdleIntSub();    Back_To_Mloop: #if(_USB_AUTO_STORE_IAP0)   {      IAP0=STACK_IAP0;      M_NOP;           }#endif   #if(_USB_DIS_ANO_INT)      M_ENI;#endif   return;    }//////////////////////////////////////////////////////////////////////////////////////////. RESUME_WAKEUP_ISR interrupt function,interrupt vector 0x98//  call when Function Remote Wake-Up Interrupt//  Call Function:AddUsbWakeup();////////////////////////////////////////////////////////////////////////////////////////void Int_FrwpInte() interrupt INT_FRWPINTE using USBBANK{#if(_USB_AUTO_SET_BANK ||_USB_AUTO_STORE_IAP0)   UsbIntPre();#endif   if(M_ISBC2(STAINTR))   {      STAINTE = 7;      M_NOP;   }   else   {      STAINTE = 0x0B;      M_NOP;      }   //. call macro _ADD_USB_WAKEUP_INT_SUB      AddUsbWakeup();    Back_To_Mloop: #if(_USB_AUTO_STORE_IAP0)   {      IAP0=STACK_IAP0;      M_NOP;           }#endif   #if(_USB_DIS_ANO_INT)      M_ENI;#endif   return;    }//////////////////////////////////////////////////////////////////////////////////////////. RESUME_WAKEUP_ISR interrupt function,interrupt vector 0x98//  call when Hub EP0 USB RX Event Detect//  Call Function:////////////////////////////////////////////////////////////////////////////////////////#if _USB_HUBvoid Int_Hint0Rxe() interrupt INT_HINT0RXE using USBBANK{  #if(_USB_AUTO_SET_BANK ||_USB_AUTO_STORE_IAP0)   UsbIntPre();  #endif   if(M_ISBC0(HEP0RXTR))   {//. h_setup_package      if(M_ISBS1(HEP0RXTR))         HEP0RXTR = 253;// #0b11111101      else         HEP0RXTR = 251;// #0b11111011      M_NOP;            _asm        MOV A,#_HbmRequestType        MOV _IAP0,A        NOP      _endasm;            while(M_ISBC3(IAP0))      {//. hReceiveCommand         IAC0 = HEP0RXDAR;      

⌨️ 快捷键说明

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