📄 f34x_usb_standard_requests.c
字号:
{
Force_Stall(); // Send procedural stall
}
}
POLL_WRITE_BYTE(INDEX, 0);
if (Ep_Status[0] != EP_STALL)
{
// Indicate setup packet has been serviced
POLL_WRITE_BYTE(E0CSR, rbSOPRDY);
}
}
//-----------------------------------------------------------------------------
// Set_Address
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// Set new function address
//
//-----------------------------------------------------------------------------
void Set_Address(void)
{
if ((Setup.bmRequestType != IN_DEVICE) ||// Request must be directed to device
Setup.wIndex.c[MSB] || Setup.wIndex.c[LSB]||// with index and length set to zero.
Setup.wLength.c[MSB] || Setup.wLength.c[LSB]||
Setup.wValue.c[MSB] || (Setup.wValue.c[LSB] & 0x80))
{
Force_Stall(); // Send stall if setup data invalid
}
Ep_Status[0] = EP_ADDRESS; // Set endpoint zero to update address next status phase
if (Setup.wValue.c[LSB] != 0)
{
USB_State = DEV_ADDRESS; // Indicate that device state is now address
}
else
{
USB_State = DEV_DEFAULT; // If new address was 0x00, return device to default
} // state
if (Ep_Status[0] != EP_STALL)
{
// Indicate setup packet has been serviced
POLL_WRITE_BYTE(E0CSR, rbSOPRDY);
}
}
//-----------------------------------------------------------------------------
// Get_Descriptor
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// This routine sets the data pointer and size to correct
// descriptor and sets the endpoint status to transmit
//
//-----------------------------------------------------------------------------
void Get_Descriptor(void)
{
switch(Setup.wValue.c[MSB]) // Determine which type of descriptor
{ // was requested, and set data ptr and
case DSC_DEVICE: // size accordingly
DataPtr = (BYTE*) &DeviceDesc;
DataSize = DeviceDesc.bLength;
break;
case DSC_CONFIG:
DataPtr = (BYTE*) &ConfigDesc;
// Compiler Specific - The next statement reverses the
// bytes in the configuration descriptor for the compiler
DataSize = ConfigDesc.wTotalLength.c[MSB] + 256*ConfigDesc.wTotalLength.c[LSB];
break;
case DSC_STRING:
DataPtr = StringDescTable[Setup.wValue.c[LSB]];
// Can have a maximum of 255 strings
DataSize = *DataPtr;
break;
case DSC_INTERFACE:
DataPtr = (BYTE*) &InterfaceDesc;
DataSize = InterfaceDesc.bLength;
break;
case DSC_ENDPOINT:
if ((Setup.wValue.c[LSB] == IN_EP1) ||
(Setup.wValue.c[LSB] == OUT_EP2))
{
if (Setup.wValue.c[LSB] == IN_EP1)
{
DataPtr = (BYTE*) &Endpoint1Desc;
DataSize = Endpoint1Desc.bLength;
}
else
{
DataPtr = (BYTE*) &Endpoint2Desc;
DataSize = Endpoint2Desc.bLength;
}
}
else
{
Force_Stall();
}
break;
default:
Force_Stall(); // Send Stall if unsupported request
break;
}
if (Setup.wValue.c[MSB] == DSC_DEVICE || // Verify that the requested descriptor is
Setup.wValue.c[MSB] == DSC_CONFIG || // valid
Setup.wValue.c[MSB] == DSC_STRING ||
Setup.wValue.c[MSB] == DSC_INTERFACE ||
Setup.wValue.c[MSB] == DSC_ENDPOINT)
{
if ((Setup.wLength.c[LSB] < DataSize) &&
(Setup.wLength.c[MSB] == 0))
{
DataSize = Setup.wLength.i; // Send only requested amount of data
}
}
if (Ep_Status[0] != EP_STALL) // Make sure endpoint not in stall mode
{
POLL_WRITE_BYTE(E0CSR, rbSOPRDY); // Service Setup Packet
Ep_Status[0] = EP_TX; // Put endpoint in transmit mode
DataSent = 0; // Reset Data Sent counter
}
}
//-----------------------------------------------------------------------------
// Get_Configuration
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// This routine returns current configuration value
//
//-----------------------------------------------------------------------------
void Get_Configuration(void)
{
if ((Setup.bmRequestType != OUT_DEVICE) ||// This request must be directed to the device
Setup.wValue.c[MSB] || Setup.wValue.c[LSB]||// with value word set to zero
Setup.wIndex.c[MSB] || Setup.wIndex.c[LSB]||// and index set to zero
Setup.wLength.c[MSB] || (Setup.wLength.c[LSB] != 1))// and setup length set to one
{
Force_Stall(); // Otherwise send a stall to host
}
else
{
if (USB_State == DEV_CONFIGURED) // If the device is configured, then return value 0x01
{ // since this software only supports one configuration
DataPtr = (BYTE*)&ONES_PACKET;
DataSize = 1;
}
if (USB_State == DEV_ADDRESS) // If the device is in address state, it is not
{ // configured, so return 0x00
DataPtr = (BYTE*)&ZERO_PACKET;
DataSize = 1;
}
}
if (Ep_Status[0] != EP_STALL)
{
POLL_WRITE_BYTE(E0CSR, rbSOPRDY); // Set Serviced Out Packet bit
Ep_Status[0] = EP_TX; // Put endpoint into transmit mode
DataSent = 0; // Reset Data Sent counter to zero
}
}
//-----------------------------------------------------------------------------
// Set_Configuration
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// This routine allows host to change current device configuration value
//
//-----------------------------------------------------------------------------
void Set_Configuration(void)
{
if ((USB_State == DEV_DEFAULT) ||// Device must be addressed before configured
(Setup.bmRequestType != IN_DEVICE) ||// and request recipient must be the device
Setup.wIndex.c[MSB] || Setup.wIndex.c[LSB]||// the index and length words must be zero
Setup.wLength.c[MSB] || Setup.wLength.c[LSB] ||
Setup.wValue.c[MSB] || (Setup.wValue.c[LSB] > 1))// This software only supports config = 0,1
{
Force_Stall(); // Send stall if setup data is invalid
}
else
{
if (Setup.wValue.c[LSB] > 0) // Any positive configuration request
{ // results in configuration being set to 1
USB_State = DEV_CONFIGURED;
Ep_Status[1] = EP_IDLE; // Set endpoint status to idle (enabled)
Ep_Status[2] = EP_IDLE;
POLL_WRITE_BYTE(INDEX, 1); // Change index to endpoint 1
POLL_WRITE_BYTE(EINCSR2, rbInDIRSEL); // Set DIRSEL to indicate endpoint 1 is IN
Handle_In1(); // Put first data packet on fifo
POLL_WRITE_BYTE(INDEX, 0); // Set index back to endpoint 0
}
else
{
USB_State = DEV_ADDRESS; // Unconfigures device by setting state to
Ep_Status[1] = EP_HALT; // address, and changing endpoint 1 and 2
Ep_Status[2] = EP_HALT; // status to halt
}
}
if (Ep_Status[0] != EP_STALL)
{
// Indicate setup packet has been serviced
POLL_WRITE_BYTE(E0CSR, rbSOPRDY);
}
}
//-----------------------------------------------------------------------------
// Get_Interface
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// This routine returns 0x00, since only one interface is supported by
// this firmware
//
//-----------------------------------------------------------------------------
void Get_Interface(void)
{
if ((USB_State != DEV_CONFIGURED) || // If device is not configured
(Setup.bmRequestType != OUT_INTERFACE) || // or recipient is not an interface
Setup.wValue.c[MSB] ||Setup.wValue.c[LSB] ||// or non-zero value or index fields
Setup.wIndex.c[MSB] ||Setup.wIndex.c[LSB] ||// or data length not equal to one
Setup.wLength.c[MSB] ||(Setup.wLength.c[LSB] != 1))
{
Force_Stall(); // Then return stall due to invalid request
}
else
{
DataPtr = (BYTE*)&ZERO_PACKET; // Otherwise, return 0x00 to host
DataSize = 1;
}
if (Ep_Status[0] != EP_STALL)
{
POLL_WRITE_BYTE(E0CSR, rbSOPRDY); // Set Serviced Setup packet, put endpoint in transmit
Ep_Status[0] = EP_TX; // mode and reset Data sent counter
DataSent = 0;
}
}
//-----------------------------------------------------------------------------
// Set_Interface
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// This routine allows host to change current device configuration value
//
//-----------------------------------------------------------------------------
void Set_Interface(void)
{
// Make sure request is directed at interface and all other packet values
// are set to zero
if ((Setup.bmRequestType != IN_INTERFACE) ||
Setup.wLength.c[MSB] ||Setup.wLength.c[LSB]||
Setup.wValue.c[MSB] ||Setup.wValue.c[LSB] ||
Setup.wIndex.c[MSB] ||Setup.wIndex.c[LSB])
{
// Otherwise send a stall to host
Force_Stall();
}
if (Ep_Status[0] != EP_STALL)
{
// Indicate setup packet has been serviced
POLL_WRITE_BYTE(E0CSR, rbSOPRDY);
}
}
//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -