Changes to support Vodafone K4606
Fork of USBHostWANDongle by
Diff: USB3GModule/WANDongleSerialPort.cpp
- Revision:
- 10:08bce4cd973a
- Parent:
- 9:c9e9817c398c
- Child:
- 13:c154e7f2e42f
--- a/USB3GModule/WANDongleSerialPort.cpp Tue Jul 31 10:37:16 2012 +0000 +++ b/USB3GModule/WANDongleSerialPort.cpp Thu Aug 30 09:15:55 2012 +0000 @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2011 mbed.org, MIT License +/* Copyright (c) 2010-2012 mbed.org, MIT License * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software * and associated documentation files (the "Software"), to deal in the Software without @@ -16,7 +16,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#define __DEBUG__ 4 //Maximum verbosity +#define __DEBUG__ 0 #ifndef __MODULE__ #define __MODULE__ "WANDongleSerialPort.cpp" #endif @@ -39,6 +39,9 @@ void WANDongleSerialPort::reset() { + tx_mtx.lock(); + rx_mtx.lock(); + bulk_in = NULL; bulk_out = NULL; @@ -51,10 +54,14 @@ buf_in_read_pos = 0; lock_rx = false; cb_rx_pending = false; + + tx_mtx.unlock(); + rx_mtx.unlock(); } int WANDongleSerialPort::readPacket() { + DBG("Read packet on %p", this); rx_mtx.lock(); if(lock_rx) { @@ -62,6 +69,13 @@ rx_mtx.unlock(); return -1; } + + if( bulk_in == NULL ) + { + WARN("Port is disconnected"); + rx_mtx.unlock(); + return -1; + } lock_rx = true; //Receiving rx_mtx.unlock(); @@ -90,6 +104,13 @@ tx_mtx.unlock(); return -1; } + + if( bulk_out == NULL ) + { + WARN("Port is disconnected"); + tx_mtx.unlock(); + return -1; + } lock_tx = true; //Transmitting tx_mtx.unlock(); @@ -286,6 +307,7 @@ else //Error, try reading again { //lock_rx.unlock(); + DBG("Trying again"); readPacket(); } }