请各位帮忙看看,运用DMA在批量传输方式中能够正常接收,无法正常发送,是什么原因? void USB_EndPoint2 (DWORD event) {
USB_DMA_DESCRIPTOR DD;
//从PC接收数据,能正常接收数据 if (event & (USB_EVT_OUT_DMA_EOT) | (USB_EVT_OUT_DMA_NDR)) { /* End of Transfer or New Descriptor Request */ DD.BufAdr = (DWORD)DataBuf + 2*DataIn; /* DMA Buffer Address */ DD.BufLen = B_S; /* DMA Packet Count*/ DD.MaxSize = 64; /* Must be 0 for Iso Transfer */ DD.InfoAdr = (DWORD)InfoBuf; /* Packet Info Buffer Address */ DD.Cfg.Val = 0; /* Initial DMA Configuration */ DD.Cfg.Type.IsoEP = 0; /* Iso Endpoint */ USB_DMA_Setup (0x02, &DD); /* Setup DMA */ USB_DMA_Enable(0x02); /* Enable DMA */ } if (event & USB_EVT_OUT_DMA_EOT) { /* End of Transfer */ if (USB_DMA_BufAdr(0x02) != ((DWORD)DataBuf + 2*DataIn)) { /* Data Available */ DataIn += 64; /* Update Data In Index*/ DataIn &= B_S - 1; /* Adjust Data In Index */ if (DataIn & (B_S - 1)) == B_S/2) { DataRun = 1; /* Data Stream running */ } } } ////////////////////////////////////发送数据到PC,不能发送数据 if (DataRun == 1) { if (event & (USB_EVT_IN_DMA_EOT) | (USB_EVT_IN_DMA_NDR)) { DD.BufAdr = (DWORD)DataBuf + 2*DataOut; /* DMA Buffer Address */ DD.BufLen = B_S; /* DMA Packet Count */ DD.MaxSize = 64; /* Must be 0 for Iso Transfer */ DD.InfoAdr = (DWORD)InfoBuf; /* Packet Info Buffer Address */ DD.Cfg.Val = 1; /* Initial DMA Configuration */ DD.Cfg.Type.IsoEP = 0; /* Iso Endpoint */ USB_DMA_Setup (0x82, &DD); /* Setup DMA */ USB_DMA_Enable(0x82); /* Enable DMA */ } if (event & USB_EVT_IN_DMA_EOT) { DataOut += 64; /* Update Data In Index */ DataOut &= B_S - 1; /* Adjust Data In Index */ if (DataIn == DataOut) { DataRun = 0; /* Data Stream running */ DataOut = DataIn; /* Initialize Data Indexes */ } } } }
程序是使用keil自带的usbaudio程序代码改过来的,现在接收应该正常了,但发送PC接收不到任何数据,我把接收部分单独提出来也没有用,象这样也收不到数据: void USB_EndPoint1 (DWORD event) { USB_DMA_DESCRIPTOR DD; DWORD DataLen; BYTE DBuf[0x10]; switch (event) { case USB_EVT_IN: //控制传输来自PC的输入 发送传输字节的总长度 break; case USB_EVT_OUT: //控制传输来自PC的输出 接收所有命令 // USB_ClrStallEP(USB_ENDPOINT_OUT(1)); DataLen = 0; DataLen = USB_ReadEP(USB_ENDPOINT_OUT(1), DBuf); DD.BufAdr = (DWORD)DataBuf; /* DMA Buffer Address */ DD.BufLen = B_S; /* DMA Packet Count */ DD.MaxSize = 64; /* Must be 0 for Iso Transfer */ DD.InfoAdr = (DWORD)InfoBuf; /* Packet Info Buffer Address */ DD.Cfg.Val = 1; /* Initial DMA Configuration */ DD.Cfg.Type.IsoEP = 0; /* Iso Endpoint */ USB_DMA_Setup (0x82, &DD); /* Setup DMA */ USB_DMA_Enable(0x82); /* Enable DMA */ break; } }
|