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

📄 gfd_usb_hl.c.bak

📁 这时linux下的usb的代码
💻 BAK
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************************
 *
 *  (c) 2004 ASIC,all rights reserved
 *         
 *           
 *	This source code and any compilation or derivative thereof 
 *is proprietary information and is confidential in nature.
 *	Under no circumstance is this software to be exposed or placed
 *under an open source License of any type without expressed
 *written permission of ASIC.  
 *
 *filename:	gfd_usb_hl.c          
 *history:
 *
 *    Version         Date            Author            Comments
 *------------------------------------------------------------------------------------    
 *     1.0          2004.9.24           lmq             Initial Creation
 *     
 **************************************************************************************/
#include "hardware_reg.h"
#include "gfd_usb_irq.h"
#include "HA_TypeDef.h"
#include "hardware.h"
#include "gfd_usb_protocol.h"
#include "gfd_usb_common.h"
#include "gfd_dmac.h"
#include "pcdisk.h"
#include "itron.h"
#include "fs.h"
/*-------------------------------------------------------------------*
 *				local	function	declerations
 *-------------------------------------------------------------------*/
static void usb_irq_setup(void);
static U8  *get_irq_request_cmd(void);
static U32 pdc_bus_ctrl_pipe_notificaion(unsigned long notif_type, unsigned char *cmd);
static void pdc_bus_get_descriptor(U8 *command);
ER  HA_GFDUSB_INTHANDLE(void);  //;when there is usb interrupt,the process starts 
static ER OUTINTR(void);
static void pdc_bus_SET_CONFIGURATION(void);
static void bulk_commmand(void);
U32 usb_bulk_cbw(void);
static void bulk_commmand(void);
void usb_bulk_csw(void);
U32 usb_bulk(void);
static U32 transcl(unsigned char *head);
U32 transbulk(unsigned char *head);
void usbswap_data(U32 *src, U16 len);
/*-------------------------------------------------------------------*
 *					global variable definitions
 *-------------------------------------------------------------------*/
unsigned char *head_temp = NULL;
unsigned char *root;
S32 desc_len = 1;
U32 temblklen;
U32 state1 = 1;
U32 tlengh;
U32 urb_num = 0;
U8 command_request[8];
U32 setstat;
U8 RX[64];
U8 *R;
U32 stat_des = 0; 
U32 stat_add = 0;
U32 stat_conf = 0;
U32 stat_defa = 0;
U32 stat_out1 = 0;
U32 stat_defa1 =0;
U32 stat_ack = 0;
U32 stat_in = 0;
U32 statep1 = 0;
U32 usbstate = USBDEF;
U32 state_in = 0;
U32 tlengh1;
U32 state3 = 0;
U32 stateep1 = 0;
S32 descactu_len = 0;
S32 requlen = 0;
U32 bulkstat = BULKOUTSTAT;
U32 transstat = TRANSBG; 
U32 bulkinepstat = BULKINDO;
U32 usbmod = 0;
U32 longpk = SHORTPK;
U8 *longurb;
U32 statempty = NEMPTY;
U32 setconstate = NSETCONFIG;
U32 blkstate = BLKCMD;
U32 blktrasstate;
U32 epstate;
U32 bulkindatebuf[1024];
U32 bulkoutdatebuf[1024];
U32 unsinglepocket = UNSINGLE;
U32 sing = UNSI;
U32 timen = 0; 
U32 timres=0;
U32 longblk = SHORTBLK;
U32 lblkaddr;
/*******************************global matrix for CBW & CSW***/
U8 cbw[31], cwst,csw[13],cswt[3], ufi_cmd[11];
U8 cbw_direct;		//means the direction of data transfer:: 0x00=host to the device; 0x80=device to the host
U32 cbw_dtl;		//cbw Data Transfer Length


/*
 * descriptors
 */
U32 device_desc[] = {
	0x01100112, /* length of this desc, DEVICE descriptor, spec rev level (BCD)*/
	0x08000000, /* device class,device subclass,device protocol,max packet size */
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle 
	0x00000000, //idle  
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle 
	0x00000000, //idle  
	0x00000000, //idle
	0x00000000, //idle  
	0x00000000, //idle
	0x66800ed1, /* device vector ID , device product ID */
	0x02010100, /* gfd's revision ID,index of manuf. string,index of prod.  string */
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000000, //idle          
	0x00000103  /* index of ser. # string, number of configs. */
};

