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

📄 usbd_otghs.lst

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

⌨️ 快捷键说明

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