USB Host WAN Dongle library

Fork of USBHostWANDongle_bleedingedge by Donatien Garnier

Files at this revision

API Documentation at this revision

Comitter:
donatien
Date:
Thu Aug 30 09:15:55 2012 +0000
Parent:
9:c9e9817c398c
Child:
11:a0841fba0599
Commit message:
Fixed reinitialization issues

Changed in this revision

USB3GModule/IUSBHostSerial.h Show annotated file Show diff for this revision Revisions of this file
USB3GModule/IUSBHostSerialListener.h Show annotated file Show diff for this revision Revisions of this file
USB3GModule/WANDongle.cpp Show annotated file Show diff for this revision Revisions of this file
USB3GModule/WANDongle.h Show annotated file Show diff for this revision Revisions of this file
USB3GModule/WANDongleInitializer.cpp Show annotated file Show diff for this revision Revisions of this file
USB3GModule/WANDongleInitializer.h Show annotated file Show diff for this revision Revisions of this file
USB3GModule/WANDongleSerialPort.cpp Show annotated file Show diff for this revision Revisions of this file
USB3GModule/WANDongleSerialPort.h Show annotated file Show diff for this revision Revisions of this file
USBHost/USBDeviceConnected.cpp Show annotated file Show diff for this revision Revisions of this file
USBHost/USBDeviceConnected.h Show annotated file Show diff for this revision Revisions of this file
USBHost/USBEndpoint.h Show annotated file Show diff for this revision Revisions of this file
USBHost/USBHALHost.cpp Show annotated file Show diff for this revision Revisions of this file
USBHost/USBHALHost.h Show annotated file Show diff for this revision Revisions of this file
USBHost/USBHost.cpp Show annotated file Show diff for this revision Revisions of this file
USBHost/USBHost.h Show annotated file Show diff for this revision Revisions of this file
USBHost/USBHostTypes.h Show annotated file Show diff for this revision Revisions of this file
--- a/USB3GModule/IUSBHostSerial.h	Tue Jul 31 10:37:16 2012 +0000
+++ b/USB3GModule/IUSBHostSerial.h	Thu Aug 30 09:15:55 2012 +0000
@@ -1,27 +1,22 @@
 /* IUSBHostSerial.h */
-/*
-Copyright (C) 2012 ARM Limited.
-
-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 restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
+/* 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
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
-
 #ifndef IUSBHOSTSERIAL_H_
 #define IUSBHOSTSERIAL_H_
 
--- a/USB3GModule/IUSBHostSerialListener.h	Tue Jul 31 10:37:16 2012 +0000
+++ b/USB3GModule/IUSBHostSerialListener.h	Thu Aug 30 09:15:55 2012 +0000
@@ -1,24 +1,20 @@
 /* IUSBHostSerialListener.h */
-/*
-Copyright (C) 2012 ARM Limited.
-
-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 restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
+/* 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
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
 
 
--- a/USB3GModule/WANDongle.cpp	Tue Jul 31 10:37:16 2012 +0000
+++ b/USB3GModule/WANDongle.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
@@ -121,6 +121,16 @@
   return false;
 }
 
+bool WANDongle::disconnect()
+{
+  dev_connected = false;
+  for(int i = 0; i < WANDONGLE_MAX_SERIAL_PORTS; i++)
+  {
+    m_serial[i].disconnect();
+  }
+  return true;
+}
+
 WAN_DONGLE_TYPE WANDongle::getDongleType()
 {
   if( m_pInitializer != NULL )
@@ -146,6 +156,7 @@
 //Private methods
 void WANDongle::init()
 {
+  m_pInitializer = NULL;
   dev_connected = false;
   for(int i = 0; i < WANDONGLE_MAX_SERIAL_PORTS; i++)
   {
@@ -157,31 +168,31 @@
 /*virtual*/ void WANDongle::setVidPid(uint16_t vid, uint16_t pid)
 {
     //Load right initializer
-          WANDongleInitializer** initializer = WANDongleInitializer::getInitializers(host);
-          
-          while(*initializer)
-          {
-            DBG("*initializer=%p", *initializer);
-            DBG("(*initializer)->getSerialVid()=%04x", (*initializer)->getSerialVid());
-            DBG("(*initializer)->getSerialPid()=%04x", (*initializer)->getSerialPid());
-            if ((dev->getVid() == (*initializer)->getSerialVid()) && (dev->getPid() == (*initializer)->getSerialPid()))
-            {
-              DBG("The dongle is in virtual serial mode");
-              m_pInitializer = *initializer;
-              break;
-            }
-            else if ((dev->getVid() == (*initializer)->getMSDVid()) && (dev->getPid() == (*initializer)->getMSDPid()))
-            {
-              DBG("Vodafone K3370 dongle detected in MSD mode");
-              m_pInitializer = *initializer;
-              break;
-            }
-            initializer++;
-          } //while()
-          if(m_pInitializer)
-          {
-            m_pInitializer->setVidPid(vid, pid);
-          }
+  WANDongleInitializer** initializer = WANDongleInitializer::getInitializers(host);
+  
+  while(*initializer)
+  {
+    DBG("*initializer=%p", *initializer);
+    DBG("(*initializer)->getSerialVid()=%04x", (*initializer)->getSerialVid());
+    DBG("(*initializer)->getSerialPid()=%04x", (*initializer)->getSerialPid());
+    if ((dev->getVid() == (*initializer)->getSerialVid()) && (dev->getPid() == (*initializer)->getSerialPid()))
+    {
+      DBG("The dongle is in virtual serial mode");
+      m_pInitializer = *initializer;
+      break;
+    }
+    else if ((dev->getVid() == (*initializer)->getMSDVid()) && (dev->getPid() == (*initializer)->getMSDPid()))
+    {
+      DBG("Vodafone K3370 dongle detected in MSD mode");
+      m_pInitializer = *initializer;
+      break;
+    }
+    initializer++;
+  } //while()
+  if(m_pInitializer)
+  {
+    m_pInitializer->setVidPid(vid, pid);
+  }
 }
 
 /*virtual*/ bool WANDongle::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed
