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

📄 usbd_otghs.lst

📁 本代bootloader通过usb下载代码首先存放在sdram中
💻 LST
📖 第 1 页 / 共 5 页
字号:
    435                      // Endpoint is in Read state
    436                      // Retrieve data and store it into the current transfer buffer
    437                      wPacketSize = (unsigned short) ((dStatus >> 20) & 0x7FF);
    438          
    439                      TRACE_DEBUG_WP("%d ", wPacketSize);
    440          
    441                      OTGHS_GetPayload(pUsb, bEndpoint, wPacketSize);
    442          
    443                      pInterface->OTGHS_DEVEPTCCR[bEndpoint] = AT91C_OTGHS_RXOUT;
    444                      pInterface->OTGHS_DEVEPTCDR[bEndpoint] = AT91C_OTGHS_FIFOCON;
    445          
    446                      if ((pEndpoint->dBytesRemaining == 0)
    447                          || (wPacketSize < pEndpoint->wMaxPacketSize)) {
    448          
    449                          pInterface->OTGHS_DEVEPTCDR[bEndpoint] = AT91C_OTGHS_RXOUT;
    450          
    451                          // Disable interrupt if this is not a control endpoint
    452                          if ((AT91C_OTGHS_EPT_TYPE & pInterface->OTGHS_DEVEPTCFG[bEndpoint])
    453                              != AT91C_OTGHS_EPT_TYPE_CTL_EPT) {
    454          
    455                              pInterface->OTGHS_DEVIDR = 1<<SHIFT_INTERUPT<<bEndpoint;
    456                          }
    457          
    458                          OTGHS_EndOfTransfer(pEndpoint, USB_STATUS_SUCCESS);
    459                      }
    460                  }
    461              }
    462          
    463              // SETUP packet received
    464              if(ISSET(dStatus, AT91C_OTGHS_RXSTP)) {
    465          
    466                  TRACE_DEBUG_WP("Stp ");
    467          
    468                  // If a transfer was pending, complete it
    469                  // Handle the case where during the status phase of a control write
    470                  // transfer, the host receives the device ZLP and ack it, but the ack
    471                  // is not received by the device
    472                  if ((pEndpoint->dState == endpointStateWrite)
    473                      || (pEndpoint->dState == endpointStateRead)) {
    474          
    475                      OTGHS_EndOfTransfer(pEndpoint, USB_STATUS_SUCCESS);
    476                  }
    477          
    478                  // Copy the setup packet in S_usb
    479                  OTGHS_GetSetup(pUsb);
    480          
    481                  // Acknowledge setup packet
    482                  pInterface->OTGHS_DEVEPTCCR[bEndpoint] = AT91C_OTGHS_RXSTP;
    483          
    484                  // Forward the request to the upper layer
    485                  USB_NewRequestCallback(pUsb);
    486              }
    487          
    488              // STALL sent
    489              if (ISSET(dStatus, AT91C_OTGHS_STALL)) {
    490          
    491                  TRACE_WARNING("Sta 0x%X [%d] ", dStatus, bEndpoint);
    492          
    493                  // Acknowledge STALL interrupt and disable it
    494                  pInterface->OTGHS_DEVEPTCCR[bEndpoint] = AT91C_OTGHS_STALL;
    495                  //pInterface->OTGHS_DEVEPTCDR[bEndpoint] = AT91C_OTGHS_STALL;
    496          
    497                  // If the endpoint is not halted, clear the stall condition
    498                  if (pEndpoint->dState != endpointStateHalted) {
    499          
    500                      TRACE_WARNING("_ " );
    501                      // Acknowledge the stall RQ flag
    502                      pInterface->OTGHS_DEVEPTCDR[bEndpoint] = AT91C_OTGHS_STALLRQ;
    503                  }
    504          
    505              }
    506          
    507          }
    508          
    509          
    510          //------------------------------------------------------------------------------
    511          //      Exported functions
    512          //------------------------------------------------------------------------------
    513          //------------------------------------------------------------------------------
    514          // \brief  Configure an endpoint with the provided endpoint descriptor
    515          // \param  pUsb    Pointer to a S_usb instance
    516          // \param  pEpDesc Pointer to the endpoint descriptor
    517          // \return true if the endpoint is now configured, false otherwise
    518          // \see    S_usb_endpoint_descriptor
    519          // \see    S_usb
    520          //------------------------------------------------------------------------------
    521          static bool OTGHS_ConfigureEndpoint(const S_usb *pUsb,
    522                                       const S_usb_endpoint_descriptor *pEpDesc)
    523          {
    524              AT91PS_OTGHS   pInterface = OTGHS_GetDriverInterface(pUsb);
    525              S_usb_endpoint *pEndpoint;
    526              unsigned char  bEndpoint;
    527              unsigned char  bType;
    528              unsigned char  endpointDir;
    529              unsigned short sizeEpt = 0;
    530          
    531              // Maximum packet size configuration value
    532              if( pEpDesc->wMaxPacketSize == 8 ) {
    533                  sizeEpt = AT91C_OTGHS_EPT_SIZE_8;
    534              } else if ( pEpDesc->wMaxPacketSize == 16 ) {
    535                  sizeEpt = AT91C_OTGHS_EPT_SIZE_16;
    536              } else if ( pEpDesc->wMaxPacketSize == 32 ) {
    537                  sizeEpt = AT91C_OTGHS_EPT_SIZE_32;
    538              } else if ( pEpDesc->wMaxPacketSize == 64 ) {
    539                  sizeEpt = AT91C_OTGHS_EPT_SIZE_64;
    540              } else if ( pEpDesc->wMaxPacketSize == 128 ) {
    541                  sizeEpt = AT91C_OTGHS_EPT_SIZE_128;
    542              } else if ( pEpDesc->wMaxPacketSize == 256 ) {
    543                  sizeEpt = AT91C_OTGHS_EPT_SIZE_256;
    544              } else if ( pEpDesc->wMaxPacketSize == 512 ) {
    545                  sizeEpt = AT91C_OTGHS_EPT_SIZE_512;
    546              } else if ( pEpDesc->wMaxPacketSize == 1024 ) {
    547                  sizeEpt = AT91C_OTGHS_EPT_SIZE_1024;
    548              } //else {
    549              //  sizeEpt = 0; // control endpoint
    550              //}
    551          
    552              // if pEpDesc == 0 then initialize the control endpoint
    553              if (pEpDesc == (S_usb_endpoint_descriptor const *) 0) {
    554          
    555                  bEndpoint = 0;
    556                  bType = 0;    // Control endpoint
    557              }
    558              else {
    559                  // The endpoint number
    560                  bEndpoint   = (unsigned char) (pEpDesc->bEndpointAddress & 0x7);
    561                  // Transfer type: Control, Isochronous, Bulk, Interrupt
    562                  bType = (unsigned char) (pEpDesc->bmAttributes     & 0x3);
    563                  // Direction, ignored for control endpoints
    564                  endpointDir  = (unsigned char) (pEpDesc->bEndpointAddress & (1<<7));
    565              }
    566          
    567              // Get pointer on endpoint
    568              pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);
    569              if (pEndpoint == 0) {
    570          
    571                  return false;
    572              }
    573          
    574              // Configure wMaxPacketSize
    575              if (pEpDesc != 0) {
    576          
    577                  pEndpoint->wMaxPacketSize = pEpDesc->wMaxPacketSize;
    578              }
    579              else {
    580          
    581                  pEndpoint->wMaxPacketSize = USB_ENDPOINT0_MAXPACKETSIZE;
    582              }
    583          
    584              // Abort the current transfer is the endpoint was configured and in
    585              // Write or Read state
    586              if ((pEndpoint->dState == endpointStateRead)
    587                  || (pEndpoint->dState == endpointStateWrite)) {
    588          
    589                  OTGHS_EndOfTransfer(pEndpoint, USB_STATUS_RESET);
    590              }
    591          
    592              // Enter in IDLE state
    593              pEndpoint->dState = endpointStateIdle;
    594          
    595              // Reset Endpoint Fifos
    596              pInterface->OTGHS_DEVEPT |= (1<<bEndpoint<<16);
    597              pInterface->OTGHS_DEVEPT &= ~(1<<bEndpoint<<16);
    598          
    599              // Enable endpoint
    600              pInterface->OTGHS_DEVEPT |= (1<<bEndpoint);
    601          
    602              // Configure endpoint
    603              switch (bType) {
    604          
    605                  //-------------------------
    606                  case ENDPOINT_TYPE_CONTROL:
    607                  //-------------------------
    608                      TRACE_INFO("Control[%d]\n\r",bEndpoint);
    609          
    610                      //! Configure endpoint
    611                      pInterface->OTGHS_DEVEPTCFG[bEndpoint] = AT91C_OTGHS_ALLOC |
    612                                      AT91C_OTGHS_EPT_SIZE_64 | AT91C_OTGHS_EPT_DIR_OUT | AT91C_OTGHS_EPT_TYPE_CTL_EPT | AT91C_OTGHS_BK_NUMBER_1;
    613          
    614                      // Enable RXSTP interrupt
    615                      pInterface->OTGHS_DEVEPTCER[bEndpoint] = AT91C_OTGHS_RXSTP;
    616          
    617                      // Enable endpoint IT
    618                      pInterface->OTGHS_DEVIER = 1<<SHIFT_INTERUPT<<bEndpoint;
    619          
    620                      break;
    621          
    622                  //-----------------------------
    623                  case ENDPOINT_TYPE_ISOCHRONOUS:
    624                  //-----------------------------
    625                      if (endpointDir) {
    626                          TRACE_INFO("Iso In[%d]\n\r",bEndpoint);
    627          
    628                          //! Configure endpoint
    629          #ifndef DMA
    630                          pInterface->OTGHS_DEVEPTCFG[bEndpoint] = AT91C_OTGHS_ALLOC |
    631                                                        sizeEpt | AT91C_OTGHS_EPT_DIR_IN | AT91C_OTGHS_EPT_TYPE_ISO_EPT | AT91C_OTGHS_BK_NUMBER_2;
    632          #else
    633                          pInterface->OTGHS_DEVEPTCFG[bEndpoint] = AT91C_OTGHS_ALLOC | AT91C_OTGHS_AUTOSW |
    634                                                        sizeEpt | AT91C_OTGHS_EPT_DIR_IN | AT91C_OTGHS_EPT_TYPE_ISO_EPT | AT91C_OTGHS_BK_NUMBER_2;
    635          #endif
    636          
    637                      }
    638                      else {
    639                          TRACE_INFO("Iso Out[%d]\n\r",bEndpoint);
    640          
    641                          //! Configure endpoint
    642          #ifndef DMA
    643                          pInterface->OTGHS_DEVEPTCFG[bEndpoint] =  AT91C_OTGHS_ALLOC |
    644                                                       sizeEpt | AT91C_OTGHS_EPT_DIR_OUT | AT91C_OTGHS_EPT_TYPE_ISO_EPT | AT91C_OTGHS_BK_NUMBER_2;
    645          #else
    646                          pInterface->OTGHS_DEVEPTCFG[bEndpoint] = AT91C_OTGHS_ALLOC | AT91C_OTGHS_AUTOSW |
    647                                                       sizeEpt | AT91C_OTGHS_EPT_DIR_OUT | AT91C_OTGHS_EPT_TYPE_ISO_EPT | AT91C_OTGHS_BK_NUMBER_2;
    648          #endif
    649          
    650                      }
    651                      break;
    652          
    653                  //----------------------
    654                  case ENDPOINT_TYPE_BULK:
    655                  //----------------------
    656                      if (endpointDir) {
    657                          TRACE_INFO("Bulk In(%d)[%d] ",bEndpoint, pEpDesc->wMaxPacketSize);
    658                          //! Configure endpoint
    659          #ifndef DMA
    660                          pInterface->OTGHS_DEVEPTCFG[bEndpoint] = AT91C_OTGHS_ALLOC |
    661                                                        sizeEpt | AT91C_OTGHS_EPT_DIR_IN | AT91C_OTGHS_EPT_TYPE_BUL_EPT | AT91C_OTGHS_BK_NUMBER_2;
    662          #else
    663                          pInterface->OTGHS_DEVEPTCFG[bEndpoint] = AT91C_OTGHS_ALLOC | AT91C_OTGHS_AUTOSW |
    664                                                        sizeEpt | AT91C_OTGHS_EPT_DIR_IN | AT91C_OTGHS_EPT_TYPE_BUL_EPT | AT91C_OTGHS_BK_NUMBER_2;
    665          #endif
    666          
    667                      }
    668                      else {
    669                          TRACE_INFO("Bulk Out(%d)[%d]\n\r",bEndpoint, pEpDesc->wMaxPacketSize);
    670                          //! Configure endpoint
    671          #ifndef DMA
    672                          pInterface->OTGHS_DEVEPTCFG[bEndpoint] =  AT91C_OTGHS_ALLOC |

⌨️ 快捷键说明

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