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

📄 usb_ctrl.c

📁 在CCS开发环境下的DSP 5509A的固件程序
💻 C
📖 第 1 页 / 共 2 页
字号:
// if the USB reset request received, abort all endpoint activities
// and reconfigure the USB module
 
  if(USB_ctl_events & USB_EVENT_RESET)        // USB RESET event received
  {
    USB_abortAllTransaction(DevNum);          // stop all data transfer activities
    usbCurConfigStat = 0x00;                  // reset device config number
    usbCurAltSetStat = 0x00;                  // reset Alt Setting number 
    USB_init(USB0, myUsbConfig, 0x80);        // reconfig the USB module
  }
  
  if(USB_ctl_events & USB_EVENT_SUSPEND)      // USB SUSPEND event received
  {
   
    // Add code to support suspend request 
      
  }

  
// if the event is a setup packet received event then read the setup packet,
// and lookup the USB_ReqTable[] for the appropriate request handler

  if((USB_ctl_events & USB_EVENT_SETUP) == USB_EVENT_SETUP)
  {
    // read the setup packet, if something wrong with setup packet then stall
    // the control endpints
    if(USB_getSetupPacket(DevNum, &USB_Setup) == USB_FALSE)
    {
       ReqHandlerRet = USB_REQUEST_STALL;
    }
    else
    {  
      // lookup the USB request handler
      Request = ((USB_Setup.bmRequestType&0xC0)<<8)|USB_Setup.bRequest;
      fpRequestHandler = USB_lookupReqHandler(Request, USB_ReqTable);
    }
    
  }   // end of if setup event received
  
  // Call the USB request handler unless ReqHandlerRet is
  // already set to USB_REQUEST_STALL by code above
  
  if(ReqHandlerRet == USB_REQUEST_DONE)
  
     // call the request handler pointed by fpRequestHandler  
     ReqHandlerRet = (*fpRequestHandler)(DevNum, &USB_Setup, hEp0In, hEp0Out);
     
  // based on the return value from the called request handler routine
  // send ACK, stall endpoint, or do nothing.
  switch(ReqHandlerRet)
  {
    // the request handler routine successfully completed the task,
    // send a 0-byte ACK
    case USB_REQUEST_SEND_ACK :
         USB_postTransaction(hEp0In, 0, NULL, USB_IOFLAG_NONE);
         fpRequestHandler = USB_reqUnknown;
            
    // request handler is not done, but waiting for more data from host,
    // do not modify fpRequestHandler, so the same request handler will
    // be called by usb_ctl() when the data packet arrive.  
    case USB_REQUEST_DATA_OUT :
         break;
         
    // the request handler routine successfully completed the task,
    // get a 0-byte ACK
    case USB_REQUEST_GET_ACK :
         USB_postTransaction(hEp0Out, 0, NULL, USB_IOFLAG_NONE);
         fpRequestHandler = USB_reqUnknown;    
         
    // request handler is not done, but waiting for more sending more data,
    // to host, do not modify fpRequestHandler, so the same request handler will
    // be called by usb_ctl() when the current data packet moves out of the
    // endpoint buffer. 
    case USB_REQUEST_DATA_IN :
         break;
      
    // the request handler does not know what to do with the setup packet,
    // stall the control endpoints
    case USB_REQUEST_STALL :
         USB_stallEndpt(hEp0Out);
         USB_stallEndpt(hEp0In);
         break;
         
    case USB_REQUEST_DONE :
         fpRequestHandler = USB_reqUnknown;     
         break;
         
    default:
         break;
  }

  // clear the flags if a new setup packet is received 
  if(USB_Setup.New)
  {
    USB_Setup.New = 0;
  }

}


/******************************************************************************/
/* Name     : USB_lookupReqHandler                                            */
/*                                                                            */
/* Purpose  : Parse through the array of USB request handler and pickup the   */
/*            address of that particular request handler                      */
/*                                                                            */
/* Author   : MH                                                              */
/*                                                                            */
/* Based on :                                                                 */
/*                                                                            */
/*                                                                            */
/*============================================================================*/
/* Arguments:                                                                 */
/*                                                                            */
/* Request       : Request value retrieved from the first 2 bytes of USB      */
/*                 setup packet                                               */
/*                                                                            */
/* *pUSB_ReqTable: A pointer to the USB request handler table                 */
/*                                                                            */
/*============================================================================*/
/* Return Value:                                                              */
/*                                                                            */
/* Returns a function pointer to the USB request handler, a NULL pointer if   */
/* the desired request handler does not exist in the request handler table    */
/*                                                                            */ 
/*============================================================================*/
/* Comments:                                                                  */
/*                                                                            */
/*                                                                            */
/******************************************************************************/
fpUSB_REQ_HANDLER USB_lookupReqHandler(Uint16 Request, USB_request_struct *pUSB_ReqTable)
{
  Uint16 ii;
  
  // parse thru the end of request handler table                                                        
  for(ii=0; pUSB_ReqTable[ii].fpRequestHandler != NULL ; ii++)
  {
    // if request handler exists return a pointer to the request handler routine
    if(pUSB_ReqTable[ii].Request == Request)
      {
        return(pUSB_ReqTable[ii].fpRequestHandler);
      }
  }
  // if request handler does not exist return a pointer to the USB_reqUnknown
  // routine
  return(USB_reqUnknown);   
}

⌨️ 快捷键说明

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