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

📄 usbd_otghs.lst

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

⌨️ 快捷键说明

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