|
天嵌的我不知道。这个函数是现成的驱动。是在一个驱动包里定义的,驱动包叫usb_slave,你要想查可以去网上搜索,这个驱动好像和dnw有关,我可以粘贴一些源码,要是下载不了联系我qq:654224414
//void WaitDownload(void)
__u32 usb_receive(char *buf, size_t len, U32 wait)
{
int first=1;
U8 tempMem[16];
U32 j;
unsigned int dwRecvTimeSec = 0;
char c;
dwUSBBufReadPtr = dwUSBBufBase; // USB_BUF_BASE; thiswa.diy, 2006.06.21
dwUSBBufWritePtr = dwUSBBufBase; // USB_BUF_BASE; thiswa.diy, 2006.06.21
bDMAPending = 0;
/* add by thisway.diy */
tempDownloadAddress = dwUSBBufBase; // USB_BUF_BASE; thiswa.diy, 2006.06.21 // RAM_BASE, changed by thisway.diy for wince, 2006.06.18
downloadAddress=(U32)tempMem; //_RAM_STARTADDRESS;
downPt=(unsigned char *)downloadAddress;
//This address is used for receiving first 8 byte.
downloadFileSize=0;
/*******************************/
/* File download */
/*******************************/
if(isUsbdSetConfiguration==0)
{
printf("USB host is not connected yet.\n");
}
while(downloadFileSize==0) /* wait until send a file */
{
if(first==1 && isUsbdSetConfiguration!=0)
{
printf("USB host is connected. Waiting a download.\n");
first=0;
}
c = awaitkey(1, 0);
if ((c & 0x7f) == INTR)
{
printf("Cancelled by user\n");
return 0;
}
}
/* add by thisway.diy */
if (downloadFileSize - 10 > len)
{
printf("Length of file is too big : %d > %d\n", downloadFileSize - 10, len);
return 0;
}
Timer_InitEx();
Timer_StartEx();
#if USBDMA
intregs->INTMSK&=~(BIT_DMA2);
ClearEp3OutPktReady();
// indicate the first packit is processed.
// has been delayed for DMA2 cofiguration.
if(downloadFileSize>EP3_PKT_SIZE)
{
if(downloadFileSize - EP3_PKT_SIZE<=(0x80000))
{
/* set the source and length */
dwUSBBufWritePtr = downloadAddress + EP3_PKT_SIZE-8;
dwWillDMACnt = downloadFileSize - EP3_PKT_SIZE;
}
else
{
dwUSBBufWritePtr = downloadAddress + EP3_PKT_SIZE - 8;
// dwWillDMACnt = 0x80000 - EP3_PKT_SIZE;
/* Changed by thisway.diy, 2006.06.22
* We want When the first DMA interrupt happened,
* it has received (0x80000 + 8) bytes data from PC
* The format of data PC send out is: <ADDR(DATA):4>+<SIZE(n+10):4>+<DATA:n>+<CS:2>
* So, the first 8 bytes isn't the real data we want
* We want the dwUSBBufWritePtr is always 0x80000 aligin
*/
dwWillDMACnt = 0x80000 + 8 - EP3_PKT_SIZE;
}
totalDmaCount = 0;
ConfigEp3DmaMode(dwUSBBufWritePtr, dwWillDMACnt);
}
else
{
dwUSBBufWritePtr = downloadAddress + downloadFileSize - 8;
totalDmaCount = downloadFileSize;
}
#endif
printf("\nNow, Downloading [ADDRESS:%xh,TOTAL:%d]\n",
downloadAddress,downloadFileSize);
if (wait)
{
printf("RECEIVED FILE SIZE:%8d",0);
j = totalDmaCount + 0x10000;
while (totalDmaCount != downloadFileSize)
{
if (totalDmaCount > j)
{
printf("\b\b\b\b\b\b\b\b%8d", j);
j = totalDmaCount + 0x10000;
}
}
printf("\b\b\b\b\b\b\b\b%8d ", totalDmaCount);
dwRecvTimeSec = Timer_StopEx();
if (dwRecvTimeSec == 0)
{
dwRecvTimeSec = 1;
}
printf("(%dKB/S, %dS)\n", (downloadFileSize/dwRecvTimeSec/1024), dwRecvTimeSec);
}
return downloadFileSize - 10;
} |
|