📄 usb_processor.c
字号:
/******************************************************************************
*
* (c) copyright Freescale Semiconductor Hong Kong Ltd 2004
* ALL RIGHTS RESERVED
*
*******************************************************************************
** THIS CODE IS ONLY INTENDED AS AN EXAMPLE FOR DEMONSTRATING THE FREESCALE **
** MICROCONTROLLERS. IT HAS ONLY BEEN GIVEN A MIMIMUM LEVEL OF TEST. IT IS **
** PROVIDED 'AS SEEN' WITH NO GUARANTEES AND NO PROMISE OF SUPPORT. **
*******************************************************************************
*
* FILE: usb_processor.c REVISION 0.1
*
* DESCRIPTION: This module handles the USB state machine & command processor
* applicaton tasks for the system
*
* NOTES: All modules remain at their reset addresses
*
* UPDATED HISTORY:
*
* REV YYYY.MM.DD AUTHOR DESCRIPTION OF CHANGE
* --- ---------- ------ ---------------------
* 0.0 2003.03.01 Vincent Ko Initial version
* 0.1 2004.04.12 Derek Lau Demo version
*
******************************************************************************/
/* Freescale is not obligated to provide any support, upgrades or new */
/* releases of the Software. Freescale may make changes to the Software at */
/* any time, without any obligation to notify or provide updated versions of */
/* the Software to you. Freescale expressly disclaims any warranty for the */
/* Software. The Software is provided as is, without warranty of any kind, */
/* either express or implied, including, without limitation, the implied */
/* warranties of merchantability, fitness for a particular purpose, or */
/* non-infringement. You assume the entire risk arising out of the use or */
/* performance of the Software, or any systems you design using the software */
/* (if any). Nothing may be construed as a warranty or representation by */
/* Freescale that the Software or any derivative work developed with or */
/* incorporating the Software will be free from infringement of the */
/* intellectual property rights of third parties. In no event will Freescale */
/* be liable, whether in contract, tort, or otherwise, for any incidental, */
/* special, indirect, consequential or punitive damages, including, but not */
/* limited to, damages for any loss of use, loss of time, inconvenience, */
/* commercial loss, or lost profits, savings, or revenues to the full extent */
/* such may be disclaimed by law. The Software is not fault tolerant and is */
/* not designed, manufactured or intended by Freescale for incorporation */
/* into products intended for use or resale in on-line control equipment in */
/* hazardous, dangerous to life or potentially life-threatening environments */
/* requiring fail-safe performance, such as in the operation of nuclear */
/* facilities, aircraft navigation or communication systems, air traffic */
/* control, direct life support machines or weapons systems, in which the */
/* failure of products could lead directly to death, personal injury or */
/* severe physical or environmental damage (High Risk Activities). You */
/* specifically represent and warrant that you will not use the Software or */
/* any derivative work of the Software for High Risk Activities. */
/* Freescale and the Freescale logos are registered trademarks of Freescale */
/* Semiconductor Inc. */
/*****************************************************************************/
#include "FreescaleDef.h" // Get my definitions (Constants & Macros)
#include "UF32reg.h" // Get the UF32 registers.
#include "mk_extern.h" // Get Mini-Kernel global prototypes
#include "usb_includes.h" // Get USB module Configuration
#include "usb_extern.h" // Get External variable
#include "usb_descriptor.h" // Get USB Descriptor
// code is placed in the main code area.
#pragma CODE_SEG DEFAULT
//#pragma CODE_SEG CodeForceToPseudo_ROM2
// ===========================================================
// Recipient() -
//
// Decode the recipient
//
// ===========================================================
muint8 Recipient(muint8 bmRequest) {
return bmRequest&0x0f;
};
// ===========================================================
// USB_DecodeSETUP() -
//
// Decode the setup packet
//
// ===========================================================
void USB_DecodeSETUP(volatile muint8 *p_Packet) {
muint8 Type;
muint8 Index;
muint16 Length, ThisLen;
// muint8 This_Config=0; // Current active Configuration
// muint8 This_Interface=1; // Current active Interface
// muint8 This_AS=1; // Current active Alternative Setting
// muint8 This_EP; // Current active Endpoint
Length = (muint16)(*(p_Packet+wLength_h) <<8) + *(p_Packet+wLength_l); // Decode wLength
switch (p_Packet[bRequest])
{
case GET_DESCRIPTOR:
Type = p_Packet[wValue_h];
Index = p_Packet[wValue_l];
switch (Type)
{
case DEVICE:
ThisLen = USB_GetMin(Device_Descriptor[0],Length);
USB_Move2LocalBuffer((muint8*) Device_Descriptor,(muint8*)USB_SetBufferPtr(PHY1IN),ThisLen);
break;
case CONFIGURATION:
ThisLen = USB_GetMin(((muint16) Configuration_DescriptorHS[3] << 8) | Configuration_DescriptorHS[2],Length);
USB_Move2LocalBuffer((muint8*)Configuration_Table[gUSBFullSpeed][Index],(muint8*)USB_SetBufferPtr(PHY1IN),ThisLen);
break;
case STRING:
ThisLen = USB_GetMin(String_Table[Index][0],Length);
USB_Move2LocalBuffer((muint8*)String_Table[Index],(muint8*)USB_SetBufferPtr(PHY1IN),ThisLen);
break;
case INTERFACE:
ThisLen = USB_GetMin(Interface_Table[Index-1][0],Length);
USB_Move2LocalBuffer((muint8*)Interface_Table[Index-1],(muint8*)USB_SetBufferPtr(PHY1IN),ThisLen);
break;
case ENDPOINT:
ThisLen = USB_GetMin(Endpoint_Table[gUSBFullSpeed][Index-1][0],Length);
USB_Move2LocalBuffer((muint8*)Endpoint_Table[gUSBFullSpeed][Index-1],(muint8*)USB_SetBufferPtr(PHY1IN),ThisLen);
break;
case DEVICE_QUALIFIER:
ThisLen = USB_GetMin(Device_Qualifier[0],Length);
USB_Move2LocalBuffer((muint8*)Device_Qualifier,(muint8*)USB_SetBufferPtr(PHY1IN),ThisLen);
break;
case OTHER_SPEED_CONFIGURATION:
ThisLen = USB_GetMin((((muint16) Other_Speed_Descriptor[3]) << 8) | (muint16) Other_Speed_Descriptor[2],Length);
USB_Move2LocalBuffer((muint8*)Configuration_DescriptorFS,(muint8*)USB_SetBufferPtr(PHY1IN),ThisLen);
USB_Move2LocalBuffer((muint8*)Other_Speed_Descriptor,(muint8*)USB_SetBufferPtr(PHY1IN),2);
break;
};
do
{
UEPCSR0 = 0x5000 | ThisLen;
}
while (!(UEPCSR0 & 0x4000)); // Enable DAVLID bit
break;
case GETMAXLUN:
*(USB_SetBufferPtr(PHY1IN)) = (kNumberOfDevice-1); // Return the value of LUN
do
{
UEPCSR0 = 0x5000 | 0x01; // wLength = 1
}
while (!(UEPCSR0 & 0x4000));
break;
// case BOMS_RESET:
// break;
// case SET_DESCRIPTOR:
// break;
// case SYNCH_FRAME:
// break;
default:
break;
// SET_ADDRESS,
// GET_STATUS:
// GET_CONFIGURATION:
// SET_CONFIGURATION:
// GET_INTERFACE:
// SET_INTERFACE:
};
};
//
// The end of file usb_processor.c
// *********************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -