⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbdebug.c

📁 基于USB2.0芯片 ISP1581 的扫描仪固件源码,USB驱动模块
💻 C
📖 第 1 页 / 共 5 页
字号:
//***********************************************************************
//									     								                  *
//                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 fn_Not_Implemented(void);
void Send_Device_Status(void);
void Send_Interface_Status(void);
void Send_Endpoint_Status(void);

void Vendor_Specific_Command(void);
void Set_Interface_Value(void);
void Get_Interface_Value(void);
void Process_Synch_Frame(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 VID[2],PID[2];
FILESIZE FileSize;
UI PIO_Count;
UC	File_Number;
UC	Current_File;
ULI bytecount;

//***********************************************************************
//*																		               *
//*	                     Routine Definition								   *
//*																		               *
//***********************************************************************

//***********************************************************************
//*										    							               *
//*	Routine 	:  USB Debug Mode                                 		   *
//*	Input		:  USB Interrupt Register 								         *
//*	Output	:  None                                					   *
//*	Function	:  Branch to respective ISR                  			   *
//*																		               *
//***********************************************************************

void USB_Debug_Mode(void)
{

      //check if bus reset has occur               
   	
   //check for setup token      
   if(USB_Int_Flag.BITS.EP0SETUP)
		USB_Setup();
   
   //check for suspend
	if(USB_Int_Flag.BITS.SUSP)
	{		
      //Clear Suspend interrupt bit
	   USB_Int_Flag.BITS.SUSP = 0;
                  
      //Activate ISp1581 into suspend mode                  
      D14_Cntrl_Reg.D14_MODE.BITS.GOSUSP = 1;
      D14_Cntrl_Reg.D14_MODE.BITS.GOSUSP = 0;

/*      
      //this is added to cater for the start to chirp when
      //bus rest from suspend state
      D14_Cntrl_Reg.D14_TEST_MODE.BITS.FORCEFS = 1;
      D14_Cntrl_Reg.D14_TEST_MODE.BITS.FORCEFS = 0;
*/
	}

	if(USB_Int_Flag.BITS.RESUME)
   {
   
      //clear resume interrupt bit
      USB_Int_Flag.BITS.RESUME = 0;         

      //Issue a resume
      D14_Cntrl_Reg.D14_MODE.BITS.SNDRSU = 1;
      D14_Cntrl_Reg.D14_MODE.BITS.SNDRSU = 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;


      if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
		{
      
         //switch on high speed LED
         HS_FS_LED = HIGH_SPEED_LED;
      
         //set device state to high speed state
	   	Kernel_Flag.BITS.HS_FS_State = HIGH_SPEED;
      
         //reconfigure endpoint to high speed endpoint
	   	Init_Endpoint();
      
         PIO_Count = 512;
         
      }

	}
		
}




//***********************************************************************
//*										    							*
//*	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_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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -