void IsrDma2(void) { U8 out_csr3; U32 dwEmptyCnt; U8 saveIndexReg=usbdevregs->INDEX_REG; usbdevregs->INDEX_REG=3; out_csr3=usbdevregs->OUT_CSR1_REG; ClearPending_my(BIT_DMA2); /* thisway.diy, 2006.06.22 * When the first DMA interrupt happened, it has received max (0x80000 + EP3_PKT_SIZE) bytes data from PC */ if (!totalDmaCount) totalDmaCount = dwWillDMACnt + EP3_PKT_SIZE; else totalDmaCount+=dwWillDMACnt; // dwUSBBufWritePtr = ((dwUSBBufWritePtr + dwWillDMACnt - USB_BUF_BASE) % USB_BUF_SIZE) + USB_BUF_BASE; /* thisway.diy, 2006.06.21 */ dwUSBBufWritePtr = ((dwUSBBufWritePtr + dwWillDMACnt - dwUSBBufBase) % dwUSBBufSize) + dwUSBBufBase; if(totalDmaCount>=downloadFileSize)// is last? { totalDmaCount=downloadFileSize; ConfigEp3IntMode(); if(out_csr3& EPO_OUT_PKT_READY) { CLR_EP3_OUT_PKT_READY(); } intregs->INTMSK|=BIT_DMA2; intregs->INTMSK&=~(BIT_USBD); } else { if((totalDmaCount+0x80000)<downloadFileSize) { dwWillDMACnt = 0x80000; } else { dwWillDMACnt = downloadFileSize - totalDmaCount; } // dwEmptyCnt = (dwUSBBufReadPtr - dwUSBBufWritePtr - 1 + USB_BUF_SIZE) % USB_BUF_SIZE; /* thisway.diy, 2006.06.21 */ dwEmptyCnt = (dwUSBBufReadPtr - dwUSBBufWritePtr - 1 + dwUSBBufSize) % dwUSBBufSize; if (dwEmptyCnt >= dwWillDMACnt) { ConfigEp3DmaMode(dwUSBBufWritePtr, dwWillDMACnt); } else { bDMAPending = 1; } } usbdevregs->INDEX_REG = saveIndexReg; }
void IsrDma2() { struct s3c24x0_interrupt *intregs = s3c24x0_get_base_interrupt(); struct s3c24x0_usb_device *usbdevregs = s3c24x0_get_base_usb_device(); U8 out_csr3; U32 dwEmptyCnt; U8 saveIndexReg = usbdevregs->INDEX_REG; usbdevregs->INDEX_REG = 3; out_csr3 = usbdevregs->OUT_CSR1_REG; ClearPending_my((int)BIT_DMA2); if (!totalDmaCount) totalDmaCount = dwWillDMACnt + EP3_PKT_SIZE; else totalDmaCount += dwWillDMACnt; dwUSBBufWritePtr = ((dwUSBBufWritePtr + dwWillDMACnt - dwUSBBufBase) % dwUSBBufSize) + dwUSBBufBase; if (totalDmaCount >= downloadFileSize) { /* last */ totalDmaCount = downloadFileSize; ConfigEp3IntMode(); if (out_csr3 & EPO_OUT_PKT_READY) CLR_EP3_OUT_PKT_READY(); /* 关闭DMA2中断并重新开启USBD中断 */ intregs->INTMSK |= BIT_DMA2; intregs->INTMSK &= ~(BIT_USBD); } else { if ((totalDmaCount + 0x80000) < downloadFileSize) dwWillDMACnt = 0x80000; else dwWillDMACnt = downloadFileSize - totalDmaCount; dwEmptyCnt = (dwUSBBufReadPtr - dwUSBBufWritePtr - 1 + dwUSBBufSize) % dwUSBBufSize; if (dwEmptyCnt >= dwWillDMACnt) ConfigEp3DmaMode(dwUSBBufWritePtr, dwWillDMACnt); } usbdevregs->INDEX_REG = saveIndexReg; }
__u32 usb_receive(char *buf, size_t len, U32 wait) { int first=1; U8 tempMem[16]; U32 j; unsigned int dwRecvTimeSec = 0; char c; struct s3c24x0_interrupt * intregs = s3c24x0_get_base_interrupt(); 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; } } printf("get downloadFileSize = %d !!\n",downloadFileSize); /* 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 writel((readl(&intregs->intmsk) & ~(BIT_DMA2)), &intregs->intmsk); // 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; }