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

📄 usbhw.lst

📁 针对飞利浦LPC214x的虚拟串口程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
  288          */
  289          
  290          void USB_DisableEP (BYTE EPNum) {
  291   1          WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(EP_STAT_DA));
  292   1      }
  293          
  294          
  295          /*
  296          *  Reset USB Endpoint
  297          *    Parameters:      EPNum: Endpoint Number
  298          *                       EPNum.0..3: Address
  299          *                       EPNum.7:    Dir
  300          *    Return Value:    None
  301          */
  302          
  303          void USB_ResetEP (BYTE EPNum) {
  304   1          WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(0));
  305   1      }
  306          
  307          
  308          /*
  309          *  Set Stall for USB Endpoint
  310          *    Parameters:      EPNum: Endpoint Number
  311          *                       EPNum.0..3: Address
  312          *                       EPNum.7:    Dir
  313          *    Return Value:    None
  314          */
  315          
  316          void USB_SetStallEP (BYTE EPNum) {
  317   1          WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(EP_STAT_ST));
  318   1      }
  319          
  320          
  321          /*
  322          *  Clear Stall for USB Endpoint
ARM COMPILER V2.53,  usbhw                                                                 09/06/07  15:42:23  PAGE 6   

  323          *    Parameters:      EPNum: Endpoint Number
  324          *                       EPNum.0..3: Address
  325          *                       EPNum.7:    Dir
  326          *    Return Value:    None
  327          */
  328          
  329          void USB_ClrStallEP (BYTE EPNum) {
  330   1          WrCmdDat(CMD_SET_EP_STAT(EPAdr(EPNum)), DAT_WR_BYTE(0));
  331   1      }
  332          
  333          
  334          /*
  335          *  Read USB Endpoint Data
  336          *    Parameters:      EPNum: Endpoint Number
  337          *                       EPNum.0..3: Address
  338          *                       EPNum.7:    Dir
  339          *                     pData: Pointer to Data Buffer
  340          *    Return Value:    Number of bytes read
  341          */
  342          
  343          DWORD USB_ReadEP (BYTE EPNum, BYTE *pData) {
  344   1          DWORD cnt, n;
  345   1          
  346   1          USB_CTRL = ((EPNum & 0x0F) << 2) | CTRL_RD_EN;
  347   1          
  348   1          do {
  349   2              cnt = RX_PLENGTH;
  350   2          } while ((cnt & PKT_RDY) == 0);
  351   1          cnt &= PKT_LNGTH_MASK;
  352   1          
  353   1          for (n = 0; n < (cnt + 3) / 4; n++) {
  354   2              *((__packed DWORD *)pData) = RX_DATA;
  355   2              pData += 4;
  356   2          }
  357   1          
  358   1          USB_CTRL = 0;
  359   1          
  360   1          WrCmd(CMD_SEL_EP(EPAdr(EPNum)));
  361   1          WrCmd(CMD_CLR_BUF);
  362   1          
  363   1          return (cnt);
  364   1      }
  365          
  366          
  367          /*
  368          *  Write USB Endpoint Data
  369          *    Parameters:      EPNum: Endpoint Number
  370          *                       EPNum.0..3: Address
  371          *                       EPNum.7:    Dir
  372          *                     pData: Pointer to Data Buffer
  373          *                     cnt:   Number of bytes to write
  374          *    Return Value:    Number of bytes written
  375          */
  376          
  377          DWORD USB_WriteEP (BYTE EPNum, BYTE *pData, DWORD cnt) {
  378   1          DWORD n;
  379   1          
  380   1          USB_CTRL = ((EPNum & 0x0F) << 2) | CTRL_WR_EN;
  381   1          
  382   1          TX_PLENGTH = cnt;
  383   1          
  384   1          for (n = 0; n < (cnt + 3) / 4; n++) {
  385   2              TX_DATA = *((__packed DWORD *)pData);
  386   2              pData += 4;
  387   2          }
  388   1          
ARM COMPILER V2.53,  usbhw                                                                 09/06/07  15:42:23  PAGE 7   

  389   1          USB_CTRL = 0;
  390   1          
  391   1          WrCmd(CMD_SEL_EP(EPAdr(EPNum)));
  392   1          WrCmd(CMD_VALID_BUF);
  393   1          
  394   1          return (cnt);
  395   1      }
  396          
  397          
  398          /*
  399          *  USB Interrupt Service Routine
  400          */
  401          
  402          void USB_ISR (void) __irq {
  403   1          DWORD disr, eisr, val, n, m;
  404   1          
  405   1          disr = DEV_INT_STAT;                      /* Device Interrupt Status */
  406   1          
  407   1          // Device Status Interrupt (Reset, Suspend/Resume, Connect change)
  408   1          if (disr & DEV_STAT_INT) {
  409   2              WrCmd(CMD_GET_DEV_STAT);
  410   2              val = RdCmdDat(DAT_GET_DEV_STAT);       /* Device Status */
  411   2              if (val & DEV_RST) {                    /* Reset */
  412   3                  USB_Reset();
  413   3      #if   USB_RESET_EVENT
  414   3                  USB_Reset_Event();
  415   3      #endif
  416   3                  goto isr_end;
  417   3              }
  418   2              if (val & DEV_SUS_CH) {                 /* Suspend/Resume */
  419   3                  if (val & DEV_SUS) {                  /* Suspend */
  420   4                      USB_Suspend();
  421   4      #if     USB_SUSPEND_EVENT
                               USB_Suspend_Event();
               #endif
  424   4                  } else {                              /* Resume */
  425   4                      USB_Resume();
  426   4      #if     USB_RESUME_EVENT
                               USB_Resume_Event();
               #endif
  429   4                  }
  430   3                  goto isr_end;
  431   3              }
  432   2              if (val & DEV_CON_CH) {                 /* Connect change */
  433   3      #if   USB_POWER_EVENT
                           USB_Power_Event(val & DEV_CON);
               #endif
  436   3                  goto isr_end;
  437   3              }
  438   2          }
  439   1          
  440   1      #if USB_SOF_EVENT
                   // Start of Frame Interrupt
                   if (disr & FRAME_INT) {
                       WrCmd(CMD_RD_FRAME);
                       val = RdCmdDat(DAT_RD_FRAME);
                       val = val | (RdCmdDat(DAT_RD_FRAME) << 8);
                       USB_SOF_Event(val);
                   }
               #endif
  449   1          
  450   1      #if USB_ERROR_EVENT
                   // Error Interrupt
                   if (disr & ERR_INT) {
                       WrCmd(CMD_RD_ERR_STAT);
                       val = RdCmdDat(DAT_RD_ERR_STAT);
ARM COMPILER V2.53,  usbhw                                                                 09/06/07  15:42:23  PAGE 8   

                       if        (val & 0x01) {
                           val = USB_ERR_PID;
                       } else if (val & 0x02) {
                           val = 0x100;  // Unexpected Error
                       } else if (val & 0x04) {
                           val = USB_ERR_CRC;
                       } else if (val & 0x08) {
                           val = USB_ERR_TIMEOUT;
                       } else if (val & 0x10) {
                           val = USB_ERR_EOP;
                       } else if (val & 0x20) {
                           val = 0x101;  // Buffer Overrun
                       } else if (val & 0x40) {
                           val = USB_ERR_BIT_STUFF;
                       } else if (val & 0x80) {
                           val = USB_ERR_DATA_TOGGLE;
                       }
                       USB_Error_Event(val);
                   }
               #endif
  475   1          
  476   1          // Ednpoint's Slow Interrupt
  477   1          if (disr & EP_SLOW_INT) {
  478   2              
  479   2              while ( eisr = EP_INT_STAT ) {           /* Endpoint Interrupt Status */
  480   3                  // Check All Endpoints
  481   3                  for (n = 0; n < USB_EP_NUM; n++) {
  482   4                      if (eisr & (1 << n)) {
  483   5                          m = n >> 1;
  484   5                          
  485   5                          EP_INT_CLR = 1 << n;
  486   5                          while ((DEV_INT_STAT & CDFULL_INT) == 0);
  487   5                          val = CMD_DATA;
  488   5                          DEV_INT_CLR = CDFULL_INT;
  489   5                          
  490   5                          if ((n & 1) == 0) {
  491   6                              // OUT Endpoint
  492   6                              if (n == 0) {                     /* Control OUT Endpoint */
  493   7                                  if (val & EP_SEL_STP) {         /* Setup Packet */
  494   8                                      if (USB_P_EP[0]) {
  495   9                                          USB_P_EP[0](USB_EVT_SETUP);
  496   9                                          continue;
  497   9                                      }
  498   8                                  }
  499   7                              }
  500   6                              if (USB_P_EP[m]) {
  501   7                                  USB_P_EP[m](USB_EVT_OUT);
  502   7                              }
  503   6                          } else {
  504   6                              // IN Endpoint
  505   6                              if (USB_P_EP[m]) {
  506   7                                  USB_P_EP[m](USB_EVT_IN);
  507   7                              }
  508   6                          }
  509   5                      }
  510   4                  }
  511   3              }
  512   2          }
  513   1          
  514   1      isr_end:
  515   1          DEV_INT_CLR = disr;
  516   1          VICVectAddr = 0;                          /* Acknowledge Interrupt */
  517   1      }
