How to read from PCIe asynchronously using Microsoft I/O API

Questions and discussions about the Xillybus IP core and drivers

How to read from PCIe asynchronously using Microsoft I/O API

Postby nasy77 »

I am receiving data from FPGA via PCIe in a Qt application using low-level C run-time APIs like _open and _read. some packets are sent to FPGA , some processes are done and the output is received in the program. The thing is if parameters are set to wrong values, there will be no output from the FPGA and _read function does not return and the code is stuck at this function. Is there any way that I could make _read return, for example after some time or immediately if there was no output? I'm using these functions like it was explained in http://xillybus.com/downloads/doc/xilly ... indows.pdf .
What I'm basically doing is like the following code:

int fdRead = open("\\\\.\\xillybus_read1", O_RDONLY | _O_BINARY);
while(!stop)
readBytes = _read(fdRead, buffer, readSize);

How can I prevent blocking in _read function? Any help would be appreciated, thanks.
nasy77
 
Posts: 3
Joined:

Re: How to read from PCIe asynchronously using Microsoft I/O

Postby support »

Hello,

This is actually a question on Windows programming rather than on Xillybus: Does Windows' POSIX-like API support termination of a _read() call by virtue of something that corresponds to a POSIX signal? Or maybe opening the file descriptor as non-blocking? This is how it would have been done in Linux.

Truth is I don't know, and Microsoft's page on _read() says nothing in this direction:

https://docs.microsoft.com/en-us/cpp/c- ... w=msvc-170

What I would try out, is to run the I/O in a separate thread, and have the main thread kill it when appropriate to terminate the _read() call. The correct way to do this seems to be cooperative canceling:

https://docs.microsoft.com/en-us/dotnet ... -threading

But if I was to implement this, I would go for Windows' native API for asynchronous I/O, with a timer event. See section 3.5 in the Programming Guide for Windows:

http://xillybus.com/downloads/doc/xilly ... indows.pdf

This way or another, I suggest pursuing this issue in Windows-related forums etc.

Regards,
Eli
support
 
Posts: 802
Joined:

Re: How to read from PCIe asynchronously using Microsoft I/O

Postby nasy77 »

Hi Eli,

From what I've found there is no way to open a file descriptor as non-blocking on Windows (except for using sockets whose descriptors are different from files), so I'm gonna go with killing the I/O thread from main thread as you suggested.

Thank you,
Nasy
nasy77
 
Posts: 3
Joined:

Re: How to read from PCIe asynchronously using Microsoft I/O

Postby nasy77 »

nasy77 wrote:Hi Eli,

From what I've found there is no way to open a file descriptor as non-blocking on Windows (except for using sockets whose descriptors are different from files), so I'm gonna go with killing the I/O thread from main thread as you suggested.

Thank you,
Nasy


Actually I forgot to say that I did not try the third link which is for asynchronous I/O. Apparently if you open use CreateFile with FILE_FLAG_OVERLAPPED and call ReadFile or ReadFileEx , that will do the job but using threads seems to be quite handy.
nasy77
 
Posts: 3
Joined:

Re: How to read from PCIe asynchronously using Microsoft I/O

Postby support »

Hello,

Yes, overlapped I/O is the natural way to tackle that issue in Windows. I guess killing threads will also work, but I prefer a controlled execution flow.

Regards,
Eli
support
 
Posts: 802
Joined:


Return to Xillybus

cron