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

📄 usb_req.c

📁 在CCS开发环境下的DSP 5509A的固件程序
💻 C
📖 第 1 页 / 共 2 页
字号:
    {       
      gen_purpose_buffer[1] = (((Uint16)USB_getRemoteWakeupStat(USB0))<<1) | usbCurDevStat;
      USB_postTransaction(hInEp, 2, &gen_purpose_buffer, USB_IOFLAG_NONE);
      break;
    }
    
    case 1:          // return Interface status
    {        
      gen_purpose_buffer[1] = usbCurIntrfcStat;
      USB_postTransaction(hInEp, 2, &gen_purpose_buffer, USB_IOFLAG_NONE);
      break;
    }
    
    case 2:           // return Endpoint status
    { 
      Endpt                 = (USB_Setup->wIndex) & 0xFF;
      hEPx                  =  USB_epNumToHandle(USB0, Endpt);
      gen_purpose_buffer[1] = (Uint16)USB_getEndptStall(hEPx);
      USB_postTransaction(hInEp, 2, &gen_purpose_buffer, USB_IOFLAG_NONE);
      break;
    }
    
    default:
    {
     // Unsupported feature, request the usb control endpoint handler
     // (usb_ctl( )) to stall the endpoint 
     ret_stat = USB_REQUEST_STALL;
     break;
    }
  }

  return(ret_stat);
}


/******************************************************************************/
/* Name     : USB_reqSetFeature                                                */
/*                                                                            */
/* Catagory : Standard Request Handler as defined in Chap 9 of USB spec 1.1   */
/*                                                                            */
/* Purpose  : Handle standard device request GET_STATUS                       */
/*                                                                            */
/* Author   :                                                                 */
/*                                                                            */
/* Comment  : USB_REQUEST_RET and USB_REQUEST_ARGS are defined in usb_req.h   */
/*            header file                                                     */
/*============================================================================*/

USB_REQUEST_RET USB_reqSetFeature(USB_REQUEST_ARGS)
{
  USB_EpHandle hEPx;
  Uint16 Endpt;           
  USB_REQUEST_RET ret_stat = USB_REQUEST_SEND_ACK;

  switch(USB_Setup->wValue)
  {
    case USB_FEATURE_ENDPOINT_STALL:    // stall endpoint  
    {
      Endpt = (USB_Setup->wIndex) & 0xFF;
      hEPx = USB_epNumToHandle(USB0, Endpt);
      USB_stallEndpt(hEPx);
      break;
    }
    
    case USB_FEATURE_REMOTE_WAKEUP:    // enable remote wakeup
    { 
      USB_setRemoteWakeup(USB0, USB_TRUE);
      break;
    }
    
    default:
    {
      // Feature not supported, request the usb control endpoint handler
      // (usb_ctl( )) to stall the endpoint
      ret_stat = USB_REQUEST_STALL;
      break;
    }
  }

  return(ret_stat);
}

/******************************************************************************/
/* Name     : USB_reqGetConfiguration                                         */
/*                                                                            */
/* Catagory : Standard Request Handler as defined in Chap 9 of USB spec 1.1   */
/*                                                                            */
/* Purpose  : Return current device configuration                             */
/*                                                                            */
/* Author   :                                                                 */
/*                                                                            */
/* Comment  : USB_REQUEST_RET and USB_REQUEST_ARGS are defined in usb_req.h   */
/*            header file                                                     */
/*============================================================================*/

USB_REQUEST_RET USB_reqGetConfiguration(USB_REQUEST_ARGS)
{
  // Send the current Configuration Value
  gen_purpose_buffer[1] = usbCurConfigStat;
  
  USB_postTransaction(hInEp, 1, (void *)&gen_purpose_buffer,
                      USB_IOFLAG_NONE|USB_IOFLAG_NOSHORT);
                      
  return(USB_REQUEST_GET_ACK);
}

/******************************************************************************/
/* Name     : USB_reqGetInterface                                             */
/*                                                                            */
/* Catagory : Standard Request Handler as defined in Chap 9 of USB spec 1.1   */
/*                                                                            */
/* Purpose  : Return current interface value                                  */
/*                                                                            */
/* Author   :                                                                 */
/*                                                                            */
/* Comment  : USB_REQUEST_RET and USB_REQUEST_ARGS are defined in usb_req.h   */
/*            header file                                                     */
/*============================================================================*/

