📄 usb_req.c
字号:
/******************************************************************************/
/* Copyright (C) 2001 Texas Instruments, Inc. All Rights Reserved. */
/* */
/* File Name : usb_req.c */
/* Project : TMS320VC5509 USB Module Support */
/* Author : C5000 H/W Applications */
/* */
/* Version : 0.1 */
/* Date : 30 Apr 2001 */
/* Updated : */
/* */
/* Description : USB Chapter 9 standard device request handlers. */
/* Users can expand the USB request handling capabilities by */
/* adding new members in the USB request table and supplying */
/* associated request handler routines. */
/* */
/******************************************************************************/
#include "string.h"
#include "csl_usb.h"
#include "usb_req.h"
Uint16 usbCurDevStat = 0x01; // Self Powered
Uint16 usbCurConfigStat = 0x00; // Device start with config = 0
Uint16 usbCurIntrfcStat = 0x00; // Only interface 0 supported
Uint16 usbCurAltSetStat = 0x00; // default Alt Setting = 0
Uint16 gen_purpose_buffer[5]; // first 2 bytes for xfer byte count
// next 8 bytes are for usb data
/******************************************************************************/
/* */
/* USB descriptors defined in usb_catdscr.c */
/* */
/******************************************************************************/
extern const Uint16 device_descriptor[];
extern const Uint16 configuration_descriptor[];
extern USB_DataStruct configuration_descriptor_link;
extern Uint16 string_descriptor_langid[];
extern char *string_descriptor[];
/******************************************************************************/
/* */
/* USB Request Table. USB control(enpoint0) parse through this */
/* table and calls the routine that matches the request sent by */
/* the host. */
/* */
/******************************************************************************/
USB_request_struct USB_ReqTable[] =
{
{ USB_REQUEST_GET_STATUS , USB_reqGetStatus },
{ USB_REQUEST_CLEAR_FEATURE , USB_reqClearFeature },
{ USB_REQUEST_SET_FEATURE , USB_reqSetFeature },
{ USB_REQUEST_SET_ADDRESS , USB_reqSetAddress },
{ USB_REQUEST_GET_DESCRIPTOR , USB_reqGetDescriptor },
{ USB_REQUEST_SET_DESCRIPTOR , USB_reqUnknown }, // not supported
{ USB_REQUEST_GET_CONFIGURATION , USB_reqGetConfiguration },
{ USB_REQUEST_SET_CONFIGURATION , USB_reqSetConfiguration },
{ USB_REQUEST_GET_INTERFACE , USB_reqGetInterface }, // not supported
{ USB_REQUEST_SET_INTERFACE , USB_reqSetInterface},
{ USB_REQUEST_SYNC_FRAME , USB_reqUnknown }, // not supported
//
// place holder for adding more request handlers
//
{ 0, NULL } // request handler table must terminate with a NULL member
};
/******************************************************************************/
/* Name : USB_reqSetAddress */
/* */
/* Catagory : Standard Request Handler as defined in Chap 9 of USB spec 1.1 */
/* */
/* Purpose : Set device address */
/* */
/* Author : */
/* */
/* Comment : USB_REQUEST_RET and USB_REQUEST_ARGS are defined in usb_req.h */
/* header file */
/*============================================================================*/
USB_REQUEST_RET USB_reqSetAddress(USB_REQUEST_ARGS)
{
// set new device address sent in the wValue field of the setup packet
USB_setDevAddr(DevNum, (Uint16)(USB_Setup->wValue));
// request usb_ctl( ), usb control endpoint handler routine, to complete
// the setup transaction with a 0-byte acknowledgement
return(USB_REQUEST_SEND_ACK);
}
/******************************************************************************/
/* Name : USB_reqSetConfiguration */
/* */
/* Catagory : Standard Request Handler as defined in Chap 9 of USB spec 1.1 */
/* */
/* Purpose : Set/clear active configuration of the USB device */
/* */
/* Author : */
/* */
/* Comment : USB_REQUEST_RET and USB_REQUEST_ARGS are defined in usb_req.h */
/* header file */
/*============================================================================*/
USB_REQUEST_RET USB_reqSetConfiguration(USB_REQUEST_ARGS)
{
USB_REQUEST_RET ret_stat;
// single configuration supported only
if((USB_Setup->wValue == 0) || (USB_Setup->wValue == 1))
{
usbCurConfigStat = USB_Setup->wValue;
ret_stat = USB_REQUEST_SEND_ACK;
}
else
{
// configuration not supported, request usb_ctl( ), the usb control
// endpoint handler routine to stall the endpoint
ret_stat = USB_REQUEST_STALL;
}
return(ret_stat);
}
/******************************************************************************/
/* Name : USB_reqSetInterface */
/* */
/* Catagory : Standard Request Handler as defined in Chap 9 of USB spec 1.1 */
/* */
/* Purpose : Set/clear active interface of the USB device */
/* */
/* Author : */
/* */
/* Comment : USB_REQUEST_RET and USB_REQUEST_ARGS are defined in usb_req.h */
/* header file */
/*============================================================================*/
USB_REQUEST_RET USB_reqSetInterface(USB_REQUEST_ARGS)
{
USB_REQUEST_RET ret_stat = USB_REQUEST_STALL;
// decode the requested feature
// only Interface 0 and single configuration supported
if((USB_Setup->wIndex == 0) && (usbCurConfigStat == 1))
{
if((USB_Setup->wValue == 0) || (USB_Setup->wValue == 1))
{
usbCurAltSetStat = USB_Setup->wValue;
ret_stat = USB_REQUEST_SEND_ACK;
}
}
return(ret_stat);
}
/******************************************************************************/
/* Name : USB_reqClearFeature */
/* */
/* Catagory : Standard Request Handler as defined in Chap 9 of USB spec 1.1 */
/* */
/* Purpose : Clear standard device features */
/* */
/* Author : */
/* */
/* Comment : USB_REQUEST_RET and USB_REQUEST_ARGS are defined in usb_req.h */
/* header file */
/*============================================================================*/
USB_REQUEST_RET USB_reqClearFeature(USB_REQUEST_ARGS)
{
USB_EpHandle hEPx;
Uint16 Endpt;
USB_REQUEST_RET ret_stat = USB_REQUEST_SEND_ACK;
// decode the requested feature
switch(USB_Setup->wValue)
{
case USB_FEATURE_ENDPOINT_STALL:
{
// retrieve the endpoint number
Endpt = (USB_Setup->wIndex) & 0xFF;
// retrieve the handle associated with the endpoint
hEPx = USB_epNumToHandle(USB0, Endpt);
// stall the endpoint
USB_clearEndptStall(hEPx);
break;
}
case USB_FEATURE_REMOTE_WAKEUP:
{
// disable remote wakeup
USB_setRemoteWakeup(USB0, USB_FALSE);
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_reqGetStatus */
/* */
/* 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_reqGetStatus(USB_REQUEST_ARGS)
{
USB_EpHandle hEPx;
Uint16 Endpt; // this is USB logical endpoint
USB_REQUEST_RET ret_stat = USB_REQUEST_GET_ACK;
switch(USB_Setup->bmRequestType - 0x80)
{
case 0: // return Device Status
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -