USBHost library. NOTE: This library is only officially supported on the LPC1768 platform. For more information, please see the handbook page.

Dependencies:   FATFileSystem mbed-rtos

Dependents:   BTstack WallbotWii SD to Flash Data Transfer USBHost-MSD_HelloWorld ... more

Issue: probable wasted position in MtxCircBuffer buffer

Hello,

As part of the USBHostSerial class we are making use of MtxCircBuffer. This class has the following method to write the received data in the internal buffer :

    void queue(T k)
    {
        mtx.lock();
        while (((write + 1) % size) == read)
        {
            mtx.unlock();
            Thread::wait(10);
            mtx.lock();
        }
        buf[write++] = k;
        write %= size;
        mtx.unlock();
    }

As far as we can see the last postion of the buffer is not written due to this line:

while (((write + 1) % size) == read)

We thing it should be:

while ( (write % size) == read )

For example in the case where:

size == 64 (write should go from 0 to 63 to use all the buffer positions) write == 63 (last valid position of buffer) read ==0

we have:

while ((63+1) % 64) == 0

We end up waiting here as if the buffer was full when actually we still have the last position available.