📄 usb.c
字号:
//***********************************************************************
// *
// P H I L I P S P R O P R I E T A R Y *
// *
// COPYRIGHT (c) 1999 BY PHILIPS SINGAPORE (APIC). *
// -- ALL RIGHTS RESERVED -- *
// *
// File Name : USBDebug.c *
// Author : Albert Goh *
// Created : 3 March 2000 *
// *
//***********************************************************************
//***********************************************************************
// *
// USBDebug has the ability to test the USB core in Bus enumeration or *
// in CBI/bulk mode. *
// *
//***********************************************************************
//***********************************************************************
// *
// Module History *
// ************** *
// *
// Date Version Author Changes *
// ==== ======= ====== ======= *
// 030300 0.1 Albert Created *
// *
//***********************************************************************
//***********************************************************************
//* *
//* Include Files Definition *
//* *
//***********************************************************************
#include "standard.h"
#include "Kernel.h"
#include "D14.h"
#include "usb.h"
extern volatile D14_CNTRL_REG xdata D14_Cntrl_Reg;
extern void Init_D14(void);
extern UC code Standard_Device_Descriptor[];
extern UC code FS_Default_Interface_Descriptor[];
extern UC code HS_Default_Interface_Descriptor[];
extern UC code Standard_Config_Descriptor[];
extern UC code Standard_Manufacturer_String[];
extern UC code Standard_Product_String[];
extern UC code Standard_String_ID[];
extern UC code Bulk_In_Descriptor[];
extern UC code Bulk_Out_Descriptor[];
extern UC code HS_Device_Descriptor[];
extern UC code HS_Device_Qualifier[];
extern UC code HS_Bulk_In_Descriptor[];
extern UC code HS_Bulk_Out_Descriptor[];
extern UC code Other_Speed_Config_Descriptor[];
extern UI count;
extern void Start_mSEC_Timer(Data);
extern void Start_SEC_Timer(Data);
extern void Check_Busy(void);
extern void TaskFile_Update(void);
extern UI Temp;
extern UC Device_Config_Value;
extern KERNEL Kernel_Flag;
extern DMA_INT_FLAG DMA_Int_Flag;
extern USB_INT_FLAG USB_Int_Flag;
extern USBCBW USB_CBW;
extern void Init_Device(void);
extern UC code Test_Packet[];
extern void Init_Endpoint(void);
extern void Get_CBW(void);
extern void Init_Device(void);
//***********************************************************************
//* *
//* Prototype Routine Definition *
//* *
//***********************************************************************
void USB_Setup(void);
void fn_Not_Implemented(void);
void Send_Device_Status(void);
void Send_Interface_Status(void);
void Send_Endpoint_Status(void);
void Send_Device_Descriptor(void);
void Send_Config_Descriptor(void);
void Send_String_ID(void);
void Send_Manufacturer_String(void);
void Send_Product_String(void);
void Send_Endpoint_Descriptor(void);
void Send_Device_Qualifier_Descriptor(void);
void Send_Other_Speed_Config_Descriptor(void);
void Set_Device_Address(void);
void Set_Config_Value(void);
void Get_Config_Value(void);
void Clear_Feature_Request(void);
void Get_Status_Request(void);
void Set_Feature_Request(void);
void Get_Interface_Value(void);
void Set_Interface_Value(void);
void Vendor_Specific_Command(void);
//***********************************************************************
//* *
//* Variable Definition *
//* *
//***********************************************************************
USB_INT_FLAG USB_Int_Flag;
USB_DEVICE_REQ idata USB_Device_Request;
USB_DEVICE USB_Device;
UC code *Descriptor_Ptr;
UC idata Endpt_FIFO[64];
//***********************************************************************
//* *
//* Routine Definition *
//* *
//***********************************************************************
//***********************************************************************
//* *
//* Routine : USB Debug Mode *
//* Input : USB Interrupt Register *
//* Output : None *
//* Function : Branch to respective ISR *
//* *
//***********************************************************************
void USB_Debug_Mode(void)
{
//check for setup token
if(USB_Int_Flag.BITS.EP0SETUP)
USB_Setup();
//check for suspend
if(USB_Int_Flag.BITS.SUSP && !USB_Int_Flag.BITS.RESUME)
{
//Clear Suspend interrupt bit
USB_Int_Flag.BITS.SUSP = 0;
Start_mSEC_Timer(400);
if(!D14_Cntrl_Reg.D14_MODE.BITS.VBUS_STATUS &&
D14_Cntrl_Reg.D14_MODE.BITS.SOFTCT)
{
D14_Cntrl_Reg.D14_MODE.BITS.SOFTCT = 0;
RESET_IDE = 0;
Start_mSEC_Timer(10);
RESET_IDE = 1;
}
//Activate ISp1581 into suspend mode
D14_Cntrl_Reg.D14_MODE.BITS.GOSUSP = 1;
D14_Cntrl_Reg.D14_MODE.BITS.GOSUSP = 0;
#ifdef HID_DEFINED
Start_mSEC_Timer(5);
EX1 = 1;
#endif
}
if(USB_Int_Flag.BITS.RESUME && !USB_Int_Flag.BITS.SUSP)
{
//clear resume interrupt bit
USB_Int_Flag.BITS.RESUME = 0;
//unlock the ISP1581 register
D14_Cntrl_Reg.D14_UNLOCK_DEVICE_LSB = 0x37;
D14_Cntrl_Reg.D14_UNLOCK_DEVICE_MSB = 0xAA;
}
if(USB_Int_Flag.BITS.HS_STAT)
{
//Clear the High speed status change bit
USB_Int_Flag.BITS.HS_STAT = 0;
//switch on high speed LED
HS_FS_LED = HIGH_SPEED_LED;
if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
{
//set device state to high speed state
Kernel_Flag.BITS.HS_FS_State = HIGH_SPEED;
//reconfigure endpoint to high speed endpoint
Init_Endpoint();
}
}
}
//***********************************************************************
//* *
//* Routine : *
//* Input : None *
//* Output : None *
//* Function : *
//* *
//***********************************************************************
void USB_Setup(void)
{
//clear setup token interrupt bit
USB_Int_Flag.BITS.EP0SETUP = 0;
Kernel_Flag.BITS.Bus_Reset = 0;
//select the setup endpoint and read in the device request
D14_Cntrl_Reg.D14_ENDPT_INDEX = 0x20;
USB_Device_Request.bmRequestType = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
USB_Device_Request.bRequest = D14_Cntrl_Reg.D14_DATA_PORT_MSB;
USB_Device_Request.wValue = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
USB_Device_Request.wValue <<= 8;
USB_Device_Request.wValue |= D14_Cntrl_Reg.D14_DATA_PORT_MSB;
USB_Device_Request.wIndex = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
USB_Device_Request.wIndex <<= 8;
USB_Device_Request.wIndex |= D14_Cntrl_Reg.D14_DATA_PORT_MSB;
USB_Device_Request.wLength = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
USB_Device_Request.wLength <<= 8;
USB_Device_Request.wLength |= D14_Cntrl_Reg.D14_DATA_PORT_MSB;
Temp = USB_Device_Request.wLength;
USB_Device_Request.wLength = 0;
USB_Device_Request.wLength = (UC) Temp;
USB_Device_Request.wLength <<= 8;
Temp >>= 8;
USB_Device_Request.wLength |= Temp;
//check if the device request is vendor or class specific
if(USB_Device_Request.bmRequestType == 0xC0 ||
USB_Device_Request.bmRequestType == 0x40 ||
USB_Device_Request.bmRequestType == 0xA1 ||
USB_Device_Request.bmRequestType == 0x21)
{
//Vendor and Classs request routine
Vendor_Specific_Command();
return;
}
//decode device reuest
switch(USB_Device_Request.bRequest)
{
case Get_Descriptor :
switch(USB_Device_Request.wValue)
{
case USB_Device_Descriptor :
Send_Device_Descriptor();
break;
case USB_Config_Descriptor_1 :
case USB_Config_Descriptor_0 :
Send_Config_Descriptor();
break;
case USB_String_ID_Descriptor :
Send_String_ID();
break;
case Manufacturer_String_Descriptor :
Send_Manufacturer_String();
break;
case Product_String_Descriptor :
Send_Product_String();
break;
case USB_Interface_Descriptor :
fn_Not_Implemented();
break;
case USB_Endpoint_Descriptor :
Send_Endpoint_Descriptor();
break;
case USB_Device_Qualifier_Descriptor :
Send_Device_Qualifier_Descriptor();
break;
case USB_Other_Speed_Config_Descriptor :
Send_Other_Speed_Config_Descriptor();
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -