📄 usbdebug.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"
#define SETUP_DMA_REQUEST 0x7104
#define GET_FIRMWARE_VERSION 0x7204
#define GET_SET_TWAIN_REQUEST 0x7304
extern volatile D14_CNTRL_REG xdata D14_Cntrl_Reg;
extern void Init_D14(void);
extern UC code FS_Device_Descriptor[];
extern UC code HS_Device_Descriptor[];
extern UC code Device_Qualifier_HS_Info[];
extern UC code Device_Qualifier_FS_Info[];
extern UC code FS_Config_Descriptor[];
extern UC code HS_Config_Descriptor[];
extern UC code Config_Descriptor_HS_Info[];
extern UC code Config_Descriptor_FS_Info[];
extern UC code Standard_Manufacturer_String[];
extern UC code Standard_Product_String[];
extern UC code Standard_String_ID[];
extern UC code HS_Interface_Descriptor_Default[];
extern UC code HS_Interface_Descriptor_Alternate1[];
extern UC code HS_Interface_Descriptor_Alternate2[];
extern UC code HS_Interface_Descriptor_Alternate3[];
extern UC code Interface_Descriptor_Default[];
extern UC code Interface_Descriptor_Alternate1[];
extern UC code Interface_Descriptor_Alternate2[];
extern UC code Iso_In_1024_Descriptor[];
extern UC code Iso_In_1020_Descriptor[];
extern UC code Iso_In_512_Descriptor[];
extern UC code Iso_In_128_Descriptor[];
extern UC code Iso_In_Zero_Descriptor[];
extern UC code Int_In_Descriptor[];
//TEST_BULK
extern UC code Bulk_In_512_Descriptor[];
extern UC code Bulk_In_256_Descriptor[];
extern UC code Bulk_In_64_Descriptor[];
//TEST_BULK
extern UI count;
extern void Start_mSEC_Timer(Data);
extern UI Temp;
UC Device_Config_Value;
extern KERNEL Kernel_Flag;
extern DMA_INT_FLAG DMA_Int_Flag;
extern USB_INT_FLAG USB_Int_Flag;
extern UC code Test_Packet[];
extern void Enable_Endpoint(void);
//***********************************************************************
//* *
//* Prototype Routine Definition *
//* *
//***********************************************************************
void USB_SOF(void);
void USB_uSOF(void);
void USB_DMA_State(void);
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_FS_Configuration_Descriptor(void);
void Send_HS_Configuration_Descriptor(void);
void Send_Product_String(void);
void Send_Manufacturer_String(void);
void Send_String_ID(void);
void Bulk_In(void);
void Bulk_Out(void);
void Control_Out_Endpt(void);
void Control_In_Endpt(void);
void Int_Out(void);
void Int_In(void);
void Iso_Out(void);
void Iso_In(void);
void Set_Configuration(void);
void Get_Configuration(void);
void Set_Interface_Request(void);
void Get_Interface_Request(void);
void Send_Qualifier_Descriptor(void);
void Send_Configuration_Descriptor_FSInfo(void);
void Send_Configuration_Descriptor_HSInfo(void);
//void Get_CBI_Command(void);
void Process_Synch_Frame(void);
extern void Vendor_Specific_Command(void);
extern void Init_Endpoint(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];
UI FIFO_Count;
UC idata File_Number;
UC idata Current_File;
FILESIZE idata FileSize;
ULI bytecount;
//***********************************************************************
//* *
//* Routine Definition *
//* *
//***********************************************************************
//***********************************************************************
//* *
//* Routine : USB Debug Mode *
//* Input : USB Interrupt Register *
//* Output : None *
//* Function : Branch to respective ISR *
//* *
//***********************************************************************
void USB_Debug_Mode(void)
{
if(USB_Int_Flag.BITS.EP0SETUP)
USB_Setup();
if(USB_Int_Flag.VALUE!=0)
{
/* if(USB_Int_Flag.BITS.SOF)
USB_Int_Flag.BITS.SOF=0;
if(USB_Int_Flag.BITS.uSOF)
USB_Int_Flag.BITS.uSOF=0;*/
if(USB_Int_Flag.BITS.SUSP)
{
USB_Int_Flag.BITS.SUSP = 0;//clear flag
D14_Cntrl_Reg.D14_MODE.BITS.GOSUSP = 1;
D14_Cntrl_Reg.D14_MODE.BITS.GOSUSP = 0;
//Write a 1 followed by a 0, activate suspend mode.
}
if(USB_Int_Flag.BITS.RESUME)
{
USB_Int_Flag.BITS.RESUME = 0;
D14_Cntrl_Reg.D14_MODE.BITS.SNDRSU = 1;
D14_Cntrl_Reg.D14_MODE.BITS.SNDRSU = 0;
//Write a 1 followed by a 0, issue a resume signal.
D14_Cntrl_Reg.D14_UNLOCK_DEVICE_LSB = 0x37;
D14_Cntrl_Reg.D14_UNLOCK_DEVICE_MSB = 0xAA;
//Write 0xaa37 to unlock the FIFOs.
}
if(USB_Int_Flag.BITS.HS_STAT)
{
USB_Int_Flag.BITS.HS_STAT = 0;
if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
{
// HS_FS_LED = HIGH_SPEED;
Kernel_Flag.BITS.HS_FS_State = HIGH_SPEED;
Init_Endpoint();
}
}
if(USB_Int_Flag.BITS.DMA)
{
USB_Int_Flag.BITS.DMA = 0;
Kernel_Flag.BITS.Transfer_Start =1;
}
/* if(USB_Int_Flag.BITS.EP0TX)
USB_Int_Flag.BITS.EP0TX = 0;
if(USB_Int_Flag.BITS.EP0RX)
USB_Int_Flag.BITS.EP0RX = 0;//*/
}
}
//***********************************************************************
//* *
//* Routine : *
//* Input : None *
//* Output : None *
//* Function : *
//* *
//***********************************************************************
void USB_Setup(void)
{
USB_Int_Flag.BITS.EP0SETUP = 0; //reset int flag
D14_Cntrl_Reg.D14_ENDPT_INDEX = 0x20;//set index to enable setup buffer.
USB_Device_Request.bmRequestType = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
USB_Device_Request.bRequest = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
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_LSB;
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_LSB;
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_LSB;
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;
if(USB_Device_Request.bmRequestType == 0xC0 || //vender request
USB_Device_Request.bmRequestType == 0x40 || //Vender request
USB_Device_Request.bmRequestType == 0xA1) //Class request
{
Vendor_Specific_Command();
return;
}
switch(USB_Device_Request.bRequest)
{
case Get_Descriptor :
switch(USB_Device_Request.wValue)
{
case 1 : //Device
if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
Descriptor_Ptr = &FS_Device_Descriptor[0]; //set pointer to device descriptor
else
Descriptor_Ptr = &HS_Device_Descriptor[0]; //set pointer to device descriptor
count = *Descriptor_Ptr; //read in descriptor length
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = 0x12;
D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
while(count != 0)
{
D14_Cntrl_Reg.D14_DATA_PORT_LSB = *Descriptor_Ptr; //fill up FIFO
Descriptor_Ptr++;
count--;
};
while(!USB_Int_Flag.BITS.EP0TX);
USB_Int_Flag.BITS.EP0TX = 0;
D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.VALUE = 2;
break;
case 2 : //Configuration
if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
Send_FS_Configuration_Descriptor();
if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
Send_HS_Configuration_Descriptor();
break;
case 3 : //String
Send_String_ID();
break;
case 0x0103 :
Send_Manufacturer_String();
break;
case 0x0203 :
Send_Product_String();
break;
case 6 : //Qualifier_Descriptor
Send_Qualifier_Descriptor();
break;
case 7 : //Other speed
if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
Send_Configuration_Descriptor_HSInfo();
if(Kernel_Flag.BITS.HS_FS_State == HIGH_SPEED)
Send_Configuration_Descriptor_FSInfo();
break;
default :
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
while(!USB_Int_Flag.BITS.EP0SETUP)
{
if(USB_Int_Flag.BITS.SUSP || USB_Int_Flag.BITS.RESET)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
break;
}
break;
case Set_Address :
USB_Int_Flag.BITS.EP0RX = 0;
switch(USB_Device.BITS.State)
{
default :
case USB_Default :
if(USB_Device_Request.wValue > 0)
USB_Device.BITS.State = USB_Addressed;
D14_Cntrl_Reg.D14_ADDRESS.BITS.DEVADDR = (USB_Device_Request.wValue >> 8);
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.VALUE = 2;
//end of status stage
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -