BRANDER
驱动牛犊
驱动牛犊
  • 注册日期2002-09-29
  • 最后登录2009-05-01
  • 粉丝0
  • 关注0
  • 积分52分
  • 威望15点
  • 贡献值0点
  • 好评度5点
  • 原创分0分
  • 专家分0分
阅读:2300回复:8

cy68013 向EP6写数据,有谁做过啊,求助!!!!!

楼主#
更多 发布于:2003-05-29 14:20
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>


#include \"ezusbsys.h\"
#include \"winioctl.h\"

int main()

{
             int buffer[2000];
             BOOL bResult;        
int length=64;
int size=2000;
int  count=1000;

BULK_TRANSFER_CONTROL bulkControl;
bulkControl.pipeNum=2;

HANDLE hDevice;               //
DWORD junk;                   hDevice = CreateFile(\"\\\\\\\\.\\\\Ezusb-0\", GENERIC_READ | GENERIC_WRITE,       FILE_SHARE_READ | FILE_SHARE_WRITE,                         NULL,    OPEN_EXISTING,  0, NULL);  
if (hDevice == INVALID_HANDLE_VALUE) // we can\'t open the drive
{
printf(\"open failed\\n\");
return (FALSE);
}



DWORD ioctl_val = IOCTL_EZUSB_BULK_READ;
bResult = DeviceIoControl(hDevice,  ioctl_val ,   &bulkControl,
  sizeof (BULK_TRANSFER_CONTROL),
                           buffer,
  length,  // output buffer
                            &junk, // discard count of bytes returned
                             NULL);  // synchronous I/O




if (!bResult) // IOCTL failed
{
printf(\"chen open fail\");

return FALSE;
}
  
// WriteFile(hDevice, buffer, 2000, &numwritten, NULL);
printf(\"ok\\n\");

    printf(\"chen=%d\",junk);
FILE *fp= fopen (\"C:\\\\DATATOFX2\\n\",\"w+b\" );
if (fp!=NULL) {
numwrite=fwrite(buffer,sizeof(int),64,fp);

}
// ReadFile();

CloseHandle(hDevice);         // we\'re done with the handle

return (bResult);
}
然后我通过CPLD向EP6发送数据,从逻辑分析仪可以采集到送到EP6中的数据,(我采用异步写的方式),但是发现FLAGC标志位没有在数据写满后拉低,而是在用逻辑分析仪再次采集数据的时候发现FLAGC拉低了,这是为什么?同时我用上面的程序去不能进行读数据,在DEVICEIOCONTROL的地方失败,请高手指点。谢过了。

最新喜欢:

lmhhlmhhlmhhlm...
guo_bin76
驱动牛犊
驱动牛犊
  • 注册日期2003-02-13
  • 最后登录2010-11-20
  • 粉丝0
  • 关注0
  • 积分129分
  • 威望74点
  • 贡献值1点
  • 好评度12点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-05-29 14:34
可能要
snow
idleman
驱动牛犊
驱动牛犊
  • 注册日期2003-01-17
  • 最后登录2003-08-08
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-05-29 15:33
问一个初级点的问题: 一块芯片有十几个EP,最后不会是都用吧?是不是根据需要选择四个(或6,8个)来做就可以呀?
宝剑锋从磨砺出 梅花香自苦寒来
BRANDER
驱动牛犊
驱动牛犊
  • 注册日期2002-09-29
  • 最后登录2009-05-01
  • 粉丝0
  • 关注0
  • 积分52分
  • 威望15点
  • 贡献值0点
  • 好评度5点
  • 原创分0分
  • 专家分0分
地板#
发布于:2003-05-29 15:50
我在I2C中的程序里面已经设置了相应的寄存器,用FLAGC表示EP6 IN,问题可能不在这上面的。
zyz1974
驱动小牛
驱动小牛
  • 注册日期2002-11-06
  • 最后登录2005-06-20
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2003-05-29 17:01
BRANDER
看来我们俩的项目比较相似,想想你请教问题,可以吗?我已经作了3个多月了。还没搞出来。希望多交流
我的qq 184355363
jinghuiren
驱动巨牛
驱动巨牛
  • 注册日期2002-06-01
  • 最后登录2008-10-27
  • 粉丝0
  • 关注0
  • 积分291分
  • 威望460点
  • 贡献值0点
  • 好评度428点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2003-05-29 21:57
三个月?
我可是做了一年!
也许是我比较笨吧
不过做那么快干什么
做完了这个还有新的活
偶认为能托就托! :D
仅限学生,要是给人打工的这么做被老板开了可别来找我! :D
yjmpepe
驱动牛犊
驱动牛犊
  • 注册日期2003-04-18
  • 最后登录2016-01-07
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2003-05-30 08:28
    我也只用了一个ep6,如果往fifo里写没有flag显示那固件很可能有问题。这个不好意思引用一下double发现的一个很奇怪的问题,他检查到flag引脚有问题,其他传输功能正常但就是引脚不指示。所以要看fifo是不是满了我建议可以在td_poll里判断一下EP2648STAR寄存器,然后用某个io指示一下。如果确实fifo里写不进数那deviceiocontrol是肯定不会返回正常值的。
    vc程序里必须用多线程技术,我也按你那么试过了不行,这是一份FAQ里说的。但你的现象很奇怪,按道理说如果deviceiocontrol没有读到数会把读线程block掉的,如果你程序运行到那里死掉了那就对了。如果你程序还返回了失败值那说明你的调用有问题。
yjmpepe
驱动牛犊
驱动牛犊
  • 注册日期2003-04-18
  • 最后登录2016-01-07
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2003-05-30 12:12
看看这段对你有没有用
General Purpose Driver (GPD) FAQ:
Question: The General Purpose device driver is used by calling a function called DeviceIoControl. DeviceIoControl has a parameter called IpOverlapped. What is IpOverlapped and how is it used?

Answer: The symbol is lpOverlapped (a long pointer to an OVERLAPPED structure), not IpOverlapped. You can get details about the OVERLAPPED structure in the Microsoft DDKs (see WINBASE.H, etc.). Essentially it allows for asynchronous DeviceIOControl calls. To make async calls, you must specify the FILE_FLAG_OVERLAPPED flag when you open the device handle. Then when you actually initiate I/O, the driver returns immediately. You then use a callback routine to signal the event associated with the overlapped I/O operation. Having said all that, you *cannot* use the OVERLAPPED (async) mechanism, because the GPD is strictly synchronous (blocks until the transfer > completes). You\'ll have to use the multi-thread technique discussed below, or write your own async driver.

Question: I have successfully been able to send the data out of the host, but I am stuck on the receive data part. The EZ-USB General Purpose Driver Specification says that the IOCTL_EZUSB_BULK_READ command will block the calling thread until the data transfer completes. What is a completed transfer? Is a NULL response from the peripheral considered a completed transfer or will blocking take place until valid data is sent from the peripheral device?

Answer: A BULK IN transfer is completed either when the exact requested amount of data is returned OR when a short packet (including a zero length packet) is returned by the device.

Question: Visual C++ (using Microsoft Foundation Classes) windows programming is event driven. In my test, I send data out whenever a Send button is pressed. I want to receive data asynchronously and not when the user presses a button. Where would I put a receive routine so that it is called periodically to check for data coming in from the device?

Answer: Spawn a thread just to do the Read. Then you use the thread synchronization Win32 APIs to determine whether the IOCTL_EZUSB_BULK_READ IOCTL has returned. (An event object is the appropriate thread sync mechanism. The Read thread would set the event object to \'signaled\' state. The non-Read thread would wait for the event object to reach the \'signaled\' state, or poll for \'signaled\' in the main event loop.) One of many references for using and synchronizing threads is Walter Oney\'s \"System Programming for Win95\".
lioniamhero
驱动小牛
驱动小牛
  • 注册日期2003-05-31
  • 最后登录2005-10-27
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
8楼#
发布于:2003-05-31 03:19
请教大虾:
CYPRESS的USB驱动怎么着手啊.用什么软件开发,怎么流程啊.
不胜感激.
游客

返回顶部