U32  conf_desc[] = {
	0x00200209,	/* length of this desc,PDC_CONFIG_DESC_TYPE,CONFIGURATION descriptor, total length returned */ 
	0xc0000101,	/* number of interfaces,number of this config,index of config. string,attr.: self powered */   
  	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle 
	0x00000000, //idle  
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle 
	0x00000000, //idle  
	0x00000000, //idle
	0x00000000, //idle  
	0x00000000, //idle
  	0x00040901, /* we take no bus power,length of this desc,INTERFACE descriptor,interface number*/
 	0x06080200, /* alternate setting,# of (non 0) endpoints,interface class (Mass Storage),interface subclass (SCSI Transparent) */  
 	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle 
	0x00000000, //idle  
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle 
	0x00000000, //idle  
	0x00000000, //idle
	0x00000000, //idle  
	0x00000000, //idle
	0x05070050, /* interface protocol (BOT Protocol),index of intf. string,length of this desc,ENDPOINT descriptor */ 
	0x00400282, /* address (IN),attributes  (BULK),max packet size*/
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle 
	0x00000000, //idle  
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle
	0x00000000, //idle 
	0x00000000, //idle  
	0x00000000, //idle
	0x00000000, //idle  
	0x00000000, //idle
	0x01050700, /* interval (ms),length of this desc,ENDPOINT descriptor,address (OUT) */
	0x00004002 /* attributes  (BULK),max packet size,interval (ms),	*/
};

/* Unicode descriptors for our device description */
unsigned char unicode_string[]= { 
	0x04,0x03,
	0x09,0x04 		/* We offer only one language: 0409, US English */
};

unsigned char mfg_string[]= {
	26,3, 'P',0, 'h',0, 'ti',0, 'l',0, 'ti',0, 'p',0, 's',0, 
	'-',0, 'A',0, 'P',0, 'ti',0, 'C',0
};

unsigned char product_string[]= 
#if 1
	gfd_product_string
#else
{
	60,3, '1',0, '3',0, '6',0, '2',0, '-',0, 'O',0, 'T',0, 'G',0, ' ',0,
	'M',0, 'A',0, 'S',0, 'S',0, ' ',0, 
	'S',0, 't',0, 'o',0, 'r',0, 'a',0, 'g',0, 'e',0, ' ',0,
#ifdef CONFIG_gfd_PCI
	'P',0, 'C',0, 'ti',0,
#else
	'ti',0, 'S',0, 'A',0,
#endif /* CONFIG_gfd_PCI */
	' ',0, 'K',0, 'ti',0, 't',0
}
#endif
;

unsigned char serial_string[]= {
	0x0A, 0x03, '1', 0x00, '.',0x00, '0', 0x00, '0', 0x00
};

unsigned char empty[] = {0x00};

/*******************************UFI command descriptions*******************/
U32	UInquiry[]= {
	0x00008000, 0x0000001f,	0x656e6547,	0x20636972,	0x20425355,
	0x52204453,	0x65646165,	0x20202072,	0x30302e32
}; 
U32 URead_capacity[]= {
	0xffd30300,0x00020000
};

U32	URead_format_capacity[]= {
	0x10000000, 0x00d40300,	0x00020002,
	0x00d40300,	0x00020000
};

U32 URequest_sense[]= {
	0X000600f0,	0X0a000000,	0X00000000,	0X00000028,
	0x00000000
};

