?? f320_usb_standard_requests.c
字號:
//-----------------------------------------------------------------------------
// F320_USB_Standard_Requests.c
//-----------------------------------------------------------------------------
// Copyright 2005 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This is the module that handles USB standard requests. These requests are
// defined in chapter nine of the USB specification.
//
// FID: 32X000064
// Target: C8051F320
// Tool chain: KEIL C51 7.0.0.1 / KEIL A51 7.0.0.1
// Silicon Laboratories IDE version 2.3
// Command Line: See Readme.txt
// Project Name: F320_DEFAULT
//
// Release 1.0
// -Initial Revision (PD)
// -05 JUL 2006
//
//
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "c8051f320.h" // SFR declarations
#include "F320_DEFAULT.h" // Main project header
#include "F320_USB_Register.h" // USB core register header
#include "F320_USB_Common.h" // USB protocol header
#include "F320_USB_Descriptor.h" // USB descriptor definitions
//-----------------------------------------------------------------------------
// Variable Declaration
//-----------------------------------------------------------------------------
idata BYTE Selected_Interface1;
//-----------------------------------------------------------------------------
// Get_Status
//
// Return Value : None
// Parameters : None
//
// Returns status information for a given device, interface, or endpoint by
// sending a two byte status packet to the host.
//
//-----------------------------------------------------------------------------
void Get_Status (void) using USB_REGISTER_BANK
{
// If non-zero return length or data length not equal to 2 then send a stall
// indicating invalid request
if ((Setup.wValue.i != 0) || (Setup.wLength.i != 2))
{
Force_Stall ();
}
switch (Setup.bmRequestType) // Determine intended recipient
{
case OUT_DEVICE: // If recipient was device
// Stall if invalid request otherwise send 0x0000, indicating bus
// power and no remote wake-up
if (Setup.wIndex.i != 0) Force_Stall();
else DataPtr = (BYTE*)&ZERO_PACKET;
break;
case OUT_INTERFACE: // See if recipient was interface
// Send stall if invalid command otherwise return 0x0000
if ((USB_State != DEV_CONFIGURED) || (Setup.wIndex.i != 0))
{
Force_Stall();
}
else DataPtr = (BYTE*)&ZERO_PACKET;
break;
case OUT_ENDPOINT: // See if recipient was an endpoint
// Make sure device is configured and index msb = 0x00 otherwise
// return stall to host
if ((USB_State != DEV_CONFIGURED) || (Setup.wIndex.c[MSB]))
{
Force_Stall();
}
else
{
switch (Setup.wIndex.c[LSB])
{
case IN_EP1:
if (Ep_Status[1] == EP_HALT) DataPtr = (BYTE*)&ONES_PACKET;
else DataPtr = (BYTE*)&ZERO_PACKET;
DataSize = 2;
break;
case OUT_EP2:
if (Ep_Status[2] == EP_HALT) DataPtr = (BYTE*)&ONES_PACKET;
else DataPtr = (BYTE*)&ZERO_PACKET;
DataSize = 2;
break;
case IN_EP3:
if (Ep_Status[3] == EP_HALT) DataPtr = (BYTE*)&ONES_PACKET;
else DataPtr = (BYTE*)&ZERO_PACKET;
DataSize = 2;
break;
default: Force_Stall (); break;
}
}
break;
default:
Force_Stall ();
break;
}
if (Ep_Status[0] != EP_STALL)
{
// Set serviced setup packet bit, put endpoint in transmit mode, reset
// data sent counter to 0 set data size to 2
POLL_WRITE_BYTE (E0CSR, rbSOPRDY);
Ep_Status[0] = EP_TX;
DataSent = 0;
DataSize = 2;
}
}
//-----------------------------------------------------------------------------
// Clear_Feature
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// This routine can clear Halt Endpoint features for data endpoints.
//
//-----------------------------------------------------------------------------
void Clear_Feature (void) using USB_REGISTER_BANK
{
// Make sure device is configured, endpoint is recipient, and halt endpoint
// feature is selected
if ((USB_State != DEV_CONFIGURED) || (Setup.bmRequestType != IN_ENDPOINT) ||
(Setup.wValue.i != ENDPOINT_HALT) || (Setup.wLength.i != 0))
{
Force_Stall (); // Otherwise send stall to host
}
else
{
switch (Setup.wIndex.c[LSB])
{
case IN_EP1:
POLL_WRITE_BYTE (INDEX, 1);
// Clear feature endpoint 1 halt
POLL_WRITE_BYTE (EINCSR1, rbInCLRDT);
Ep_Status[1] = EP_IDLE; // Set endpoint 1 status back to idle
break;
case OUT_EP2:
POLL_WRITE_BYTE (INDEX, 2);
// Clear feature endpoint 2 halt
POLL_WRITE_BYTE (EOUTCSR1, rbOutCLRDT);
Ep_Status[2] = EP_IDLE; // Set endpoint 2 status back to idle
break;
case IN_EP3:
POLL_WRITE_BYTE (INDEX, 3);
// Clear feature endpoint 3 halt
POLL_WRITE_BYTE (EINCSR1, rbInCLRDT);
Ep_Status[3] = EP_IDLE; // Set endpoint 3 status back to idle
break;
default: Force_Stall (); break;
}
}
POLL_WRITE_BYTE (INDEX, 0); // Reset Index to 0
// Indicate setup packet has been serviced
if (Ep_Status[0] != EP_STALL) POLL_WRITE_BYTE (E0CSR, rbSOPRDY);
}
//-----------------------------------------------------------------------------
// Set_Feature
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// This routine will set the EP Halt feature for data endpoints
//
//-----------------------------------------------------------------------------
void Set_Feature (void) using USB_REGISTER_BANK
{
// Make sure device is configured, endpoint is recipient, and halt endpoint
// feature is selected
if ((USB_State != DEV_CONFIGURED) || (Setup.bmRequestType != IN_ENDPOINT) ||
(Setup.wValue.i != ENDPOINT_HALT) || (Setup.wLength.i != 0))
{
Force_Stall (); // Otherwise send stall to host
}
else
{
switch (Setup.wIndex.c[LSB])
{
case IN_EP1:
POLL_WRITE_BYTE (INDEX, 1);
// Set feature endpoint 1 halt
POLL_WRITE_BYTE (EINCSR1, rbInSDSTL);
Ep_Status[1] = EP_HALT; // Set endpoint 1 status to halt
break;
case OUT_EP2:
POLL_WRITE_BYTE (INDEX, 2);
// Set feature endpoint 2 halt
POLL_WRITE_BYTE (EOUTCSR1, rbOutSDSTL);
Ep_Status[2] = EP_HALT; // Set endpoint 2 status to halt
break;
case IN_EP3:
POLL_WRITE_BYTE (INDEX, 3);
// Set feature endpoint 3 halt
POLL_WRITE_BYTE (EINCSR1, rbInSDSTL);
Ep_Status[3] = EP_HALT; // Set endpoint 3 status to halt
break;
default: Force_Stall (); break;
}
}
POLL_WRITE_BYTE (INDEX, 0); // Reset Index to 0
// Indicate setup packet has been serviced
if (Ep_Status[0] != EP_STALL) POLL_WRITE_BYTE (E0CSR, rbSOPRDY);
}
//-----------------------------------------------------------------------------
// Set_Address
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters : None
//
// Set new function address
//
//-----------------------------------------------------------------------------
void Set_Address (void) using USB_REGISTER_BANK
{
// Request must be directed to device with index and length set to zero
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -