?? chap_9.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 Bulk_Interface_Descriptor[];
extern UC code Iso_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 Int_In_Descriptor[];
extern UC code Int_Out_Descriptor[];
extern UC code Iso_In_Descriptor[];
extern UC code Iso_Out_Descriptor[];
extern UC code Iso_In_Zero_Descriptor[];
extern UC code Iso_Out_Zero_Descriptor[];
extern UC code HS_Device_Descriptor[];
extern UC code HS_Device_Qualifier[];
extern UC code HS_Bulk_Interface_Descriptor[];
extern UC code HS_Bulk_In_Descriptor[];
extern UC code HS_Bulk_Out_Descriptor[];
extern UC code HS_Int_In_Descriptor[];
extern UC code HS_Int_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 Init_Device(void);
extern void Set_USB(void);
//***********************************************************************
//* *
//* Prototype Routine Definition *
//* *
//***********************************************************************
void USB_Setup(void);
void reserved(void);
void Send_Device_Status(void);
void Send_Interface_Status(void);
void Send_Endpoint_Status(void);
void Vendor_Specific_Command(void);
void Send_Status(unsigned char tran_status);
void Set_Interface_Value(void);
void Get_Interface_Value(void);
void Process_Synch_Frame(void);
void get_status(void);
void clear_feature(void);
void set_feature(void);
void set_address(void);
void get_descriptor(void);
void get_config(void);
void set_config(void);
void get_interface(void);
void set_interface(void);
void Set_Descriptor(void);
void reserved(void);
void ep0in_ack(void);
void ep0out_ack(void);
void wait_ep0tx(void);
void wait_ep0rx(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[MAX_BUF];
UI FIFO_Count;
UC VID[2],PID[2];
FILESIZE FileSize;
UI PIO_Count;
UC File_Number;
UC Current_File;
ULI bytecount;
//USB標準請求
code void (*StandardDeviceRequest[])(void) =
{
get_status,
clear_feature,
reserved,
set_feature,
reserved,
set_address,
get_descriptor,
reserved,
get_config,
set_config,
get_interface,
set_interface,
reserved,
reserved,
reserved,
reserved
};
//***********************************************************************
//* *
//* Routine Definition *
//* *
//***********************************************************************
//***********************************************************************
//* *
//* Routine : USB Debug Mode *
//* Input : USB Interrupt Register *
//* Output : None *
//* Function : Branch to respective ISR *
//* *
//***********************************************************************
void USB_Debug_Mode(void)
{
//端點0接收到setup包處理
if(USB_Int_Flag.BITS.EP0SETUP)
{
EA_DISABLE;
USB_Setup();
EA_ENABLE;
}
//掛起處理
if(USB_Int_Flag.BITS.SUSP)
{
//清除掛起標志
EA_DISABLE;
USB_Int_Flag.BITS.SUSP = 0;
EA_ENABLE;
//ISP1581進入掛起狀態
D14_Cntrl_Reg.D14_MODE.BITS.GOSUSP = 1;
D14_Cntrl_Reg.D14_MODE.BITS.GOSUSP = 0;
}
//掛起恢復處理
if(USB_Int_Flag.BITS.RESUME)
{
//清除恢復標志
EA_DISABLE;
USB_Int_Flag.BITS.RESUME = 0;
EA_ENABLE;
//產生一個恢復信號
D14_Cntrl_Reg.D14_MODE.BITS.SNDRSU = 1;
D14_Cntrl_Reg.D14_MODE.BITS.SNDRSU = 0;
}
//高速狀態
if(USB_Int_Flag.BITS.HS_STAT)
{
//清除高速狀態標志
EA_DISABLE;
USB_Int_Flag.BITS.HS_STAT = 0;
EA_ENABLE;
if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
{
//切換高速指示
HS_FS_LED = HIGH_SPEED_LED;
//設置高速模式狀態
Kernel_Flag.BITS.HS_FS_State = HIGH_SPEED;
//重新配置高速端點
Init_Endpoint();
// PIO_Count = 64;
PIO_Count = 512;
}
}
}
//***********************************************************************
//* *
//* Routine : *
//* Input : None *
//* Output : None *
//* Function : *
//* *
//***********************************************************************
//建立包處理
void USB_Setup(void)
{
unsigned char type, req;
//清除EP0SETUP中斷標志
USB_Int_Flag.BITS.EP0SETUP = 0;
//清除總線復位標志
Kernel_Flag.BITS.Bus_Reset = 0;
//選擇端點0SETUP緩沖區
D14_Cntrl_Reg.D14_ENDPT_INDEX = 0x20;
//讀取USB請求
//讀取請求類型
USB_Device_Request.bmRequestType = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
//讀取請求號
USB_Device_Request.bRequest = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
//讀取16bit請求數據
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;
//讀取16bit請求索引
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;
//讀取16bit長度
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;
//長度處理(高低8位對調)
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;
type = USB_Device_Request.bmRequestType & 0x60;
req = USB_Device_Request.bRequest & 0x0f;
//廠商請求
if (type == 0x40)
{
Vendor_Specific_Command();//廠商請求處理
}
else if (type == 0x00)
(*StandardDeviceRequest[req])();//調用標準請求
}
//***********************************************************************
//* *
//* Routine : *
//* Input : None *
//* Output : None *
//* Function : *
//* *
//***********************************************************************
//廠商請求處理
void Vendor_Specific_Command(void)
{
if(USB_Device_Request.bRequest == 0x0C)
{
switch (USB_Device_Request.wIndex)
{
case GET_FIRMWARE_VERSION ://獲取固件版本
if(USB_Device_Request.wLength == 1)
{
//select endpoint
D14_Cntrl_Reg.D14_ENDPT_INDEX = 1;
//set the data length to 1 byte
D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB = 1;
D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = 0;
//sent 0x21 as data
D14_Cntrl_Reg.D14_DATA_PORT_LSB = 0x21;//版本號
wait_ep0tx();
ep0out_ack();
// ep0in_ack();
break;
}
case SETUP_DMA_REQUEST :
//Out Token Ack detected
wait_ep0rx();
D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
//
FileSize.Size.Address[0] = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
FileSize.Size.Address[1] = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
FileSize.Size.Address[2] = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
//讀取傳輸字節數
Temp = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
bytecount = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
bytecount <<= 8;
bytecount |= Temp;
//讀取傳輸方式
FileSize.Size.DIR = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
ep0in_ack();
Kernel_Flag.BITS.Transfer_Start = 1;//標志傳輸數據開始
break;
default :
if(USB_Device_Request.bmRequestType == 0xC0)
{
ep0in_ack();
break;
}
if(USB_Device_Request.bmRequestType == 0x40)
{
D14_Cntrl_Reg.D14_ENDPT_INDEX = 0;
D14_Cntrl_Reg.D14_CONTROL_FUNCTION.BITS.STALL = 1;
while(!USB_Int_Flag.BITS.EP0SETUP)
{
//讀取ISP1581中斷寄存器
USB_Int_Flag.VALUE |= D14_Cntrl_Reg.D14_INT.VALUE;
//回寫ISP1581中斷寄存器
D14_Cntrl_Reg.D14_INT.VALUE = USB_Int_Flag.VALUE;
if(USB_Int_Flag.BITS.SUSP || USB_Int_Flag.BITS.RESET)
return;
}
USB_Int_Flag.BITS.EP0TX = 0;
break;
}
}
}
}
//***********************************************************************
//* *
//* Routine : *
//* Input : None *
//* Output : None *
//* Function : *
//* *
//***********************************************************************
void reserved(void)
{
}
//Get_Descriptor()獲取描述符
void get_descriptor(void)
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -