📄 gfd_usb_hl.c
字号:
blt=0;
lstate=0;
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_RMW_clrreg(USB_INTR,0x7ffffdff);
}
if(evnt & out)
{
OUTINTR();
usb_RMW_clrreg(USB_INTR,0x7ffffffb);
evnt = usb_lock_readreg(USB_INTR);
}
if( evnt & setup)
{
usb_irq_setup();
usb_RMW_clrreg(USB_INTR,0x7ffffffe);
evnt = usb_lock_readreg(USB_INTR);
}
if(evnt & ping)
{
usb_RMW_clrreg(USB_INTR,0x7ffffff7);
evnt = usb_lock_readreg(USB_INTR);
}
if(evnt & traerr)
{
usb_RMW_clrreg(USB_INTR,0x7fffffef);
evnt = usb_lock_readreg(USB_INTR);
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);
evnt = usb_lock_readreg(USB_INTR);
}
if(evnt & ctraerr)
{
usb_RMW_clrreg(USB_INTR,0x7fffff7f);;
evnt = usb_lock_readreg(USB_INTR);
}
intr = usb_lock_readreg(USB_INTR);
imask = usb_read_reg(USB_INTRMASK);
}
}
else
{
epstate = EPBULK;
evnt = intr & (SETUP|IN|OUT|PING|TRAERR|ACK|STCOV|CTRAERR) & (~imask);
if(evnt & OUT)
{
OUTINTR();
usb_RMW_clrreg(USB_INTR,0x7ffffffb);
}
}
if(evnt & RESET)
{
//for(i;i<21;i++);
head_temp = NULL;
desc_len = 1;
state1 = 1;
urb_num = 0;
stat_des = 0;
stat_add = 0;
stat_conf = 0;
stat_defa = 0;
stat_out1 = 0;
stat_defa1 =0;
stat_ack = 0;
stat_in = 0;
statep1 = 0;
state_in = 0;
state3 = 0;
stateep1 = 0;
descactu_len = 0;
requlen = 0;
//usbstate = USBDEF;
bulkstat = BULKOUTSTAT;
transstat = TRANSBG;
bulkinepstat = BULKINDO;
longpk = SHORTPK;
statempty = NEMPTY;
setconstate = NSETCONFIG;
blkstate = BLKCMD;
usbmod = 0;
unsinglepocket = UNSINGLE;
sing = UNSI;
timen = 0;
timres=0;
longblk = SHORTBLK;
usbdmapp = NAPP;
blt=0;
lstate=0;
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_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);
evnt = usb_lock_readreg(USB_INTR);
}
if(evnt & traerr)
{
usb_RMW_clrreg(USB_INTR,0x7fffffef);
evnt = usb_lock_readreg(USB_INTR);
while(1);
}
}
/*OUT POCKET HANDLE*/
ER OUTINTR(void)
{
U32 t,t1,t2,outtime=0;
int ti,j;
ER stat;
volatile U32 i;
stat_out1++ ;
stat = usb_lock_readreg(USB_EPINFO);
if((stat &= 0x1f) != 0x0)
{
/* NON0EDNP HANDLE*/
state_in = 0;
statep1 = 1;//endp1 transport
/*BLK CMD STATE*/
if(blkstate == BLKCMD)
{
usb_write_reg((U32)USB_INTRMASK, 0x126);
t2 = *(RP)(USB_RECEIVETYPE) & 0x4;
while((t2 == 0x0) && (outtime < 1000))
{
t2 = *(RP)(USB_RECEIVETYPE) & 0X4;
outtime++;
}
if(outtime < 1000)
{
if(t2 == 0x4)
{
R = RX;
/*CBW STATE*/
usbdmapp = APP;
USB_DMA_TRANS_RX((U32)USB_RXFIFO,(U32)R,0x32,0x32,0x16,0x0,0x10);
i = *(volatile U32 *)DMACC0Configuration;
while((i & 0x1) != 0)
{
i = *(volatile U32 *)DMACC0Configuration;
}
R = R + 64;
t = usb_read_reg(USB_RXLENGTH);
if(t != 64)
{
t = 64 - t;
R = R - t;
}
}
}
}
}
else
{
statep1 = 0;
*(RP)USB_RECEIVETYPE &= 0x07;
}
return(0);
}
void ENT_INT_USB(void)
{
ent_int();
mask_irq(INT_USB);
HA_GFDUSB_INTHANDLE();
unmask_irq(INT_USB);
ret_int();
}
void usbswap_data(U32 *src, U16 len)
{
char *psrc, *pdst, tmp;
int i;
psrc = (char *)src;
for(i = 0; i < len*128; i++)
{
tmp = *(psrc+3);
*(psrc+3) = *psrc;
*psrc = tmp;
tmp = *(psrc+2);
*(psrc+2) = *(psrc+1);
*(psrc+1) = tmp;
src++;
psrc = (char *)src;
}
}
INT usbpc_rd_io(UINT16 driveno, UINT32 block, VOID *buffer, UINT32 count,
INT reading)
{
UINT32 *p;
UINT32 ltemp;
UINT16 page_number;
UINT32 byte_number;
INT16 i;
UINT32 *pbuffer;
/* We don't use drive no. You could have multiple drives if wanted */
driveno = driveno;
pbuffer = (UINT32 *)buffer;
while (count)
{
/* Get the page number */
ltemp = block / RAMDISK_PAGE_SIZE;
page_number = (UINT16) ltemp;
/* Check. This shouldn't happen */
if ( (page_number >= NUM_RAMDISK_PAGES) || !rd_pages[page_number] )
return(NO);
/* Get the offset */
ltemp = block % RAMDISK_PAGE_SIZE;
byte_number = (UINT32) (ltemp*128);
p = (UINT32 *)rd_pages[page_number];
p += byte_number;
if (reading&0x01) // &0x01 for flash flush.
{
for (i = 0; i < 128; i++)
*pbuffer++ = *p++;
}
else
{
for (i = 0; i < 128; i++)
*p++ = *pbuffer++;
}
count--;
block++;
}
return(YES);
}
#if 0
INT dev_io_proc(UINT16 driveno, UINT32 sector, VOID *buffer, UINT16 count, INT reading)
{
_PC_BDEVSW *pdev;
DDRIVE *pdr;
UINT16 ltemp, ebnum, ebsize, ionum,offsetsec, *peb, *pfat, *pdirty;
UINT8 *devbuf, *pbuffer = buffer;
pdr = (DDRIVE *)NUF_Drive_Pointers[driveno];
/*
* MASTER BUFFER READ/WRITE
*/
ltemp = pdr->firstclblock;
if ( sector < ltemp )
{
//printf("op sector=%x count=%d FAT TABLE %s\n", sector, count, (reading==YES)?"R":"Write");
devbuf = pdr->fat_swap_structure.master_buffer + (sector<<9);
if (reading == YES)
memcpy(buffer, devbuf, count<<9);
else if (reading == NO)
memcpy1(devbuf, buffer, count<<9);
else if (reading == FLUSH)
{
/* FLUSH the data in the data buffer into device, and
* there is no error check here because the device
* must have been destroyed completely. */
ebsize = NUF_Drive_Erase_Size[driveno];
ebnum = 0;
for (ebnum = 0; ebnum < ltemp; ebnum += ebsize)
{
io_err_proc(driveno, ebnum, devbuf, ebsize, NO);
devbuf += ebsize<<9;
}
}
return 1;/*ok*/
}
/*
* DATA READ/WRITE
*/
devbuf = pdr->fat_swap_structure.data_buffer;
pdirty = &pdr->fat_swap_structure.data_buf_dirty;
peb = &pdr->fat_swap_structure.data_buf_eb;
ltemp = *peb;
ebsize = NUF_Drive_Erase_Size[driveno];
/*
* if device is NOR FLASH(that is driveno == 1), and
* only if operation is reading data,
* read the nor flash device directly for speed up.
*/
if(driveno == 1 && reading == YES)
{
pdev = &pc_bdevsw[driveno];
while(count)
{
ebnum = sector/ebsize;
offsetsec = sector%ebsize;
if ( ebnum != ltemp || ltemp == 0 ) /* read the device directly*/
{
ionum = ebsize-offsetsec;
if(count<=ionum)
{
if (pdev->io_proc(driveno, sector, pbuffer, count, YES))
return YES; /* read ok */
return NO; /* read failed */
}
else
{
if (!pdev->io_proc(driveno, sector, pbuffer, ionum, YES))
return NO; /* read failed */
}
sector += ionum;
count -= ionum;
pbuffer += ionum<<9;
}
else
{
if (offsetsec)
{
devbuf += (offsetsec<<9);
ionum = ebsize - offsetsec;
if (count<ionum)
ionum = count;
}
else
{
if (count<=ebsize)
ionum = count;
else
ionum = ebsize;
}
count -= ionum;
sector += ionum;
memcpy(pbuffer, devbuf, ionum<<9); /* read data from data buffer */
pbuffer += ionum<<9;
}
}
return YES; /* read ok */
}
/* The DATA BUFFER is out of date, the current data in the buffer
* should be saved into the real device. And the new data sent by
* the caller will be put into the buffer afterward or read from the
* buffer. */
while(count)
{
ebnum = sector/ebsize;
offsetsec = sector%ebsize;
devbuf = pdr->fat_swap_structure.data_buffer;
if ( ebnum != ltemp || ltemp == 0 )
{
if (ltemp != 0)
{
/* Save the current data in the buffer to the device */
if ( *pdirty == 1 )
{
*pdirty = 0;
if (!io_err_proc(driveno, ltemp*ebsize, devbuf, ebsize, NO))
return 0;/*error*/
}
if (reading == FLUSH)
return 1;/*ok*/
}
/* Record the new EB number */
*peb = ebnum;
ltemp = ebnum;
/* Load the new data from the device */
if (!io_err_proc(driveno, ebnum*ebsize, devbuf, ebsize, YES))
{
*peb = 0;
return 0;/*error*/
}
}
/* Check the EB according to the current data buffer is not BAD */
pdr = (DDRIVE *)NUF_Drive_Pointers[driveno];
pfat = (UINT16*)&pdr->fat_swap_structure.data_array[0];
pfat += (ebnum*ebsize-pdr->firstclblock)/pdr->secpalloc + 2;
if (*(pfat + 3 ) == 0xFFF7 )
{
*peb = 0; *pdirty = 0;
return 0;/*error*/
}
/* The DATA BUFFER is update, continue the operation. */
if (offsetsec)
{
devbuf += (offsetsec<<9);
ionum = ebsize - offsetsec;
if (count<ionum)
ionum = count;
}
else
{
if (count<=ebsize)
ionum = count;
else
ionum = ebsize;
}
count -= ionum;
sector += ionum;
if (reading == YES)
{
memcpy(pbuffer, devbuf, ionum<<9);
pbuffer += ionum<<9;
}
else
{
memcpy(devbuf, pbuffer, ionum<<9);
pbuffer += ionum<<9;
*pdirty = 1;
}
}
return 1;/*ok*/
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -