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

📄 usbd_otghs.lst

📁 ATmel的AT91sam7SE芯片 USB固件开发源代码
💻 LST
📖 第 1 页 / 共 5 页
字号:
    185              if ((pEndpoint->dState == endpointStateWrite)
    186                  || (pEndpoint->dState == endpointStateRead)) {
    187          
    188                  TRACE_DEBUG_L("E");
    189          
    190                  // Endpoint returns in Idle state
    191                  pEndpoint->dState = endpointStateIdle;
    192          
    193                  // Invoke callback is present
    194                  if (pEndpoint->fCallback != 0) {
    195          
    196                      pEndpoint->fCallback((unsigned int) pEndpoint->pArgument,
    197                                           (unsigned int) bStatus,
    198                                           pEndpoint->dBytesTransferred,
    199                                           pEndpoint->dBytesRemaining
    200                                           + pEndpoint->dBytesBuffered);
    201                  }
    202              }
    203          }
    204          
    205          //------------------------------------------------------------------------------
    206          // \brief  Transfers a data payload from the current tranfer buffer to the
    207          //         endpoint FIFO.
    208          // \param  pUsb      Pointer to a S_usb instance
    209          // \param  bEndpoint Index of endpoint
    210          // \return Number of bytes transferred
    211          // \see    S_usb
    212          //------------------------------------------------------------------------------
    213          static unsigned int OTGHS_WritePayload(const S_usb *pUsb,
    214                                                 unsigned char bEndpoint)
    215          {
    216              AT91PS_OTGHS_EPTFIFO pInterfaceEPT = OTGHS_GetInterfaceEPT(pUsb);
    217              S_usb_endpoint *pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);
    218              char           *pfifo;
    219              unsigned int   dBytes;
    220              unsigned int   dCtr;
    221          
    222              pfifo = (char*)&(pInterfaceEPT->OTGHS_READEPT0[bEndpoint*16384]);
    223          
    224              // Get the number of bytes to send
    225              dBytes = min(pEndpoint->wMaxPacketSize, pEndpoint->dBytesRemaining);
    226          
    227              // Transfer one packet in the FIFO buffer
    228              for (dCtr = 0; dCtr < dBytes; dCtr++) {
    229          
    230                  pfifo[dCtr] = *(pEndpoint->pData);
    231                  pEndpoint->pData++;
    232              }
    233          
    234              pEndpoint->dBytesBuffered += dBytes;
    235              pEndpoint->dBytesRemaining -= dBytes;
    236          
    237              return dBytes;
    238          }
    239          
    240          //----------------------------------------------------------------------------
    241          // \brief  Transfers a data payload from an endpoint FIFO to the current
    242          //         transfer buffer.
    243          // \param  pUsb        Pointer to a S_usb instance
    244          // \param  bEndpoint   Index of endpoint
    245          // \param  wPacketSize Size of received data packet
    246          // \return Number of bytes transferred
    247          // \see    S_usb
    248          //------------------------------------------------------------------------------
    249          static unsigned int OTGHS_GetPayload(const S_usb    *pUsb,
    250                                               unsigned char  bEndpoint,
    251                                               unsigned short wPacketSize)
    252          {
    253              AT91PS_OTGHS_EPTFIFO pInterfaceEPT = OTGHS_GetInterfaceEPT(pUsb);
    254              S_usb_endpoint *pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);
    255              char           *pfifo;
    256              unsigned int   dBytes;
    257              unsigned int   dCtr;
    258          
    259              pfifo = (char*)&(pInterfaceEPT->OTGHS_READEPT0[bEndpoint*16384]);
    260          
    261              // Get number of bytes to retrieve
    262              dBytes = min(pEndpoint->dBytesRemaining, wPacketSize);
    263          
    264              // Retrieve packet
    265              for (dCtr = 0; dCtr < dBytes; dCtr++) {
    266          
    267                  *(pEndpoint->pData) = pfifo[dCtr];
    268                  pEndpoint->pData++;
    269              }
    270          
    271              pEndpoint->dBytesRemaining -= dBytes;
    272              pEndpoint->dBytesTransferred += dBytes;
    273              pEndpoint->dBytesBuffered += wPacketSize - dBytes;
    274          
    275              return dBytes;
    276          }
    277          
    278          //------------------------------------------------------------------------------
    279          // \brief  Transfers a received SETUP packet from endpoint 0 FIFO to the
    280          //         S_usb_request structure of an USB driver
    281          // \param  pUsb Pointer to a S_usb instance
    282          // \see    S_usb
    283          //------------------------------------------------------------------------------
    284          static void OTGHS_GetSetup(const S_usb *pUsb)
    285          {
    286              unsigned int *pData = (unsigned int *) USB_GetSetup(pUsb);
    287              AT91PS_OTGHS_EPTFIFO pInterfaceEPT = OTGHS_GetInterfaceEPT(pUsb);
    288          
    289              pData[0] = pInterfaceEPT->OTGHS_READEPT0[0];
    290              pData[1] = pInterfaceEPT->OTGHS_READEPT0[0];
    291          }
    292          
    293          //------------------------------------------------------------------------------
    294          // \brief  This function reset all endpoint transfer descriptors
    295          // \param  pUsb Pointer to a S_usb instance
    296          // \see    S_usb
    297          //------------------------------------------------------------------------------
    298          static void OTGHS_ResetEndpoints(const S_usb *pUsb)
    299          {
    300              S_usb_endpoint *pEndpoint;
    301              unsigned char  bEndpoint;
    302          
    303              // Reset the transfer descriptor of every endpoint
    304              for (bEndpoint = 0; bEndpoint < pUsb->dNumEndpoints; bEndpoint++) {
    305          
    306                  pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);
    307          
    308                  // Reset endpoint transfer descriptor
    309                  pEndpoint->pData = 0;
    310                  pEndpoint->dBytesRemaining = 0;
    311                  pEndpoint->dBytesTransferred = 0;
    312                  pEndpoint->dBytesBuffered = 0;
    313                  pEndpoint->fCallback = 0;
    314                  pEndpoint->pArgument = 0;
    315          
    316                  // Configure endpoint characteristics
    317                  pEndpoint->dState = endpointStateDisabled;
    318              }
    319          }
    320          
    321          //------------------------------------------------------------------------------
    322          // \brief  Disable all endpoints (except control endpoint 0), aborting current
    323          //         transfers if necessary.
    324          // \param  pUsb Pointer to a S_usb instance
    325          //------------------------------------------------------------------------------
    326          static void OTGHS_DisableEndpoints(const S_usb *pUsb)
    327          {
    328              S_usb_endpoint *pEndpoint;
    329              unsigned char  bEndpoint;
    330          
    331              // Foreach endpoint, if it is enabled, disable it and invoke the callback
    332              // Control endpoint 0 is not disabled
    333              for (bEndpoint = 1; bEndpoint < pUsb->dNumEndpoints; bEndpoint++) {
    334          
    335                  pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);
    336                  OTGHS_EndOfTransfer(pEndpoint, USB_STATUS_RESET);
    337          
    338                  pEndpoint->dState = endpointStateDisabled;
    339              }
    340          }
    341          
    342          //------------------------------------------------------------------------------
    343          // \brief  Endpoint interrupt handler.
    344          //
    345          //         Handle IN/OUT transfers, received SETUP packets and STALLing
    346          // \param  pUsb      Pointer to a S_usb instance
    347          // \param  bEndpoint Index of endpoint
    348          // \see    S_usb
    349          //------------------------------------------------------------------------------
    350          static void OTGHS_EndpointHandler(const S_usb *pUsb, unsigned char bEndpoint)
    351          {
    352              S_usb_endpoint *pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);
    353              AT91PS_OTGHS pInterface = OTGHS_GetDriverInterface(pUsb);
    354              unsigned int dStatus = pInterface->OTGHS_DEVEPTCSR[bEndpoint];
    355              unsigned short wPacketSize;
    356          
    357              TRACE_DEBUG_L("Ept%d, 0x%X ", bEndpoint, dStatus);
    358          
    359              // Handle interrupts
    360              // IN packet sent
    361              if((ISSET(pInterface->OTGHS_DEVEPTCMR[bEndpoint], AT91C_OTGHS_TXINI))
    362              && (ISSET(dStatus, AT91C_OTGHS_TXINI ))) {
    363          
    364                  TRACE_DEBUG_L("Wr ");
    365          
    366                  if (pEndpoint->dBytesBuffered > 0) {
    367          
    368                      TRACE_DEBUG_L("%d ", pEndpoint->dBytesBuffered);
    369          
    370                      pEndpoint->dBytesTransferred += pEndpoint->dBytesBuffered;
    371                      pEndpoint->dBytesBuffered = 0;
    372                  }
    373          
    374                  if ((!pEndpoint->isDataSent) || (pEndpoint->dBytesRemaining > 0)) {
    375                      
    376                      OTGHS_WritePayload(pUsb, bEndpoint);
    377                      pEndpoint->isDataSent = true;
    378          
    379                      pInterface->OTGHS_DEVEPTCCR[bEndpoint] = AT91C_OTGHS_TXINI;
    380                      // For a non-control endpoint, the FIFOCON bit must be cleared
    381                      // to start the transfer
    382                      if ((AT91C_OTGHS_EPT_TYPE & pInterface->OTGHS_DEVEPTCFG[bEndpoint])
    383                          != AT91C_OTGHS_EPT_TYPE_CTL_EPT) {
    384          
    385                          pInterface->OTGHS_DEVEPTCDR[bEndpoint] = AT91C_OTGHS_FIFOCON;
    386                      }
    387                  }
    388                  else {
    389                      
    390                      pInterface->OTGHS_DEVEPTCDR[bEndpoint] = AT91C_OTGHS_TXINI;
    391          
    392                      // Disable interrupt if this is not a control endpoint
    393                      if ((AT91C_OTGHS_EPT_TYPE & pInterface->OTGHS_DEVEPTCFG[bEndpoint])
    394                          != AT91C_OTGHS_EPT_TYPE_CTL_EPT) {
    395          
    396                          pInterface->OTGHS_DEVIDR = 1<<SHIFT_INTERUPT<<bEndpoint;
    397          
    398                      }
    399                      OTGHS_EndOfTransfer(pEndpoint, USB_STATUS_SUCCESS);
    400                  }
    401              }
    402          
    403              // OUT packet received
    404              if(ISSET(dStatus, AT91C_OTGHS_RXOUT)) {
    405          
    406                  TRACE_DEBUG_L("Rd ");
    407          
    408                  // Check that the endpoint is in Read state
    409                  if (pEndpoint->dState != endpointStateRead) {
    410          
    411                      // Endpoint is NOT in Read state
    412                      if (ISCLEARED(pInterface->OTGHS_DEVEPTCFG[bEndpoint], AT91C_OTGHS_EPT_TYPE)
    413                       && ISCLEARED(dStatus, (0x7FF<<20))) {  // byte count
    414          
    415                          // Control endpoint, 0 bytes received
    416                          // Acknowledge the data and finish the current transfer
    417                          TRACE_DEBUG_L("Ack ");
    418                          pInterface->OTGHS_DEVEPTCCR[bEndpoint] = AT91C_OTGHS_RXOUT;
    419          
    420                          OTGHS_EndOfTransfer(pEndpoint, USB_STATUS_SUCCESS);

⌨️ 快捷键说明

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