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

📄 usbd_otghs.lst

📁 本代bootloader通过usb下载代码首先存放在sdram中
💻 LST
📖 第 1 页 / 共 5 页
字号:
    911                      // Flush and enable the Suspend interrupt
    912                      SET(pInterface->OTGHS_DEVICR, AT91C_OTGHS_WAKEUP | AT91C_OTGHS_SUSP);
    913          
    914                      // Enable the Start Of Frame (SOF) interrupt if needed
    915                      if (pUsb->pCallbacks->startOfFrame != 0) {
    916          
    917                          SET(pInterface->OTGHS_DEVIER, AT91C_OTGHS_SOF);
    918                      }
    919          
    920                      // Invoke the Reset callback
    921                      USB_ResetCallback(pUsb);
    922          
    923                      // Acknowledge end of bus reset interrupt
    924                      pInterface->OTGHS_DEVICR = AT91C_OTGHS_EORST;
    925                  }
    926          
    927                  // Handle upstream resume interrupt
    928                  else if (dStatus & AT91C_OTGHS_UPRSM) {
    929          
    930                      TRACE_DEBUG_WP("  External resume interrupt\n\r");
    931          
    932                      // - Acknowledge the IT
    933                      pInterface->OTGHS_DEVICR = AT91C_OTGHS_UPRSM;
    934                  }
    935          
    936                  // Endpoint interrupts
    937                  else {
    938          #ifndef DMA
    939                      // Handle endpoint interrupts
    940                      for (numIT = 0; numIT < NUM_IT_MAX; numIT++) {
    941                          if( dStatus & (1<<SHIFT_INTERUPT<<numIT) ) {
    942                              OTGHS_EndpointHandler(pUsb, numIT);
    943                          }
    944                      }
    945          #else
    946                      // Handle endpoint control interrupt
    947                      if( dStatus & (1<<SHIFT_INTERUPT<<0) ) {
    948                          OTGHS_EndpointHandler(pUsb, 0);
    949                      }
    950                      // Handle DMA interrupts
    951                      for(numIT = 1; numIT <= NUM_IT_MAX_DMA; numIT++) {
    952                          if( dStatus & (1<<SHIFT_DMA<<numIT) ) {
    953                              OTGHS_DmaHandler(pUsb, numIT);
    954                          }
    955                      }
    956          #endif
    957                  }
    958          
    959                  // Retrieve new interrupt status
    960                  dStatus = (pInterface->OTGHS_DEVISR) & (pInterface->OTGHS_DEVIMR);
    961          
    962                  // Mask unneeded interrupts
    963                  if (!ISSET(USB_GetState(pUsb), USB_STATE_DEFAULT)) {
    964          
    965                      dStatus &= AT91C_OTGHS_EORST | AT91C_OTGHS_SOF;
    966                  }
    967          
    968                  TRACE_DEBUG_H("\n\r");
    969          
    970                  if (dStatus != 0) {
    971          
    972                      TRACE_DEBUG_WP("  - ");
    973                  }
    974              }
    975          
    976              if ( (!ISSET(USB_GetState(pUsb), USB_STATE_SUSPENDED))
    977                 && (ISSET(USB_GetState(pUsb), USB_STATE_POWERED))){
    978          
    979                  LED_TOGGLE(LED_USB);
    980              }
    981          }
    982          
    983          //------------------------------------------------------------------------------
    984          // \brief  Sends data through an USB endpoint
    985          //
    986          //         Sets up the transfer descriptor, write one or two data payloads
    987          //         (depending on the number of FIFO banks for the endpoint) and then
    988          //         starts the actual transfer. The operation is complete when all
    989          //         the data has been sent.
    990          // \param  pUsb      Pointer to a S_usb instance
    991          // \param  bEndpoint Index of endpoint
    992          // \param  pData     Pointer to a buffer containing the data to send
    993          // \param  dLength   Length of the data buffer
    994          // \param  fCallback Optional function to invoke when the transfer finishes
    995          // \param  pArgument Optional argument for the callback function
    996          // \return Operation result code
    997          // \see    Operation result codes
    998          // \see    Callback_f
    999          // \see    S_usb
   1000          //------------------------------------------------------------------------------
   1001          static char OTGHS_Write(const S_usb   *pUsb,
   1002                                  unsigned char bEndpoint,
   1003                                  const void    *pData,
   1004                                  unsigned int  dLength,
   1005                                  Callback_f    fCallback,
   1006                                  void          *pArgument)
   1007          {
   1008              S_usb_endpoint *pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);
   1009              AT91PS_OTGHS pInterface = OTGHS_GetDriverInterface(pUsb);
   1010          
   1011              // Check that the endpoint is in Idle state
   1012              if (pEndpoint->dState != endpointStateIdle) {
   1013          
   1014                  return USB_STATUS_LOCKED;
   1015              }
   1016          
   1017              TRACE_DEBUG_WP("Write%d(%d) ", bEndpoint, dLength);
   1018          
   1019              // Setup the transfer descriptor
   1020              pEndpoint->pData = (char *) pData;
   1021              pEndpoint->dBytesRemaining = dLength;
   1022              pEndpoint->dBytesBuffered = 0;
   1023              pEndpoint->dBytesTransferred = 0;
   1024              pEndpoint->fCallback = fCallback;
   1025              pEndpoint->pArgument = pArgument;
   1026              pEndpoint->isDataSent = false;
   1027              
   1028              // Send one packet
   1029              pEndpoint->dState = endpointStateWrite;
   1030          
   1031          #ifdef DMA
   1032              // Test if endpoint type control
   1033              if (AT91C_OTGHS_EPT_TYPE_CTL_EPT == (AT91C_OTGHS_EPT_TYPE & pInterface->OTGHS_DEVEPTCFG[bEndpoint])) {
   1034          #endif
   1035                  // Enable endpoint IT
   1036                  pInterface->OTGHS_DEVIER = (1<<SHIFT_INTERUPT<<bEndpoint);
   1037                  pInterface->OTGHS_DEVEPTCER[bEndpoint] = AT91C_OTGHS_TXINI;
   1038          
   1039          #ifdef DMA
   1040              }
   1041              else {
   1042          
   1043                  // others endoint (not control)
   1044                  pEndpoint->dBytesBuffered = pEndpoint->dBytesRemaining;
   1045                  pEndpoint->dBytesRemaining = 0;
   1046          
   1047                  pInterface->OTGHS_DEVDMA[bEndpoint].OTGHS_DEVDMAADDRESS = (unsigned int) pEndpoint->pData;
   1048          
   1049                  // Enable IT DMA
   1050                  pInterface->OTGHS_DEVIER = (1<<SHIFT_DMA<<bEndpoint);
   1051          
   1052                  pInterface->OTGHS_DEVDMA[bEndpoint].OTGHS_DEVDMACONTROL = 
   1053                       (((pEndpoint->dBytesBuffered<<16)&AT91C_OTGHS_BUFF_LENGTH)
   1054                         | AT91C_OTGHS_END_B_EN
   1055                         | AT91C_OTGHS_END_BUFFIT
   1056                         | AT91C_OTGHS_CHANN_ENB);
   1057          
   1058              }
   1059          #endif
   1060          
   1061              return USB_STATUS_SUCCESS;
   1062          }
   1063          
   1064          //------------------------------------------------------------------------------
   1065          // \brief  Reads incoming data on an USB endpoint
   1066          //
   1067          //         This methods sets the transfer descriptor and activate the endpoint
   1068          //         interrupt. The actual transfer is then carried out by the endpoint
   1069          //         interrupt handler. The Read operation finishes either when the
   1070          //         buffer is full, or a short packet (inferior to endpoint maximum
   1071          //         packet size) is received.
   1072          // \param  pUsb      Pointer to a S_usb instance
   1073          // \param  bEndpoint Index of endpoint
   1074          // \param  pData     Pointer to a buffer to store the received data
   1075          // \param  dLength   Length of the receive buffer
   1076          // \param  fCallback Optional callback function
   1077          // \param  pArgument Optional callback argument
   1078          // \return Operation result code
   1079          // \see    Callback_f
   1080          // \see    S_usb
   1081          //------------------------------------------------------------------------------
   1082          static char OTGHS_Read(const S_usb   *pUsb,
   1083                                 unsigned char bEndpoint,
   1084                                 void          *pData,
   1085                                 unsigned int  dLength,
   1086                                 Callback_f    fCallback,
   1087                                 void          *pArgument)
   1088          {
   1089              AT91PS_OTGHS pInterface = OTGHS_GetDriverInterface(pUsb);
   1090              S_usb_endpoint *pEndpoint = USB_GetEndpoint(pUsb, bEndpoint);
   1091          
   1092              //! Return if the endpoint is not in IDLE state
   1093              if (pEndpoint->dState != endpointStateIdle) {
   1094          
   1095                  return USB_STATUS_LOCKED;
   1096              }
   1097          
   1098              TRACE_DEBUG_M("Read%d(%d) ", bEndpoint, dLength);
   1099          
   1100              // Endpoint enters Read state
   1101              pEndpoint->dState = endpointStateRead;
   1102          
   1103              //! Set the transfer descriptor
   1104              pEndpoint->pData = (char *) pData;
   1105              pEndpoint->dBytesRemaining = dLength;
   1106              pEndpoint->dBytesBuffered = 0;
   1107              pEndpoint->dBytesTransferred = 0;
   1108              pEndpoint->fCallback = fCallback;
   1109              pEndpoint->pArgument = pArgument;
   1110          
   1111          #ifdef DMA
   1112              // Test if endpoint type control
   1113              if (AT91C_OTGHS_EPT_TYPE_CTL_EPT == (AT91C_OTGHS_EPT_TYPE & pInterface->OTGHS_DEVEPTCFG[bEndpoint])) {
   1114          #endif
   1115                  // Control endpoint
   1116                  // Enable endpoint IT
   1117                  pInterface->OTGHS_DEVIER = (1<<SHIFT_INTERUPT<<bEndpoint);
   1118                  pInterface->OTGHS_DEVEPTCER[bEndpoint] = AT91C_OTGHS_RXOUT;
   1119          #ifdef DMA
   1120              }
   1121              else {
   1122          
   1123                  // others endoint (not control)
   1124                  pEndpoint->dBytesBuffered = pEndpoint->dBytesRemaining;
   1125                  pEndpoint->dBytesRemaining = 0;
   1126          
   1127                  // Enable IT DMA
   1128                  pInterface->OTGHS_DEVIER = (1<<SHIFT_DMA<<bEndpoint);
   1129          
   1130                  pInterface->OTGHS_DEVDMA[bEndpoint].OTGHS_DEVDMAADDRESS = (unsigned int) pEndpoint->pData;
   1131          
   1132                  pInterface->OTGHS_DEVDMA[bEndpoint].OTGHS_DEVDMACONTROL = \
   1133                                       ( (pEndpoint->dBytesBuffered<<16)
   1134                                         | AT91C_OTGHS_END_TR_EN
   1135                                         | AT91C_OTGHS_END_TR_IT
   1136                                         | AT91C_OTGHS_END_B_EN
   1137                                         | AT91C_OTGHS_END_BUFFIT
   1138                                         | AT91C_OTGHS_CHANN_ENB);
   1139              }
   1140          #endif
   1141          
   1142            return USB_STATUS_SUCCESS;
   1143          }
   1144          
   1145          //---------------------------------------------

⌨️ 快捷键说明

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