unsigned char Ucode_15[]= {
	0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x02, 0x00, 0x1c, 0x0a, 0x80, 0x04,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
	
unsigned char Ucode_1A[]= {
	0x0b, 0x00, 0x00, 0x00, 0x1c, 0x06, 0x00, 0x05,
	0x00, 0x00, 0x00, 0x00};

/*-------------------------------------------------------------------*
 *				extern variable declerations
 *-------------------------------------------------------------------*/	
 extern UINT8  *rd_pages[NUM_RAMDISK_PAGES];
 extern UINT8	g_nor_buf[256*1024];
 extern int g_nor_blknum;
/*-------------------------------------------------------------------*
 *				extern	function	decleratios			
 *-------------------------------------------------------------------*/
extern  ER usb_write_reg(U32 reg, U32 val);
extern  ER usb_read_reg(U32 reg); 
extern  U8 usb_chang_reg32_to_reg8(U32 reg);
extern  U16 usb_change_reg32_to_reg16(U32 reg);
extern  U8 usb_get_regbit15_to_8(U32 reg);
extern  ER USB_DMA_TRANS_RX(U32 srcadd, U32 destadd, U32 srcwidth, U32 destwidth, U32 srcsize, U32 channelnum, U32 transnum);
extern  ER USB_DMA_TRANS_TX(U32 srcadd, U32 destadd, U32 srcwidth, U32 destwidth, U32 srcsize, U32 channelnum, U32 transnum);
extern  ER usb_lock_readreg(U32 reg);
extern  ER usb_RMW_reg(U32 reg, U32 val);
extern  ER usb_RMW_clrreg(U32 reg, U32 val); 
extern  INT nor_rd_io(UINT16 driveno, UINT32 page, VOID FAR *buffer, UINT16 count, INT do_read);
/*-------------------------------------------------------------------*
 * 				local	function	definitions
 *-------------------------------------------------------------------*/
 
/*
 *bulk transmit: command block wrapper
 */
U32 usb_bulk(void)
{
	U8 k;
	
	for(k=0; k<31; k++)
		cbw[k] = RX[k];
	if(cbw[0] != 0x55)
		return -1;
	if(cbw[1] != 0x53)
		return -1;
	if(cbw[2] != 0x42)
		return -1;
	if(cbw[3] == 0x43)
		usb_bulk_cbw();
	return 0;
}

U32 usb_bulk_cbw(void)
{
	U32 cbwtag;
	U8 cbw_len;			//the valid length of the cbw in bytes
	U8 ti;

	cbwtag = ((cbw[7]<<24)|(cbw[6]<<16)|(cbw[5]<<8)|(cbw[4]));
	cbw_dtl = ((cbw[11]<<24)|(cbw[10]<<16)|(cbw[9]<<8)|(cbw[8]));
	cbw_direct = cbw[12];
	cbw_len = cbw[14];
	for(ti=0; ti<12; ti++)
		ufi_cmd[ti] = 0;
	for(ti=0; ti<cbw_len; ti++)
		ufi_cmd[ti] = cbw[15+ti];
	bulk_commmand();
	return cbwtag;	
} 

/*
 * UFI COMMAND FUNCTION
 */
void bulk_commmand(void)
{
	U8 command;
	U16 translen,blktmp;

	command  = ufi_cmd[0];
	lblkaddr = (((U32)ufi_cmd[1]) << 24) | (((U32)ufi_cmd[2]) << 16) | (((U32)ufi_cmd[3]) << 8) | ((U32)ufi_cmd[4]);
	translen = (((U16)ufi_cmd[7]) << 8) | ((U16)ufi_cmd[8]); 
	switch(command)
	{
		case 	INQUIRY:
			desc_len = 0x24;//sizeof (UInquiry);modified
			head_temp = (unsigned char *)UInquiry;
			descactu_len = 0x24;//sizeof (UInquiry);
			requlen = cbw_dtl;
			blktrasstate = BULKIN;
			break;
		case 	READ:
			blktrasstate = BULKIN;
			temblklen = translen;
			if(temblklen > 8)
			{
				longblk = LONGBLK;
				blktmp = 8;
				desc_len = 8*512;
			}
			else
			{
				longblk = SHORTBLK;
				blktmp = temblklen;
				desc_len = temblklen*512;
			}
			/*read from flush*/
			nor_rd_io(0,(UINT32)lblkaddr, bulkindatebuf,(UINT16)blktmp,0); 
			/*invert order*/
			usbswap_data(bulkindatebuf,blktmp);
			head_temp = (unsigned char *)bulkindatebuf;
			descactu_len = translen*512;//sizeof (URead20);
			requlen = translen*512;//sizeof (URead20);
			break;
		case 	READ_CAPACITY:
			blktrasstate = BULKIN;
			desc_len = 0x8;//sizeof (URead_capacity);
			head_temp = (unsigned char *)URead_capacity;
			descactu_len = 0x8;//sizeof (URead_capacity);
			requlen = cbw_dtl;
			break;
		case 	READ_FORMAT_CAPACITY:
			blktrasstate = BULKIN;
			desc_len = 0x14;//sizeof (URead_format_capacity);
			head_temp = (unsigned char *)URead_format_capacity;
			descactu_len = 0x14;//sizeof (URead_format_capacity);
			requlen = cbw_dtl;
			break;
		case 	REQUEST_SENSE:
			blktrasstate = BULKIN;
			desc_len = 0x12;//sizeof (URequest_sense);
			head_temp = (unsigned char *)URequest_sense;
			descactu_len = 0x12;//sizeof (URequest_sense);
 			requlen = cbw_dtl;
			break;
		case 	CODE_1A:
			blktrasstate = BULKIN;
			desc_len = sizeof (Ucode_1A);
  			head_temp = Ucode_1A;
  			descactu_len = sizeof (Ucode_1A);
			requlen = cbw_dtl;
			break;
		case 	CODE_15:
			blktrasstate = BULKIN;
			desc_len = sizeof (Ucode_15);
			head_temp = Ucode_15;
			descactu_len = sizeof (Ucode_15);
			requlen = cbw_dtl;
			break;
		case 	WRITE2:
			blktrasstate = BULKOUT;
			temblklen = translen;                      
			if(temblklen > 8)                          
			{                                          
				longblk = LONGBLK;                     
				blktmp = 8;                            
				desc_len = 8*512;                      
			}                                          
			else                                       
			{  
				longblk = SHORTBLK;                                        
				blktmp = temblklen;                    
				desc_len = temblklen*512;              
			}                                          
			head_temp = (unsigned char *)bulkindatebuf;
			descactu_len = translen*512;//sizeof (URead20);
			requlen = translen*512;//sizeof (URead20);
			break;
		case 	TESTUNITREADY :
			unsinglepocket = SINGLE;
			break;
		case	PREVENT :
			unsinglepocket = SINGLE;	
			sing = SI;
			break;
	}	    
}           
            
void usb_bulk_csw(void)
{
	U32 residue;

	csw[0] = 0x55;
	csw[1] = 0x53;
	csw[2] = 0x42;
	csw[3] = 0x53;
	csw[4] = usb_bulk_cbw();
	csw[5] = (usb_bulk_cbw()>>8);
	csw[6] = (usb_bulk_cbw()>>16);
	csw[7] = (usb_bulk_cbw()>>24);
    residue = requlen - descactu_len;
    csw[8] = residue;
    csw[9] = residue >> 8;
    csw[10] = residue >> 16;
    csw[11] = residue >> 24;
    if(sing == UNSI)
    {
    	csw[12] = 0x00;
   	}
   	else
   	{
   		timen++;
   		sing = UNSI;
   		csw[12] = 0x01;
   	}
	tlengh = 13;
	head_temp = csw;
}

/*DATA TRANSFER*/
U32 transbulk(unsigned char *head)
{
	unsigned char *urb;
	int j, ti;
	U32 P2;
	U32 stat,temp = 0;
	U32 t;
	
	if(blktrasstate == BULKIN)
	{
		/*in transfer*/
		ti = desc_len;
		urb = head;
		if(ti < 64)
		{
			*(RP)(USB_TXLENGTH) = ti;//the pocket, less than 8 bytes
		}
		else
		{
			*(RP)(USB_TXLENGTH) = 64;
		}
		j = ti/64;
		usbmod = ti%64;
		if(desc_len < 64)
		{
			USB_DMA_TRANS_TX((U32)urb,(U32)USB_TXFIFO,0x32,0x32,0x16,0x0,0x10);
		}
		else
		{
			longpk = LONGPKSTATE;
			USB_DMA_TRANS_TX((U32)urb,(U32)USB_TXFIFO,0x32,0x32,0x16,0x0,j*0x10);
			longurb = head + j*64;

⌨️ 快捷键说明

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