Usenet.com

www.Usenet.com

Group Index

Comp Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Re: FTDI isochronous USB transfer



Hello,

Please read above:

[EMAIL PROTECTED] wrote in message 
> You don't have to read the entire packet at once.
> You can read whatever is available and stuff it into a buffer
> until that buffer is the same size as the expected packet.

I set up some code like this:

1) Global variable (from a link in this thread):
CCircularBuffer< char, 14880000 > circBuffer;

2) Working thread's function:
UINT CTestMThreadDlg::USBCommThread(LPVOID pParam)
{
        CTestMThreadDlg* pTestMThread = (CTestMThreadDlg*) pParam;

        FT_STATUS ftStatus;
        DWORD eventDWord;
        DWORD rxBytes;
        DWORD txBytes;
        DWORD bytesReceived;
        char rxBuffer[63488];
        unsigned int dataReceived = 0;

        HANDLE hEvent = CreateEvent(
                NULL,
                false, // auto-reset event
                true, // non-signalled state
                "");
        // Check the value of the hEvent!!!
        if (hEvent == NULL) {
                DWORD lastError = GetLastError();
                printf("Error %d when tried to create handle\n", lastError);
        }
        else {
                DWORD eventMask = FT_EVENT_RXCHAR;
                ftStatus = FT_SetEventNotification(eventMask, hEvent);

                while (dataReceived < 148800) {
                        WaitForSingleObject(hEvent, INFINITE);

                        ftStatus  = FT_GetStatus(&rxBytes, &txBytes, 
                                &eventDWord);
                        
                        if (ftStatus == FT_OK && (eventDWord & FT_EVENT_RXCHAR) 
                                && rxBytes > 0) {
                                ftStatus = FT_Read(rxBuffer, rxBytes, 
                                        &bytesReceived);
                                circBuffer.Write(rxBuffer, rxBytes);
                                dataReceived += rxBytes;
                        }
                }
        }

        return 0;
}

I need/want to fill the complete buffer, or a buffer of that size
(14.88MB, or bigger!!!). My questions/problems that I am facing are:

1) Why if I pass the "false" value to the third parameter (initial
signaling state) of the CreateEvent function, the
WaitForSingleObject(hEvent, INFINITE); function NEVER returns?????? I
had to put it in _initial signaled_ state for it to return ("true"
value), but the documentation and examples here provided say something
very different. The other way, using the "false" value, is to use
WaitForSingleObject(hEvent, XXX), with XXX any timeout (I tried with
500, and worked).

2) (And the most important). I need to gather 14.88MB thru USB. In
order to do so, I have a counter of all the bytes received, which
increments every time I read data and write it to Circular Buffer. The
reading process continues until I have read all the data that I need.
The problem is that if I loop reading for more than 148800 bytes in
"while (dataReceived < 148800)", the thread seems to get blocked....
Why???? I've tried with values 2*148800, 1488000, and similar
(>148800) but it is always the same. It is worth saying that this
behaviour happens regardless of what I do in question 1)

All of your comments and recommendations are VERY welcome.

BTW, I've liked the fact that you also send the replies to my e-mail,
because that way I can have the feedback quicker (it takes a long time
in www.deja.com, where I post them).

Thank you very much,

JaaC

> 
> Of course this assume that the 1st byte is sync'ed with the start of a
> packet.  That's a reason for using using two threads with a circular
> buffer,  1) to read  the USB data and stuff it into the buffer as fast
> as it is available; 2) to parse the buffer, making sure you locate and
> sync with the proper "start of packet" sequence, and deliver the
> properly formated packet to the user application.



<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com



Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.