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

📄 gfd_usb_hl.c

📁 最近在國外網站抓到的作業系統 以Arm為基礎去開發的
💻 C
📖 第 1 页 / 共 3 页
字号:
/**************************************************************************************
 *
 *  (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
 *-------------------------------------------------------------------*/
U32 *head_temp = NULL;
unsigned char *root;
S32 desc_len = 1;
U32 temblklen;
U32 state1 = 1;
U8 analys[120][31];
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];
extern U32 *bulkindatebuf;
extern U32 *bulkoutdatebuf;
U32 unsinglepocket = UNSINGLE;
U32 sing = UNSI;
U32 timen = 0; 
U32 timres=0;
U32 longblk = SHORTBLK;
U32 lblkaddr;
U16 blktmp;
U32 usbdmapp = NAPP;
U32 blt=0;
U32 lstate=0;
/*******************************global matrix for CBW & CSW***/
U8 cbw[31],  ufi_cmd[11];
U32 csw[4];
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	UInquiry[]= {
	0x00008000, 0x0000001f,'fraG', 'deli',
	' VED', 'ssaM','otS ', 'egar','01.1'
}; 

/*
unsigned char	inquiry_data[INQUIRY_DATA_SIZE] = { 
	0x00, 0x80, 0x02, 0x00, 0x33, 0x00, 0x00, 0x00,
	'P', 'h', 'i', 'l', 'i', 'p', 's', ' ',
	'O', 'T', 'G', ' ', 'M', 'a', 's', 's', 
	' ', 'S', 't', 'o', 'r', 'a', 'g', 'e',
	'1', '.', '0', '0'
};*/

/*32M*/
#if 0
U32 URead_capacity[]= {
	0xffff0000,0x00020000
};
#endif
/*16M*/
#if 0
U32 URead_capacity[]= {
	0xff7f0000,0x00020000
};
#endif

/*4M*/
#if 0
U32 URead_capacity[]= {
	0xff1f0000,0x00020000
};
#endif

/*5M*/
#if 1
U32 URead_capacity[]= {
	0xff270000,0x00020000
};
#endif

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

/*32M*/
#if 0
U32	URead_format_capacity[]= {
	0x10000000, 0x00001000,	0x00020002,
	0x00000100,	0x00020000,
};
#endif

/*16M*/
#if 0
U32	URead_format_capacity[]= {
	0x10000000, 0x00800000,	0x00020002,
	0x00800000,	0x00020000,
};
#endif

/*4M*/
#if 0
U32	URead_format_capacity[]= {
	0x10000000, 0x00200000,	0x00020002,
	0x00200000,0x00020000,
};
#endif

/*5M*/
#if 1
U32	URead_format_capacity[]= {
	0x10000000, 0x00280000,	0x00020002,
	0x00280000,0x00020000,
};
#endif
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};
/*-------------------------------------------------------------------*
 *	define declarations
 *-------------------------------------------------------------------*/


/*-------------------------------------------------------------------*
 *				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(blt <120)
	{
		for(k=0;k<31;k++)
		{
			analys[blt][k] = RX[k];
		}

		blt++;
	}
#if 0
	blt--;
	if(analys[blt][19]  == 0x02)
	{
		while(1);
	}
	blt++;
#endif
	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;

	command  = ufi_cmd[0];
       if((ufi_cmd[0] == 0x28) && (ufi_cmd[4] ==0x40) )
	{
		while(1);
	}

	lblkaddr = (((U32)ufi_cmd[2]) << 24) | (((U32)ufi_cmd[3]) << 16) | (((U32)ufi_cmd[4]) << 8) | ((U32)ufi_cmd[5]);
	translen = (((U16)ufi_cmd[7]) << 8) | ((U16)ufi_cmd[8]); 

	switch(command)
	{
		case 	INQUIRY:
			desc_len = 0x24;//sizeof (UInquiry);modified
			head_temp = UInquiry;
			descactu_len = 0x24;//sizeof (UInquiry);
			requlen = cbw_dtl;
			blktrasstate = BULKIN;
			break;
		case 	READ:
			blktrasstate = BULKIN;
			temblklen = translen;
			if(temblklen > 8)
			{
				longblk = LONGBLK;

⌨️ 快捷键说明

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