ARM COMPILER V2.53,  usbhw                                                                 09/06/07  15:42:23  PAGE 9   

ASSEMBLY LISTING OF GENERATED OBJECT CODE



*** EXTERNALS:
 EXTERN DATA (USB_DeviceStatus)
 EXTERN CODE16 (USB_Reset_Event?T)
 EXTERN DATA (USB_P_EP)
 EXTERN CODE32 (USB_Reset_Event?A)



*** PUBLICS:
 PUBLIC         USB_Init?T
 PUBLIC         USB_Connect?T
 PUBLIC         USB_Reset?T
 PUBLIC         USB_Reset?A
 PUBLIC         USB_Suspend?T
 PUBLIC         USB_Suspend?A
 PUBLIC         USB_Resume?T
 PUBLIC         USB_Resume?A
 PUBLIC         USB_WakeUp?T
 PUBLIC         USB_WakeUpCfg?T
 PUBLIC         USB_SetAddress?T
 PUBLIC         USB_Configure?T
 PUBLIC         USB_ConfigEP?T
 PUBLIC         USB_DirCtrlEP?T
 PUBLIC         USB_EnableEP?T
 PUBLIC         USB_DisableEP?T
 PUBLIC         USB_ResetEP?T
 PUBLIC         USB_SetStallEP?T
 PUBLIC         USB_ClrStallEP?T
 PUBLIC         USB_ReadEP?T
 PUBLIC         USB_WriteEP?T
 PUBLIC         USB_ISR?A
 PUBLIC         EPAdr?T
 PUBLIC         WrCmd?T
 PUBLIC         WrCmd?A
 PUBLIC         WrCmdDat?T
 PUBLIC         RdCmdDat?T
 PUBLIC         RdCmdDat?A



*** CODE SEGMENT '?PR?EPAdr?T?usbhw':
   38: DWORD EPAdr (DWORD EPNum) {
 00000000  1C03      MOV         R3,R0 ; EPNum
 00000002  ---- Variable 'EPNum' assigned to Register 'R3' ----
 00000002            ; SCOPE-START
   41:     val = (EPNum & 0x0F) << 1;
 00000002  1C19      MOV         R1,R3 ; EPNum
 00000004  200F      MOV         R0,#0xF
 00000006  4001      AND         R1,R0
 00000008  0049      LSL         R1,R1,#0x1
 0000000A  ---- Variable 'val' assigned to Register 'R1' ----
   42:     if (EPNum & 0x80) {
 0000000A  1C18      MOV         R0,R3 ; EPNum
 0000000C  2280      MOV         R2,#0x80
 0000000E  4210      TST         R0,R2 ; EPNum
 00000010  D000      BEQ         L_1  ; T=0x00000014
   43:         val += 1;
 00000012  3101      ADD         R1,#0x1
   44:     }
 00000014          L_1:
   45:     return (val);
 00000014  1C08      MOV         R0,R1 ; val
 00000016            ; SCOPE-END

⌨️ 快捷键说明

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