USB_REQUEST_RET USB_reqGetInterface(USB_REQUEST_ARGS)
{
  // Send the current Configuration Value
  gen_purpose_buffer[1] = usbCurAltSetStat;
  
  USB_postTransaction(hInEp, 1, (void *)&gen_purpose_buffer,
                      USB_IOFLAG_NONE|USB_IOFLAG_NOSHORT);
                      
  return(USB_REQUEST_GET_ACK);
}

/******************************************************************************/
/* Name     : USB_reqGetDescriptor                                            */
/*                                                                            */
/* Catagory : Standard Request Handler as defined in Chap 9 of USB spec 1.1   */
/*                                                                            */
/* Purpose  : Return requested descriptor                                     */
/*                                                                            */
/* Author   :                                                                 */
/*                                                                            */
/* Comment  : USB_REQUEST_RET and USB_REQUEST_ARGS are defined in usb_req.h   */
/*            header file                                                     */
/*============================================================================*/

USB_REQUEST_RET USB_reqGetDescriptor(USB_REQUEST_ARGS)
{
  Uint16 ii;
  Uint16 inout_flag;

  switch(USB_Setup->wValue>>8)
  {
    case USB_DESCRIPTOR_DEVICE:         // send device descriptor
    
         ii = device_descriptor[1]&0xFF;

         {
           // select the smaller of two
           ii = (ii < USB_Setup->wLength) ? ii : USB_Setup->wLength;  
           USB_postTransaction(hInEp, ii, (void *)&device_descriptor[0], USB_IOFLAG_NONE);
         }
         break;    

    case USB_DESCRIPTOR_CONFIG: // send config descriptor
    
         // config descriptor is made of linked lists
         inout_flag = (USB_IOFLAG_LNK | USB_IOFLAG_CAT);
         ii = configuration_descriptor[2];
         if((ii == USB_Setup->wLength) || ((USB_Setup->wLength%64) == 0)) // patch 07/31 $MH$
           inout_flag |= USB_IOFLAG_NOSHORT;
         
         // select the smaller of two
         ii = (ii < USB_Setup->wLength) ? ii : USB_Setup->wLength; 
         USB_postTransaction(hInEp, ii, &configuration_descriptor_link, inout_flag);
         break;

    case USB_DESCRIPTOR_STRING:         // send string descriptor

         if((USB_Setup->wValue & 0xFF) == 0) // LANGID Language Codes
         {
           ii = string_descriptor_langid[1] & 0xFF;
           // select the smaller of the two
           ii = (ii < USB_Setup->wLength) ? ii : USB_Setup->wLength;
           USB_postTransaction(hInEp, ii, &string_descriptor_langid[0], USB_IOFLAG_NONE);
         }
         else
         {
           // strlen of the string requested
           ii = (strlen(string_descriptor[USB_Setup->wValue & 0xFF])*2)-2 ;
           // select the smaller of the two
           ii = (ii < USB_Setup->wLength) ? ii : USB_Setup->wLength;
           
           // Insert descriptor type and length in first two bytes of string dscr
           string_descriptor[USB_Setup->wValue&0xFF][1] = (USB_DESCRIPTOR_STRING<<8) | ii;
           USB_postTransaction(hInEp, ii, &string_descriptor[USB_Setup->wValue&0xFF][0], USB_IOFLAG_NONE);
         }
         break;
        
    default: return(USB_REQUEST_STALL);
  }

  return(USB_REQUEST_GET_ACK);
}

/******************************************************************************/
/* Name     : USB_reqUnknown                                                  */
/*                                                                            */
/* Catagory :                                                                 */
/*                                                                            */
/* Purpose  : Respond to unknown requests                                     */
/*                                                                            */
/* Author   :                                                                 */
/*                                                                            */
/* Comment  : USB_REQUEST_RET and USB_REQUEST_ARGS are defined in usb_req.h   */
/*            header file                                                     */
/*============================================================================*/

USB_REQUEST_RET USB_reqUnknown(USB_REQUEST_ARGS)
{
  USB_REQUEST_RET ret_stat = USB_REQUEST_DONE;

  if(USB_Setup->New)
  {
    // The request is either not known or not supported.
    // Request the usb control endpoint handler (usb_ctl( )) to stall the endpoint
    ret_stat = USB_REQUEST_STALL;
  }

  return(ret_stat);
}


/******************************************************************************/
/*                                                                            */
/*              Add user definded USB request handler below                   */
/*                                                                            */
/******************************************************************************/

⌨️ 快捷键说明

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