📄 gfd_usb_hl.c
字号:
#include "hardware_reg.h"
#include "gfd_usb_irq.h"
#include "HA_TypeDef.h"
#include "hardware.h"
#include "intc.h"
#include "gfd_usb_common.h"
#include "Gfd_usb_protocol.h"
#ifndef NULL
#define NULL ((void *)0)
#endif
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); //usb 中断服务程序
static ER OUTINTR(void);
U32 transcl(unsigned char *head);
U32 usb_bulk_cbw(void);
void bulk_commmand(void);
struct USBDevice MSDevice;//海量存储器类别
struct USBDevice *pMSDevice = &(MSDevice);
//extern struct USBDevice MSDevice;
/*
* descriptors,描述符请参看USB1.1协议
*/
#ifdef READCARD
U32 device_desc[] = {
0x01100112, /* 描述符长度, 设备描述符, 版本号 (BCD)*/
0x08000000, /* 设备类,设备子类,设备协议,包的最大长度 */
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, /* 设备商ID , 厂商ID */
0x02010100, /* gfd's revision ID,制造商索引. 字符串索引*/
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 /* 字符串索引, 配置数目. */
};
U32 conf_desc[] = {
0x00200209, /* 描述符长度,配置描述符, 返回的总长度 */
0xc0000101, /* 接口数目,配置数目,配置索引,字符串索引,属性.: 自供电 */
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, /* 不使用总线供电,描述符长度,接口描述符,接口数目*/
0x06080200, /* 可选设置,非0端点,接口类 (Mass Storage),接口子类 (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, /* 接口协议(BOT Protocol),索引值. 字符串描述符长度,端点描述符 */
0x00400282, /* 地址(IN),属性(BULK),包的最大尺寸*/
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, /* 轮询时间 (ms),端点描述符长度,地址(OUT) */
0x00004002 /* 属性 (BULK),包的最大尺寸,轮询时间 (ms), */
};
#endif
#ifdef UDISK
U32 device_desc[] = {
0x01100112, /* 描述符长度, 设备描述符, 版本号 (BCD)*/
0x08000000, /* 设备类,设备子类,设备协议,包的最大长度 */
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
0x9382058f, /* 设备商ID , 厂商ID */
0x02010100, /* gfd's revision ID,制造商索引. 字符串索引*/
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
0x00000100 /* 字符串索引, 配置数目. */
};
U32 conf_desc[] = {
0x00200209, /* 描述符长度,配置描述符, 返回的总长度 */
0x80000101, /* 接口数目,配置数目,配置索引,字符串索引,属性.: 自供电 */
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
0x00040932, /* 不使用总线供电,描述符长度,接口描述符,接口数目*/
0x06080200, /* 可选设置,非0端点,接口类 (Mass Storage),接口子类 (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, /* 接口协议(BOT Protocol),索引值. 字符串描述符长度,端点描述符 */
0x00400282, /* 地址(IN),属性(BULK),包的最大尺寸*/
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, /* 轮询时间 (ms),端点描述符长度,地址(OUT) */
0x00004002 /* 属性 (BULK),包的最大尺寸,轮询时间 (ms), */
};
#endif
/* Unicode描述符 */
unsigned char unicode_string[]= {
0x04,0x03,
0x09,0x04 /* 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,'fraG', 'deli',
' VED', 'ssaM','otS ', 'egar','01.1'
};
/*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 0
U32 URead_capacity[]= {
0xff270000,0x00020000
};
#endif
/*64M*/ /*added by xl on 5.6*/
#ifdef USBNANDFLASH
U32 URead_capacity[]= {
0xffff0100,0x00020000
};
#endif
/*128M*/
#if 1//USBMMC
U32 URead_capacity[]= {
0xffff0300,0x00020000
};
#endif
/*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 1
U32 URead_format_capacity[]= {
0x10000000, 0x00200000, 0x00020002,
0x00200000,0x00020000,
};
#endif
/*5M*/
#if 0
U32 URead_format_capacity[]= {
0x10000000, 0x00280000, 0x00020002,
0x00280000,0x00020000,
};
#endif
/*64M*/
#ifdef USBNANDFLASH
U32 URead_format_capacity[]= {
0x10000000, 0x00000200, 0x00020002,
0x00000200,0x00020000,
};
#endif
/*128M*/
#if 0
U32 URead_format_capacity[]= {
0x10000000, 0x0000040, 0x00020002,
0x0000040,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 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);
/*USB中断响应程序*/
void ENT_INT_USB(void)
{
//ent_int();
mask_irq(INT_USB);
HA_GFDUSB_INTHANDLE();
unmask_irq(INT_USB);
//ret_int();
}
/*USB 中断处理程序*/
ER HA_GFDUSB_INTHANDLE(void)
{
ER Epstat;
U32 evnt,intr,imask;
int i;
intr = usb_lock_readreg(USB_INTR);
imask = usb_read_reg(USB_INTRMASK);
Epstat = usb_lock_readreg(USB_EPINFO);
if(((Epstat &= 0x1f)== 0) || ((Epstat &= 0x1f)== 1))
{
MSDevice.dUSBStat.epstate = EPCL;
while(1)
{
/* 读中断寄存器*/
evnt = intr & (SETUP|IN|OUT|PING|TRAERR|ACK|STCOV|CTRAERR|RESET) & (~imask);
/* 判断是否有中断 */
if (evnt==0)
{
return 0;
}
if(evnt & RESET)
{
MSDevice.dUSBTrans.head_temp = (U32*)NULL;
MSDevice.dUSBTrans.desc_len = 1;
MSDevice.dBulkStat.descactu_len = 0;
MSDevice.dCBW.requlen = 0;
MSDevice.dUSBTrans.longpk = SHORTPK;
MSDevice.dCtrlTrans.statempty = NEMPTY;
MSDevice.dUSBStat.setconstate = NSETCONFIG;
MSDevice.dBulkStat.blkstate = BLKCMD;
MSDevice.dUSBTrans.usbmod = 0;
MSDevice.dBulkStat.unsinglepocket = UNSINGLE;
MSDevice.dCSW.sing = UNSI;
MSDevice.dBulkData.longblk = SHORTBLK;
MSDevice.dUSBStat.usbdmapp = NAPP;
usb_write_reg((U32)USB_EP0OUTSTAT, 0x02);
usb_write_reg((U32)USB_EP1OUTSTAT, 0x02);
usb_write_reg((U32)USB_EP2INSTAT, 0x02);
usb_write_reg((U32)USB_INTR, 0x0);
usb_write_reg((U32)USB_INTRMASK, 0x172);
usb_RMW_clrreg(USB_INTR,0x7ffffdff);
}
if(evnt & out)
{
OUTINTR();
usb_RMW_clrreg(USB_INTR,0x7ffffffb);
}
if( evnt & setup)
{
usb_irq_setup();
usb_RMW_clrreg(USB_INTR,0x7ffffffe);
}
if(evnt & ping)
{
usb_RMW_clrreg(USB_INTR,0x7ffffff7);
while(1);
}
if(evnt & traerr)
{
usb_RMW_clrreg(USB_INTR,0x7fffffef);
while(1);
}
if (evnt & stcov)
{
usb_write_reg(USB_PKTPASSEDCTRL,0x00);
usb_write_reg(USB_PKTDROPPEDCTRL,0x00);
usb_write_reg(USB_CRCERRCTRL,0x00);
usb_write_reg(USB_BITSTUFFERRCTRL,0x00);
usb_write_reg(USB_PIDERRCTRL,0x00);
usb_write_reg(USB_FRAMINGERrCTRL,0x00);
usb_write_reg(USB_TXPKTCTRL,0x00);
usb_RMW_clrreg(USB_INTR,0x7fffffbf);
}
if(evnt & ctraerr)
{
usb_RMW_clrreg(USB_INTR,0x7fffff7f);
}
intr = usb_lock_readreg(USB_INTR);
imask = usb_read_reg(USB_INTRMASK);
}
}
else
{
MSDevice.dUSBStat.epstate = EPBULK;
evnt = intr & (SETUP|IN|OUT|PING|TRAERR|ACK|STCOV|CTRAERR|RESET) & (~imask);
if(evnt & OUT)
{
OUTINTR();
usb_RMW_clrreg(USB_INTR,0x7ffffffb);
}
}
if(evnt & RESET)
{
usb_RMW_clrreg(USB_INTR,0x7ffffdff);
}
if (evnt & stcov)
{
usb_write_reg(USB_PKTPASSEDCTRL,0x00);
usb_write_reg(USB_PKTDROPPEDCTRL,0x00);
usb_write_reg(USB_CRCERRCTRL,0x00);
usb_write_reg(USB_BITSTUFFERRCTRL,0x00);
usb_write_reg(USB_PIDERRCTRL,0x00);
usb_write_reg(USB_FRAMINGERrCTRL,0x00);
usb_write_reg(USB_TXPKTCTRL,0x00);
usb_RMW_clrreg(USB_INTR,0x7fffffbf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -