Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of VodafoneUSBModem by
Diff: serial/usb/USBSerialStream.cpp
- Revision:
- 10:21a6f09d5631
- Parent:
- 8:04b6a042595f
- Child:
- 22:06fb2a93a1f6
diff -r 04b6a042595f -r 21a6f09d5631 serial/usb/USBSerialStream.cpp --- a/serial/usb/USBSerialStream.cpp Tue Jun 26 13:44:59 2012 +0000 +++ b/serial/usb/USBSerialStream.cpp Fri Jul 06 08:56:32 2012 +0000 @@ -57,7 +57,8 @@ WARN("Error %d while waiting for incoming data", ret); return ret; } - int readLen = MIN( available(), maxLength ); + int a = available(); //Prevent macro issues + int readLen = MIN( a, maxLength ); *pLength = readLen; setupReadableISR(false); @@ -84,7 +85,7 @@ int ret; if(available()) //Is data already available? { - m_availableSphre.wait(0); //Clear the queue as data is available + while( m_availableSphre.wait(0) > 0 ); //Clear the queue as data is available return OK; } @@ -101,7 +102,7 @@ return NET_INTERRUPTED; } DBG("Finished waiting"); - m_availableSphre.wait(0); //Clear the queue as data is available + while( m_availableSphre.wait(0) > 0 ); //Clear the queue as data is available return OK; } @@ -142,11 +143,12 @@ int ret = waitSpace(timeout); if(ret) { - WARN("Error %d while waiting for space"); + WARN("Error %d while waiting for space", ret); return ret; } - int writeLen = MIN( space(), length ); - DBG("Writing %d chars", length); + int s = space(); //Prevent macro issues + int writeLen = MIN( s, length ); + DBG("Writing %d chars", writeLen); setupWriteableISR(false); while(writeLen) { @@ -155,15 +157,14 @@ length--; writeLen--; } + //If m_serial tx fifo is empty we need to start the packet write + if( m_outBuf.available() && m_serialTxFifoEmpty ) + { + writeable(); + } setupWriteableISR(true); } while(length); - //If m_serial tx fifo is empty we need to start the packet write - setupWriteableISR(false); - if( m_outBuf.available() && m_serialTxFifoEmpty ) - { - writeable(); - } - setupWriteableISR(true); + DBG("Write successful"); return OK; } @@ -181,7 +182,7 @@ int ret; if(space()) //Is still space already left? { - m_spaceSphre.wait(0); //Clear the queue as space is available + while( m_spaceSphre.wait(0) > 0); //Clear the queue as space is available return OK; } @@ -197,7 +198,7 @@ DBG("Aborted"); return NET_INTERRUPTED; } - m_spaceSphre.wait(0); //Clear the queue as space is available + while( m_spaceSphre.wait(0) > 0); //Clear the queue as space is available return OK; } @@ -230,8 +231,10 @@ m_outBuf.dequeue(&c); m_serial.putc((char)c); } - static volatile int i=0; m_serial.writePacket(); //Start packet write } - m_spaceSphre.release(); //Force exiting the waiting state + if(!m_outBuf.isFull()) + { + m_spaceSphre.release(); //Force exiting the waiting state + } }