--- a/USB3GModule/WANDongle.h	Tue Jul 31 10:37:16 2012 +0000
+++ b/USB3GModule/WANDongle.h	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
@@ -58,6 +58,13 @@
      * * @return true if connection was successful
      */
     bool tryConnect();
+    
+    /*
+     * Disconnect device
+     *
+     * * @return true if disconnection was successful
+     */
+    bool disconnect();
        
     WAN_DONGLE_TYPE getDongleType();
     
--- a/USB3GModule/WANDongleInitializer.cpp	Tue Jul 31 10:37:16 2012 +0000
+++ b/USB3GModule/WANDongleInitializer.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__ 0 //Maximum verbosity
+#define __DEBUG__ 0
 #ifndef __MODULE__
 #define __MODULE__ "WANDongleInitializer.cpp"
 #endif
--- a/USB3GModule/WANDongleInitializer.h	Tue Jul 31 10:37:16 2012 +0000
+++ b/USB3GModule/WANDongleInitializer.h	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
--- 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();
   }
 }
--- a/USB3GModule/WANDongleSerialPort.h	Tue Jul 31 10:37:16 2012 +0000
+++ b/USB3GModule/WANDongleSerialPort.h	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
--- a/USBHost/USBDeviceConnected.cpp	Tue Jul 31 10:37:16 2012 +0000
+++ b/USBHost/USBDeviceConnected.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
--- a/USBHost/USBDeviceConnected.h	Tue Jul 31 10:37:16 2012 +0000
+++ b/USBHost/USBDeviceConnected.h	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
--- a/USBHost/USBEndpoint.h	Tue Jul 31 10:37:16 2012 +0000
+++ b/USBHost/USBEndpoint.h	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
--- a/USBHost/USBHALHost.cpp	Tue Jul 31 10:37:16 2012 +0000
+++ b/USBHost/USBHALHost.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
@@ -13,8 +13,8 @@
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/
-
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
 
 #define __DEBUG__ 0 //WARN: ENABLING DEBUGGING HERE WILL PRINTF IN IRQS!! UNEXPECTED BEHAVIOUR MAY RESULT...
 #ifndef __MODULE__
--- a/USBHost/USBHALHost.h	Tue Jul 31 10:37:16 2012 +0000
+++ b/USBHost/USBHALHost.h	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
--- a/USBHost/USBHost.cpp	Tue Jul 31 10:37:16 2012 +0000
+++ b/USBHost/USBHost.cpp	Thu Aug 30 09:15:55 2012 +0000
@@ -1,21 +1,20 @@
-/* Copyright (c) 2010-2011 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
- * restriction, including without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
+/* 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
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
 
 #define __DEBUG__ 0 //WARN: ENABLING DEBUGGING HERE WILL PRINTF IN IRQS!! UNEXPECTED BEHAVIOUR MAY RESULT...
 #ifndef __MODULE__
--- a/USBHost/USBHost.h	Tue Jul 31 10:37:16 2012 +0000
+++ b/USBHost/USBHost.h	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
--- a/USBHost/USBHostTypes.h	Tue Jul 31 10:37:16 2012 +0000
+++ b/USBHost/USBHostTypes.h	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