USB Host WAN Dongle library
Fork of USBHostWANDongle_bleedingedge by
Revision 9:c9e9817c398c, committed 2012-07-31
- Comitter:
- donatien
- Date:
- Tue Jul 31 10:37:16 2012 +0000
- Parent:
- 8:0d1ec493842c
- Child:
- 10:08bce4cd973a
- Child:
- 12:a712bad7a979
- Commit message:
- Renamed Endpoint->USBEndpoint because it conflicted with the Socket API! Made some weird symbols mixups happen that made everything explode when the first USB endpoint was allocated.
Changed in this revision
--- a/USB3GModule/WANDongleInitializer.cpp Mon Jul 30 13:51:34 2012 +0000 +++ b/USB3GModule/WANDongleInitializer.cpp Tue Jul 31 10:37:16 2012 +0000 @@ -64,7 +64,7 @@ { if (pDev->getInterface(i)->intf_class == MSD_CLASS) { - Endpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); + USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); if ( pEp != NULL ) { DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i); @@ -76,7 +76,7 @@ return false; } -Endpoint* VodafoneK3770Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) +USBEndpoint* VodafoneK3770Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) { return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0); } @@ -174,7 +174,7 @@ { if (pDev->getInterface(i)->intf_class == MSD_CLASS) { - Endpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); + USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); if ( pEp != NULL ) { DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i); @@ -186,7 +186,7 @@ return false; } -Endpoint* VodafoneK3772ZInitializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) +USBEndpoint* VodafoneK3772ZInitializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) { return pDev->getEndpoint((serialPortNumber==1)?0:1, BULK_ENDPOINT, tx?OUT:IN, 0); } @@ -240,7 +240,7 @@ { if( m_hasSwitched ) { - DBG("Endpoint on Inteface #%d; Type:%d; Direction:%d", intf_nb, type, dir); + DBG("USBEndpoint on Inteface #%d; Type:%d; Direction:%d", intf_nb, type, dir); if( (type == BULK_ENDPOINT) && m_endpointsToFetch ) { m_endpointsToFetch--;
--- a/USB3GModule/WANDongleInitializer.h Mon Jul 30 13:51:34 2012 +0000 +++ b/USB3GModule/WANDongleInitializer.h Tue Jul 31 10:37:16 2012 +0000 @@ -48,7 +48,7 @@ virtual bool switchMode(USBDeviceConnected* pDev) = 0; - virtual Endpoint* getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) = 0; + virtual USBEndpoint* getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) = 0; virtual int getSerialPortCount() = 0; @@ -76,7 +76,7 @@ virtual bool switchMode(USBDeviceConnected* pDev); - virtual Endpoint* getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx); + virtual USBEndpoint* getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx); virtual int getSerialPortCount(); @@ -108,7 +108,7 @@ virtual bool switchMode(USBDeviceConnected* pDev); - virtual Endpoint* getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx); + virtual USBEndpoint* getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx); virtual int getSerialPortCount();
--- a/USB3GModule/WANDongleSerialPort.cpp Mon Jul 30 13:51:34 2012 +0000 +++ b/USB3GModule/WANDongleSerialPort.cpp Tue Jul 31 10:37:16 2012 +0000 @@ -1,318 +1,318 @@ -/* 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. -*/ - -#define __DEBUG__ 4 //Maximum verbosity -#ifndef __MODULE__ -#define __MODULE__ "WANDongleSerialPort.cpp" -#endif - -#include "dbg.h" -#include <cstdint> -#include "rtos.h" - -#include "WANDongleSerialPort.h" - -WANDongleSerialPort::WANDongleSerialPort() : cb_tx_en(false), cb_rx_en(false), listener(NULL) -{ - reset(); -} - -void WANDongleSerialPort::init(USBHost* pHost) -{ - host = pHost; -} - -void WANDongleSerialPort::reset() -{ - bulk_in = NULL; - bulk_out = NULL; - - buf_out_len = 0; - max_out_size = 0; - lock_tx = false; - cb_tx_pending = false; - - buf_in_len = 0; - buf_in_read_pos = 0; - lock_rx = false; - cb_rx_pending = false; -} - -int WANDongleSerialPort::readPacket() -{ - rx_mtx.lock(); - if(lock_rx) - { - ERR("Fail"); - rx_mtx.unlock(); - return -1; - } - - lock_rx = true; //Receiving - rx_mtx.unlock(); -// DBG("readPacket"); - //lock_rx.lock(); - host->lock(); - USB_TYPE res = host->bulkRead(dev, (Endpoint *)bulk_in, buf_in, ((Endpoint *)bulk_in)->getSize(), false); //Queue transfer - if(res != USB_TYPE_PROCESSING) - { - host->unlock(); - //lock_rx.unlock(); - ERR("host->bulkRead() returned %d", res); - Thread::wait(100); - return -1; - } - host->unlock(); - return 0; -} - -int WANDongleSerialPort::writePacket() -{ - tx_mtx.lock(); - if(lock_tx) - { - ERR("Fail"); - tx_mtx.unlock(); - return -1; - } - - lock_tx = true; //Transmitting - tx_mtx.unlock(); -// DBG("writePacket"); - - //lock_tx.lock(); - host->lock(); - USB_TYPE res = host->bulkWrite(dev, (Endpoint *)bulk_out, buf_out, buf_out_len, false); //Queue transfer - if(res != USB_TYPE_PROCESSING) - { - host->unlock(); - //lock_tx.unlock(); - ERR("host->bulkWrite() returned %d", res); - Thread::wait(100); - return -1; - } - host->unlock(); - return 0; -} - -int WANDongleSerialPort::putc(int c) -{ - tx_mtx.lock(); - if(!lock_tx) - { - if(buf_out_len < max_out_size) - { - buf_out[buf_out_len] = (uint8_t)c; - buf_out_len++; - } - } - else - { - ERR("CAN'T WRITE!"); - } - tx_mtx.unlock(); - return c; -} - -int WANDongleSerialPort::getc() -{ - rx_mtx.lock(); - int c = 0; - if(!lock_rx) - { - if(buf_in_read_pos < buf_in_len) - { - c = (int)buf_in[buf_in_read_pos]; - buf_in_read_pos++; - } - } - else - { - ERR("CAN'T READ!"); - } - rx_mtx.unlock(); - return c; -} - -int WANDongleSerialPort::readable() -{ - rx_mtx.lock(); - if (lock_rx) - { - rx_mtx.unlock(); - return 0; - } - - /* if( !lock_rx.trylock() ) - { - return 0; - }*/ - int res = buf_in_len - buf_in_read_pos; - //lock_rx.unlock(); - rx_mtx.unlock(); - return res; -} - -int WANDongleSerialPort::writeable() -{ - tx_mtx.lock(); - if (lock_tx) - { - tx_mtx.unlock(); - return 0; - } - - /*if( !lock_tx.trylock() ) - { - return 0; - }*/ - int res = max_out_size - buf_out_len; - tx_mtx.unlock(); - //lock_tx.unlock(); - return res; -} - -void WANDongleSerialPort::attach(IUSBHostSerialListener* pListener) -{ - if(pListener == NULL) - { - setupIrq(false, RxIrq); - setupIrq(false, TxIrq); - } - listener = pListener; - if(pListener != NULL) - { - setupIrq(true, RxIrq); - setupIrq(true, TxIrq); - } -} - -void WANDongleSerialPort::setupIrq(bool en, IrqType irq /*= RxIrq*/) -{ - switch(irq) - { - case RxIrq: - rx_mtx.lock(); - cb_rx_en = en; - if(en && cb_rx_pending) - { - cb_rx_pending = false; - rx_mtx.unlock(); - listener->readable(); //Process the interrupt that was raised - } - else - { - rx_mtx.unlock(); - } - break; - case TxIrq: - tx_mtx.lock(); - cb_tx_en = en; - if(en && cb_tx_pending) - { - cb_tx_pending = false; - tx_mtx.unlock(); - listener->writeable(); //Process the interrupt that was raised - } - else - { - tx_mtx.unlock(); - } - break; - } -} - - -void WANDongleSerialPort::connect( USBDeviceConnected* pDev, Endpoint* pInEp, Endpoint* pOutEp ) -{ - dev = pDev; - bulk_in = pInEp; - bulk_out = pOutEp; - max_out_size = bulk_out->getSize(); - if( max_out_size > WANDONGLE_MAX_OUTEP_SIZE ) - { - max_out_size = WANDONGLE_MAX_OUTEP_SIZE; - } - bulk_in->attach(this, &WANDongleSerialPort::rxHandler); - bulk_out->attach(this, &WANDongleSerialPort::txHandler); - readPacket(); //Start receiving data -} - -void WANDongleSerialPort::disconnect( ) -{ - reset(); -} - -//Private methods - - -void WANDongleSerialPort::rxHandler() -{ - if (((Endpoint *) bulk_in)->getState() == USB_TYPE_IDLE) //Success - { - buf_in_read_pos = 0; - buf_in_len = ((Endpoint *) bulk_in)->getLengthTransferred(); //Update length - //lock_rx.unlock(); - rx_mtx.lock(); - lock_rx = false; //Transmission complete - if(cb_rx_en) - { - rx_mtx.unlock(); - listener->readable(); //Call handler from the IRQ context - //readPacket() should be called by the handler subsequently once the buffer has been emptied - } - else - { - cb_rx_pending = true; //Queue the callback - rx_mtx.unlock(); - } - - } - else //Error, try reading again - { - //lock_rx.unlock(); - readPacket(); - } -} - -void WANDongleSerialPort::txHandler() -{ - if (((Endpoint *) bulk_out)->getState() == USB_TYPE_IDLE) //Success - { - tx_mtx.lock(); - buf_out_len = 0; //Reset length - lock_tx = false; //Transmission complete - //lock_tx.unlock(); - if(cb_tx_en) - { - tx_mtx.unlock(); - listener->writeable(); //Call handler from the IRQ context - //writePacket() should be called by the handler subsequently once the buffer has been filled - } - else - { - cb_tx_pending = true; //Queue the callback - tx_mtx.unlock(); - } - } - else //Error, try reading again - { - //lock_tx.unlock(); - writePacket(); - } -} +/* 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. +*/ + +#define __DEBUG__ 4 //Maximum verbosity +#ifndef __MODULE__ +#define __MODULE__ "WANDongleSerialPort.cpp" +#endif + +#include "dbg.h" +#include <cstdint> +#include "rtos.h" + +#include "WANDongleSerialPort.h" + +WANDongleSerialPort::WANDongleSerialPort() : cb_tx_en(false), cb_rx_en(false), listener(NULL) +{ + reset(); +} + +void WANDongleSerialPort::init(USBHost* pHost) +{ + host = pHost; +} + +void WANDongleSerialPort::reset() +{ + bulk_in = NULL; + bulk_out = NULL; + + buf_out_len = 0; + max_out_size = 0; + lock_tx = false; + cb_tx_pending = false; + + buf_in_len = 0; + buf_in_read_pos = 0; + lock_rx = false; + cb_rx_pending = false; +} + +int WANDongleSerialPort::readPacket() +{ + rx_mtx.lock(); + if(lock_rx) + { + ERR("Fail"); + rx_mtx.unlock(); + return -1; + } + + lock_rx = true; //Receiving + rx_mtx.unlock(); +// DBG("readPacket"); + //lock_rx.lock(); + host->lock(); + USB_TYPE res = host->bulkRead(dev, (USBEndpoint *)bulk_in, buf_in, ((USBEndpoint *)bulk_in)->getSize(), false); //Queue transfer + if(res != USB_TYPE_PROCESSING) + { + host->unlock(); + //lock_rx.unlock(); + ERR("host->bulkRead() returned %d", res); + Thread::wait(100); + return -1; + } + host->unlock(); + return 0; +} + +int WANDongleSerialPort::writePacket() +{ + tx_mtx.lock(); + if(lock_tx) + { + ERR("Fail"); + tx_mtx.unlock(); + return -1; + } + + lock_tx = true; //Transmitting + tx_mtx.unlock(); +// DBG("writePacket"); + + //lock_tx.lock(); + host->lock(); + USB_TYPE res = host->bulkWrite(dev, (USBEndpoint *)bulk_out, buf_out, buf_out_len, false); //Queue transfer + if(res != USB_TYPE_PROCESSING) + { + host->unlock(); + //lock_tx.unlock(); + ERR("host->bulkWrite() returned %d", res); + Thread::wait(100); + return -1; + } + host->unlock(); + return 0; +} + +int WANDongleSerialPort::putc(int c) +{ + tx_mtx.lock(); + if(!lock_tx) + { + if(buf_out_len < max_out_size) + { + buf_out[buf_out_len] = (uint8_t)c; + buf_out_len++; + } + } + else + { + ERR("CAN'T WRITE!"); + } + tx_mtx.unlock(); + return c; +} + +int WANDongleSerialPort::getc() +{ + rx_mtx.lock(); + int c = 0; + if(!lock_rx) + { + if(buf_in_read_pos < buf_in_len) + { + c = (int)buf_in[buf_in_read_pos]; + buf_in_read_pos++; + } + } + else + { + ERR("CAN'T READ!"); + } + rx_mtx.unlock(); + return c; +} + +int WANDongleSerialPort::readable() +{ + rx_mtx.lock(); + if (lock_rx) + { + rx_mtx.unlock(); + return 0; + } + + /* if( !lock_rx.trylock() ) + { + return 0; + }*/ + int res = buf_in_len - buf_in_read_pos; + //lock_rx.unlock(); + rx_mtx.unlock(); + return res; +} + +int WANDongleSerialPort::writeable() +{ + tx_mtx.lock(); + if (lock_tx) + { + tx_mtx.unlock(); + return 0; + } + + /*if( !lock_tx.trylock() ) + { + return 0; + }*/ + int res = max_out_size - buf_out_len; + tx_mtx.unlock(); + //lock_tx.unlock(); + return res; +} + +void WANDongleSerialPort::attach(IUSBHostSerialListener* pListener) +{ + if(pListener == NULL) + { + setupIrq(false, RxIrq); + setupIrq(false, TxIrq); + } + listener = pListener; + if(pListener != NULL) + { + setupIrq(true, RxIrq); + setupIrq(true, TxIrq); + } +} + +void WANDongleSerialPort::setupIrq(bool en, IrqType irq /*= RxIrq*/) +{ + switch(irq) + { + case RxIrq: + rx_mtx.lock(); + cb_rx_en = en; + if(en && cb_rx_pending) + { + cb_rx_pending = false; + rx_mtx.unlock(); + listener->readable(); //Process the interrupt that was raised + } + else + { + rx_mtx.unlock(); + } + break; + case TxIrq: + tx_mtx.lock(); + cb_tx_en = en; + if(en && cb_tx_pending) + { + cb_tx_pending = false; + tx_mtx.unlock(); + listener->writeable(); //Process the interrupt that was raised + } + else + { + tx_mtx.unlock(); + } + break; + } +} + + +void WANDongleSerialPort::connect( USBDeviceConnected* pDev, USBEndpoint* pInEp, USBEndpoint* pOutEp ) +{ + dev = pDev; + bulk_in = pInEp; + bulk_out = pOutEp; + max_out_size = bulk_out->getSize(); + if( max_out_size > WANDONGLE_MAX_OUTEP_SIZE ) + { + max_out_size = WANDONGLE_MAX_OUTEP_SIZE; + } + bulk_in->attach(this, &WANDongleSerialPort::rxHandler); + bulk_out->attach(this, &WANDongleSerialPort::txHandler); + readPacket(); //Start receiving data +} + +void WANDongleSerialPort::disconnect( ) +{ + reset(); +} + +//Private methods + + +void WANDongleSerialPort::rxHandler() +{ + if (((USBEndpoint *) bulk_in)->getState() == USB_TYPE_IDLE) //Success + { + buf_in_read_pos = 0; + buf_in_len = ((USBEndpoint *) bulk_in)->getLengthTransferred(); //Update length + //lock_rx.unlock(); + rx_mtx.lock(); + lock_rx = false; //Transmission complete + if(cb_rx_en) + { + rx_mtx.unlock(); + listener->readable(); //Call handler from the IRQ context + //readPacket() should be called by the handler subsequently once the buffer has been emptied + } + else + { + cb_rx_pending = true; //Queue the callback + rx_mtx.unlock(); + } + + } + else //Error, try reading again + { + //lock_rx.unlock(); + readPacket(); + } +} + +void WANDongleSerialPort::txHandler() +{ + if (((USBEndpoint *) bulk_out)->getState() == USB_TYPE_IDLE) //Success + { + tx_mtx.lock(); + buf_out_len = 0; //Reset length + lock_tx = false; //Transmission complete + //lock_tx.unlock(); + if(cb_tx_en) + { + tx_mtx.unlock(); + listener->writeable(); //Call handler from the IRQ context + //writePacket() should be called by the handler subsequently once the buffer has been filled + } + else + { + cb_tx_pending = true; //Queue the callback + tx_mtx.unlock(); + } + } + else //Error, try reading again + { + //lock_tx.unlock(); + writePacket(); + } +}
--- a/USB3GModule/WANDongleSerialPort.h Mon Jul 30 13:51:34 2012 +0000 +++ b/USB3GModule/WANDongleSerialPort.h Tue Jul 31 10:37:16 2012 +0000 @@ -1,126 +1,126 @@ -/* 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. -*/ - -#ifndef WANDONGLESERIALPORT_H -#define WANDONGLESERIALPORT_H - -#include "USBHost.h" -#include "IUSBHostSerial.h" - -#include "rtos.h" - - -#define WANDONGLE_MAX_OUTEP_SIZE 64 -#define WANDONGLE_MAX_INEP_SIZE 64 - -/** A class to use a WAN (3G/LTE) access dongle - * - */ -class WANDongleSerialPort : public IUSBHostSerial { -public: - /* - * Constructor - * - */ - WANDongleSerialPort(); - - void init( USBHost* pHost ); - - void connect( USBDeviceConnected* pDev, Endpoint* pInEp, Endpoint* pOutEp ); - - void disconnect( ); - - /* - * Get a char from the dongle's serial interface - */ - virtual int getc(); - - /* - * Put a char to the dongle's serial interface - */ - virtual int putc(int c); - - /* - * Read a packet from the dongle's serial interface, to be called after multiple getc() calls - */ - virtual int readPacket(); - - /* - * Write a packet to the dongle's serial interface, to be called after multiple putc() calls - */ - virtual int writePacket(); - - /** - * Check the number of bytes available. - * - * @returns the number of bytes available - */ - virtual int readable(); - - /** - * Check the free space in output. - * - * @returns the number of bytes available - */ - virtual int writeable(); - - /** - * Attach a handler to call when a packet is received / when a packet has been transmitted. - * - * @param pListener instance of the listener deriving from the IUSBHostSerialListener - */ - virtual void attach(IUSBHostSerialListener* pListener); - - /** - * Enable or disable readable/writeable callbacks - */ - virtual void setupIrq(bool en, IrqType irq = RxIrq); - - -protected: - Endpoint * bulk_in; - Endpoint * bulk_out; - USBHost * host; - USBDeviceConnected * dev; - - uint8_t buf_out[WANDONGLE_MAX_OUTEP_SIZE]; - volatile uint32_t buf_out_len; - uint32_t max_out_size; - volatile bool lock_tx; - volatile bool cb_tx_en; - volatile bool cb_tx_pending; - Mutex tx_mtx; - - uint8_t buf_in[WANDONGLE_MAX_INEP_SIZE]; - volatile uint32_t buf_in_len; - volatile uint32_t buf_in_read_pos; - volatile bool lock_rx; - volatile bool cb_rx_en; - volatile bool cb_rx_pending; - Mutex rx_mtx; - - IUSBHostSerialListener* listener; - - void reset(); - - void rxHandler(); - void txHandler(); - -}; - -#endif +/* 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. +*/ + +#ifndef WANDONGLESERIALPORT_H +#define WANDONGLESERIALPORT_H + +#include "USBHost.h" +#include "IUSBHostSerial.h" + +#include "rtos.h" + + +#define WANDONGLE_MAX_OUTEP_SIZE 64 +#define WANDONGLE_MAX_INEP_SIZE 64 + +/** A class to use a WAN (3G/LTE) access dongle + * + */ +class WANDongleSerialPort : public IUSBHostSerial { +public: + /* + * Constructor + * + */ + WANDongleSerialPort(); + + void init( USBHost* pHost ); + + void connect( USBDeviceConnected* pDev, USBEndpoint* pInEp, USBEndpoint* pOutEp ); + + void disconnect( ); + + /* + * Get a char from the dongle's serial interface + */ + virtual int getc(); + + /* + * Put a char to the dongle's serial interface + */ + virtual int putc(int c); + + /* + * Read a packet from the dongle's serial interface, to be called after multiple getc() calls + */ + virtual int readPacket(); + + /* + * Write a packet to the dongle's serial interface, to be called after multiple putc() calls + */ + virtual int writePacket(); + + /** + * Check the number of bytes available. + * + * @returns the number of bytes available + */ + virtual int readable(); + + /** + * Check the free space in output. + * + * @returns the number of bytes available + */ + virtual int writeable(); + + /** + * Attach a handler to call when a packet is received / when a packet has been transmitted. + * + * @param pListener instance of the listener deriving from the IUSBHostSerialListener + */ + virtual void attach(IUSBHostSerialListener* pListener); + + /** + * Enable or disable readable/writeable callbacks + */ + virtual void setupIrq(bool en, IrqType irq = RxIrq); + + +protected: + USBEndpoint * bulk_in; + USBEndpoint * bulk_out; + USBHost * host; + USBDeviceConnected * dev; + + uint8_t buf_out[WANDONGLE_MAX_OUTEP_SIZE]; + volatile uint32_t buf_out_len; + uint32_t max_out_size; + volatile bool lock_tx; + volatile bool cb_tx_en; + volatile bool cb_tx_pending; + Mutex tx_mtx; + + uint8_t buf_in[WANDONGLE_MAX_INEP_SIZE]; + volatile uint32_t buf_in_len; + volatile uint32_t buf_in_read_pos; + volatile bool lock_rx; + volatile bool cb_rx_en; + volatile bool cb_rx_pending; + Mutex rx_mtx; + + IUSBHostSerialListener* listener; + + void reset(); + + void rxHandler(); + void txHandler(); + +}; + +#endif
--- a/USBHost/Endpoint.cpp Mon Jul 30 13:51:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,233 +0,0 @@ -/* 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. -*/ - - -#define __DEBUG__ 0 //Maximum verbosity -#ifndef __MODULE__ -#define __MODULE__ "Endpoint.cpp" -#endif - -#include "dbg.h" -#include <cstdint> - -#include "Endpoint.h" - - -void Endpoint::init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]) { - this->hced = hced; - this->type = type; - this->dir = /*(type == CONTROL_ENDPOINT) ? OUT :*/ dir; - setup = (type == CONTROL_ENDPOINT) ? true : false; - - //TDs have been allocated by the host - memcpy((HCTD**)this->td_list, td_list, sizeof(HCTD*)*2); //TODO: Maybe should add a param for td_list size... at least a define - memcpy(td_list[0], 0, sizeof(HCTD)); - memcpy(td_list[1], 0, sizeof(HCTD)); - - this->hced->control = 0; - //Empty queue - this->hced->tailTD = (uint32_t)td_list[0]; - this->hced->headTD = (uint32_t)td_list[0]; - this->hced->nextED = 0; - - this->hced->control = ((ep_number & 0x7F) << 7) // Endpoint address - | (type != CONTROL_ENDPOINT ? ( dir << 11) : 0 ) // direction : Out = 1, 2 = In - | ((size & 0x3ff) << 16); // MaxPkt Size - - //carry = false; - transfer_len = 0; - transferred = 0; - buf_start = 0; - nextEp = NULL; - - td_current = td_list[0]; - td_next = td_list[1]; - - state = USB_TYPE_IDLE; -} - -void Endpoint::setSize(uint32_t size) { - hced->control &= ~(0x3ff << 16); - hced->control |= (size << 16); -} - - -uint32_t Endpoint::getSize() { - return (hced->control >> 16) & 0x3ff; -} - -void Endpoint::setDeviceAddress(uint8_t addr) { - hced->control &= ~(0x7f); - hced->control |= (addr & 0x7F); -} - -uint8_t Endpoint::getDeviceAddress() { - return hced->control & 0x7f; -} - -void Endpoint::setSpeed(uint8_t speed) { - if(speed) { - DBG("SET LOW SPEED"); - } - hced->control &= ~(1 << 13); - hced->control |= (speed << 13); -} - - -void Endpoint::setNextToken(uint32_t token) { //Only for control Eps - switch (token) { - case TD_SETUP: - dir = OUT; - setup = true; - break; - case TD_IN: - dir = IN; - setup = false; - break; - case TD_OUT: - dir = OUT; - setup = false; - break; - } -} - -volatile HCTD* Endpoint::getNextTD() -{ - return td_current/*(HCTD*) hced->tailTD*/; //It's the tailing one -} - -void Endpoint::queueTransfer() { - //Try with OHCI impl - //Caller of getNextTD() has now populated the td - //So insert it into queue - - //Find an OTHER free td - //TODO: if we had more than 2 tds, this would have to be changed - /*HCTD* toSendTD = (HCTD*) hced->tailTD;*/ - //HCTD* freeTD; -/* - if( hced->tailTD == td_list[0] ) - { - freeTD = td_list[1]; - } - else *//*if( hced->tailTD == (uint32_t) td_list[1] )*/ - /*{ - freeTD = td_list[0]; - } - */ - - /* - freeTD->control = 0; - freeTD->currBufPtr = 0; - freeTD->bufEnd = 0; - freeTD->nextTD = 0; - - td_current = toSendTD; -*/ - transfer_len = td_current->bufEnd - td_current->currBufPtr + 1; - transferred = transfer_len; - buf_start = td_current->currBufPtr; - - //No add this free TD at this end of the queue - state = USB_TYPE_PROCESSING; - td_current->nextTD = (volatile uint32_t)td_next; - hced->tailTD = (volatile uint32_t)td_next; - - #if 0 - // if TD list empty -> we put the head of the list - if (!hced->headTD) { - state = USB_TYPE_IDLE; - hced->headTD = (uint32_t)(td); - hced->tailTD = (uint32_t)(td); - tailTD = (HCTD *) (hced->headTD); - //DBG("queue null transfer: endpoint: %p, %08X\r\n", this, (uint32_t)(td)); - } else { - state = USB_TYPE_PROCESSING; - td->nextTD = (uint32_t)headTD & ~(0x0f); - hced->headTD = (uint32_t)(td) | ((carry) ? 0x2 : 0); - } - headTD = (HCTD *) ((hced->headTD) & ~(0x3)); - transfer_len = td->bufEnd - td->currBufPtr + 1; - transferred = transfer_len; - buf_start = td->currBufPtr; -#endif - //printf("queue real transfer: endpoint: %p \t headTD: %p \t head: %08X \t tail: %08X \t td: %08X \t nexttd: %08X\r\n", this, hced->headTD, hced->headTD, ((HCTD *)((hced->headTD) & ~(0x0f)))->nextTD, toSendTD, toSendTD->nextTD); -} - -volatile HCTD * Endpoint::getProcessedTD() -{ - return td_current; -} - -void Endpoint::setLengthTransferred(int len) { - transferred = len; -} - -uint32_t Endpoint::getBufStart() { - return buf_start; -} - -void Endpoint::unqueueTransfer(volatile HCTD * td) { - //printf("unqueue transfer: %p on endpoint: %p\r\n", (void *)td, this); - //headTD = tailTD; //FIXME FIXME -// hced->headTD = hced->headTD | (td-> & 0x02); - if(td != td_current) - { - ERR("MISMATCH"); - ERR("this=%p, td_current = %p, td_next=%p, td=%p", this, td_current, td_next, td); - error(""); - } - td->control=0; - td->currBufPtr=0; - td->bufEnd=0; - td->nextTD=0; - hced->headTD = hced->tailTD | (hced->headTD & 0x2); //Carry bit - td_current = td_next; - td_next = td; - DBG("current:%p, next:%p", td_current, td_next); -} - -ENDPOINT_TYPE Endpoint::getType() { - return type; -} - - -Endpoint * Endpoint::nextEndpoint() { - return (Endpoint*)nextEp; -} - - -void Endpoint::queueEndpoint(Endpoint * ed) { - nextEp = ed; - hced->nextED = (ed == NULL) ? 0 : (uint32_t)ed->getHCED(); -} - -volatile HCED * Endpoint::getHCED() { - return hced; -} - - -volatile HCTD * Endpoint::getHeadTD() { - //return headTD; - return (volatile HCTD*) (hced->headTD & ~0xF); -} - -volatile HCTD ** Endpoint::getTDList() -{ - return td_list; -}
--- a/USBHost/Endpoint.h Mon Jul 30 13:51:34 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,189 +0,0 @@ -/* 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. -*/ - -#ifndef ENDPOINT_H -#define ENDPOINT_H - -#include "stdint.h" -#include "FunctionPointer.h" -#include "USBHostTypes.h" - - -enum ENDPOINT_TYPE { - CONTROL_ENDPOINT = 0, - ISOCHRONOUS_ENDPOINT, - BULK_ENDPOINT, - INTERRUPT_ENDPOINT -}; - -enum ENDPOINT_DIRECTION { - OUT = 1, - IN -}; - -class Endpoint { -public: - /* - * Constructor - */ - Endpoint() {state = USB_TYPE_FREE; nextEp = NULL;}; - - /* - * Initialize an endpoint - * - * @param hced hced associated to the endpoint - * @param type endpoint type - * @param dir endpoint direction - * @param size endpoint size - * @param ep_number endpoint number - */ - void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]); - - /* - * Set next token. Warining: only useful for the control endpoint - * - * @param token IN, OUT or SETUP token - */ - void setNextToken(uint32_t token); - - /* - * Queue an endpoint - * - * endpoint endpoint which will be queued in the linked list - */ - void queueEndpoint(Endpoint * endpoint); - - /* - * Get a td to be queued - * - * @returns td hctd which will be queued - */ - volatile HCTD* getNextTD(); - - /* - * Queue a transfer on the endpoint - * - */ - void queueTransfer(); - - /* - * Get the currently processed td - * - * @returns td hctd that was queued - */ - volatile HCTD * getProcessedTD(); - - /* - * Unqueue a transfer from the endpoint - * - * @param td hctd which will be unqueued - */ - void unqueueTransfer(volatile HCTD * td); - - /* - * Return the next endpoint in the linked list - * - * @returns next endpoint - */ - Endpoint * nextEndpoint(); - - /** - * Attach a member function to call when a transfer is finished - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - */ - template<typename T> - void attach(T* tptr, void (T::*mptr)(void)) { - if((mptr != NULL) && (tptr != NULL)) { - rx.attach(tptr, mptr); - } - } - - /** - * Attach a callback called when a transfer is finished - * - * @param fptr function pointer - */ - void attach(void (*fn)(void)) { - if(fn != NULL) { - rx.attach(fn); - } - } - - /* - * Call the handler associted to the end of a transfer - */ - void call() { - rx.call(); - }; - - - /* - * Setters - */ - void setState(USB_TYPE st) {state = st;} - void setDeviceAddress(uint8_t addr); - void setLengthTransferred(int len); - void setSpeed(uint8_t speed); - void setSize(uint32_t size); - void setDir(ENDPOINT_DIRECTION d) {dir = d;} - - /* - * Getters - */ - USB_TYPE getState() {return state;} - ENDPOINT_TYPE getType(); - uint8_t getDeviceAddress(); - int getLengthTransferred() {return transferred;} - uint32_t getBufStart(); - uint32_t getSize(); - volatile HCTD * getHeadTD(); - volatile HCTD** getTDList(); - volatile HCED * getHCED(); - ENDPOINT_DIRECTION getDir() {return dir;} - bool isSetup() {return setup;} - - -private: - ENDPOINT_TYPE type; - volatile USB_TYPE state; - ENDPOINT_DIRECTION dir; - bool setup; - - int transfer_len; - int transferred; - uint32_t buf_start; - - FunctionPointer rx; - - Endpoint* nextEp; - - // Endpoint descriptor - volatile HCED * hced; - - volatile HCTD * td_list[2]; - volatile HCTD * td_current; - volatile HCTD * td_next; - /*bool carry;*/ - - int count; - -}; - -#endif
--- a/USBHost/IUSBEnumerator.h Mon Jul 30 13:51:34 2012 +0000 +++ b/USBHost/IUSBEnumerator.h Tue Jul 31 10:37:16 2012 +0000 @@ -1,41 +1,41 @@ -/* 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 IUSBENUMERATOR_H_ -#define IUSBENUMERATOR_H_ - -#include "stdint.h" - -#include "Endpoint.h" - -/* -Generic interface to implement for "smart" USB enumeration -*/ - -class IUSBEnumerator { -public: - - virtual void setVidPid(uint16_t vid, uint16_t pid) = 0; - - virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) = 0; //Must return true if the interface should be parsed - - virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) = 0; //Must return true if the endpoint will be used - -}; - +/* 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 IUSBENUMERATOR_H_ +#define IUSBENUMERATOR_H_ + +#include "stdint.h" + +#include "USBEndpoint.h" + +/* +Generic interface to implement for "smart" USB enumeration +*/ + +class IUSBEnumerator { +public: + + virtual void setVidPid(uint16_t vid, uint16_t pid) = 0; + + virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) = 0; //Must return true if the interface should be parsed + + virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) = 0; //Must return true if the endpoint will be used + +}; + #endif /*IUSBENUMERATOR_H_*/ \ No newline at end of file
--- a/USBHost/USBDeviceConnected.cpp Mon Jul 30 13:51:34 2012 +0000 +++ b/USBHost/USBDeviceConnected.cpp Tue Jul 31 10:37:16 2012 +0000 @@ -64,7 +64,7 @@ return true; } -bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, Endpoint * ept) { +bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) { if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use == false) || (intf[intf_nb].nb_endpoint >= MAX_ENDPOINT_PER_INTERFACE)) { return false; } @@ -95,7 +95,7 @@ -Endpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) { +USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) { if (intf_nb >= MAX_INTF) { return NULL; } @@ -114,7 +114,7 @@ return NULL; } -Endpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) { +USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) { if ((intf_nb >= MAX_INTF) || (index >= MAX_ENDPOINT_PER_INTERFACE)) { return NULL; }
--- a/USBHost/USBDeviceConnected.h Mon Jul 30 13:51:34 2012 +0000 +++ b/USBHost/USBDeviceConnected.h Tue Jul 31 10:37:16 2012 +0000 @@ -20,7 +20,7 @@ #define USBDEVICECONNECTED_H #include "stdint.h" -#include "Endpoint.h" +#include "USBEndpoint.h" #define MAX_ENDPOINT_PER_INTERFACE 2 #define MAX_INTF 2 @@ -31,7 +31,7 @@ uint8_t intf_class; uint8_t intf_subclass; uint8_t intf_protocol; - Endpoint * ep[MAX_ENDPOINT_PER_INTERFACE]; + USBEndpoint * ep[MAX_ENDPOINT_PER_INTERFACE]; FunctionPointer detach; }INTERFACE; @@ -45,31 +45,31 @@ USBDeviceConnected(); /* - * Attach an endpoint to this device + * Attach an USBEndpoint to this device * - * @param ep pointeur on the endpoint which will be attached + * @param ep pointeur on the USBEndpoint which will be attached * @returns true if successful, false otherwise */ - bool addEndpoint(uint8_t intf_nb, Endpoint * ep); + bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep); /* - * Retrieve an endpoint by its TYPE and DIRECTION + * Retrieve an USBEndpoint by its TYPE and DIRECTION * - * @param intf_nb the interface on which to lookup the endpoint - * @param type type of the endpoint looked for - * @param direction of the endpoint looked for - * @param index the index of the endpoint whitin the interface - * @returns pointer on the endpoint if found, NULL otherwise + * @param intf_nb the interface on which to lookup the USBEndpoint + * @param type type of the USBEndpoint looked for + * @param direction of the USBEndpoint looked for + * @param index the index of the USBEndpoint whitin the interface + * @returns pointer on the USBEndpoint if found, NULL otherwise */ - Endpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0); + USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0); /* - * Retrieve an endpoint by its index + * Retrieve an USBEndpoint by its index * - * @param index index of the endpoint - * @returns pointer on the endpoint if found, NULL otherwise + * @param index index of the USBEndpoint + * @returns pointer on the USBEndpoint if found, NULL otherwise */ - Endpoint * getEndpoint(uint8_t intf_nb, uint8_t index); + USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index); bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); @@ -181,7 +181,7 @@ private: INTERFACE intf[MAX_INTF]; - //Endpoint * ep[MAX_ENDPOINT_PER_DEVICE]; + //USBEndpoint * ep[MAX_ENDPOINT_PER_DEVICE]; uint32_t sizeControlEndpoint; uint8_t hub; uint8_t port;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBHost/USBEndpoint.cpp Tue Jul 31 10:37:16 2012 +0000 @@ -0,0 +1,233 @@ +/* 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 //Maximum verbosity +#ifndef __MODULE__ +#define __MODULE__ "USBEndpoint.cpp" +#endif + +#include "dbg.h" +#include <cstdint> + +#include "USBEndpoint.h" + + +void USBEndpoint::init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]) { + this->hced = hced; + this->type = type; + this->dir = /*(type == CONTROL_ENDPOINT) ? OUT :*/ dir; + setup = (type == CONTROL_ENDPOINT) ? true : false; + + //TDs have been allocated by the host + memcpy((HCTD**)this->td_list, td_list, sizeof(HCTD*)*2); //TODO: Maybe should add a param for td_list size... at least a define + memcpy(td_list[0], 0, sizeof(HCTD)); + memcpy(td_list[1], 0, sizeof(HCTD)); + + this->hced->control = 0; + //Empty queue + this->hced->tailTD = (uint32_t)td_list[0]; + this->hced->headTD = (uint32_t)td_list[0]; + this->hced->nextED = 0; + + this->hced->control = ((ep_number & 0x7F) << 7) // Endpoint address + | (type != CONTROL_ENDPOINT ? ( dir << 11) : 0 ) // direction : Out = 1, 2 = In + | ((size & 0x3ff) << 16); // MaxPkt Size + + //carry = false; + transfer_len = 0; + transferred = 0; + buf_start = 0; + nextEp = NULL; + + td_current = td_list[0]; + td_next = td_list[1]; + + state = USB_TYPE_IDLE; +} + +void USBEndpoint::setSize(uint32_t size) { + hced->control &= ~(0x3ff << 16); + hced->control |= (size << 16); +} + + +uint32_t USBEndpoint::getSize() { + return (hced->control >> 16) & 0x3ff; +} + +void USBEndpoint::setDeviceAddress(uint8_t addr) { + hced->control &= ~(0x7f); + hced->control |= (addr & 0x7F); +} + +uint8_t USBEndpoint::getDeviceAddress() { + return hced->control & 0x7f; +} + +void USBEndpoint::setSpeed(uint8_t speed) { + if(speed) { + DBG("SET LOW SPEED"); + } + hced->control &= ~(1 << 13); + hced->control |= (speed << 13); +} + + +void USBEndpoint::setNextToken(uint32_t token) { //Only for control Eps + switch (token) { + case TD_SETUP: + dir = OUT; + setup = true; + break; + case TD_IN: + dir = IN; + setup = false; + break; + case TD_OUT: + dir = OUT; + setup = false; + break; + } +} + +volatile HCTD* USBEndpoint::getNextTD() +{ + return td_current/*(HCTD*) hced->tailTD*/; //It's the tailing one +} + +void USBEndpoint::queueTransfer() { + //Try with OHCI impl + //Caller of getNextTD() has now populated the td + //So insert it into queue + + //Find an OTHER free td + //TODO: if we had more than 2 tds, this would have to be changed + /*HCTD* toSendTD = (HCTD*) hced->tailTD;*/ + //HCTD* freeTD; +/* + if( hced->tailTD == td_list[0] ) + { + freeTD = td_list[1]; + } + else *//*if( hced->tailTD == (uint32_t) td_list[1] )*/ + /*{ + freeTD = td_list[0]; + } + */ + + /* + freeTD->control = 0; + freeTD->currBufPtr = 0; + freeTD->bufEnd = 0; + freeTD->nextTD = 0; + + td_current = toSendTD; +*/ + transfer_len = td_current->bufEnd - td_current->currBufPtr + 1; + transferred = transfer_len; + buf_start = td_current->currBufPtr; + + //No add this free TD at this end of the queue + state = USB_TYPE_PROCESSING; + td_current->nextTD = (volatile uint32_t)td_next; + hced->tailTD = (volatile uint32_t)td_next; + + #if 0 + // if TD list empty -> we put the head of the list + if (!hced->headTD) { + state = USB_TYPE_IDLE; + hced->headTD = (uint32_t)(td); + hced->tailTD = (uint32_t)(td); + tailTD = (HCTD *) (hced->headTD); + //DBG("queue null transfer: endpoint: %p, %08X\r\n", this, (uint32_t)(td)); + } else { + state = USB_TYPE_PROCESSING; + td->nextTD = (uint32_t)headTD & ~(0x0f); + hced->headTD = (uint32_t)(td) | ((carry) ? 0x2 : 0); + } + headTD = (HCTD *) ((hced->headTD) & ~(0x3)); + transfer_len = td->bufEnd - td->currBufPtr + 1; + transferred = transfer_len; + buf_start = td->currBufPtr; +#endif + //printf("queue real transfer: endpoint: %p \t headTD: %p \t head: %08X \t tail: %08X \t td: %08X \t nexttd: %08X\r\n", this, hced->headTD, hced->headTD, ((HCTD *)((hced->headTD) & ~(0x0f)))->nextTD, toSendTD, toSendTD->nextTD); +} + +volatile HCTD * USBEndpoint::getProcessedTD() +{ + return td_current; +} + +void USBEndpoint::setLengthTransferred(int len) { + transferred = len; +} + +uint32_t USBEndpoint::getBufStart() { + return buf_start; +} + +void USBEndpoint::unqueueTransfer(volatile HCTD * td) { + //printf("unqueue transfer: %p on endpoint: %p\r\n", (void *)td, this); + //headTD = tailTD; //FIXME FIXME +// hced->headTD = hced->headTD | (td-> & 0x02); + if(td != td_current) + { + ERR("MISMATCH"); + ERR("this=%p, td_current = %p, td_next=%p, td=%p", this, td_current, td_next, td); + error(""); + } + td->control=0; + td->currBufPtr=0; + td->bufEnd=0; + td->nextTD=0; + hced->headTD = hced->tailTD | (hced->headTD & 0x2); //Carry bit + td_current = td_next; + td_next = td; + DBG("current:%p, next:%p", td_current, td_next); +} + +ENDPOINT_TYPE USBEndpoint::getType() { + return type; +} + + +USBEndpoint * USBEndpoint::nextEndpoint() { + return (USBEndpoint*)nextEp; +} + + +void USBEndpoint::queueEndpoint(USBEndpoint * ed) { + nextEp = ed; + hced->nextED = (ed == NULL) ? 0 : (uint32_t)ed->getHCED(); +} + +volatile HCED * USBEndpoint::getHCED() { + return hced; +} + + +volatile HCTD * USBEndpoint::getHeadTD() { + //return headTD; + return (volatile HCTD*) (hced->headTD & ~0xF); +} + +volatile HCTD ** USBEndpoint::getTDList() +{ + return td_list; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBHost/USBEndpoint.h Tue Jul 31 10:37:16 2012 +0000 @@ -0,0 +1,189 @@ +/* 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. +*/ + +#ifndef USBENDPOINT_H +#define USBENDPOINT_H + +#include "stdint.h" +#include "FunctionPointer.h" +#include "USBHostTypes.h" + + +enum ENDPOINT_TYPE { + CONTROL_ENDPOINT = 0, + ISOCHRONOUS_ENDPOINT, + BULK_ENDPOINT, + INTERRUPT_ENDPOINT +}; + +enum ENDPOINT_DIRECTION { + OUT = 1, + IN +}; + +class USBEndpoint { +public: + /* + * Constructor + */ + USBEndpoint() {state = USB_TYPE_FREE; nextEp = NULL;}; + + /* + * Initialize an endpoint + * + * @param hced hced associated to the endpoint + * @param type endpoint type + * @param dir endpoint direction + * @param size endpoint size + * @param ep_number endpoint number + */ + void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]); + + /* + * Set next token. Warining: only useful for the control endpoint + * + * @param token IN, OUT or SETUP token + */ + void setNextToken(uint32_t token); + + /* + * Queue an endpoint + * + * endpoint endpoint which will be queued in the linked list + */ + void queueEndpoint(USBEndpoint * endpoint); + + /* + * Get a td to be queued + * + * @returns td hctd which will be queued + */ + volatile HCTD* getNextTD(); + + /* + * Queue a transfer on the endpoint + * + */ + void queueTransfer(); + + /* + * Get the currently processed td + * + * @returns td hctd that was queued + */ + volatile HCTD * getProcessedTD(); + + /* + * Unqueue a transfer from the endpoint + * + * @param td hctd which will be unqueued + */ + void unqueueTransfer(volatile HCTD * td); + + /* + * Return the next endpoint in the linked list + * + * @returns next endpoint + */ + USBEndpoint * nextEndpoint(); + + /** + * Attach a member function to call when a transfer is finished + * + * @param tptr pointer to the object to call the member function on + * @param mptr pointer to the member function to be called + */ + template<typename T> + void attach(T* tptr, void (T::*mptr)(void)) { + if((mptr != NULL) && (tptr != NULL)) { + rx.attach(tptr, mptr); + } + } + + /** + * Attach a callback called when a transfer is finished + * + * @param fptr function pointer + */ + void attach(void (*fn)(void)) { + if(fn != NULL) { + rx.attach(fn); + } + } + + /* + * Call the handler associted to the end of a transfer + */ + void call() { + rx.call(); + }; + + + /* + * Setters + */ + void setState(USB_TYPE st) {state = st;} + void setDeviceAddress(uint8_t addr); + void setLengthTransferred(int len); + void setSpeed(uint8_t speed); + void setSize(uint32_t size); + void setDir(ENDPOINT_DIRECTION d) {dir = d;} + + /* + * Getters + */ + USB_TYPE getState() {return state;} + ENDPOINT_TYPE getType(); + uint8_t getDeviceAddress(); + int getLengthTransferred() {return transferred;} + uint32_t getBufStart(); + uint32_t getSize(); + volatile HCTD * getHeadTD(); + volatile HCTD** getTDList(); + volatile HCED * getHCED(); + ENDPOINT_DIRECTION getDir() {return dir;} + bool isSetup() {return setup;} + + +private: + ENDPOINT_TYPE type; + volatile USB_TYPE state; + ENDPOINT_DIRECTION dir; + bool setup; + + int transfer_len; + int transferred; + uint32_t buf_start; + + FunctionPointer rx; + + USBEndpoint* nextEp; + + // USBEndpoint descriptor + volatile HCED * hced; + + volatile HCTD * td_list[2]; + volatile HCTD * td_current; + volatile HCTD * td_next; + /*bool carry;*/ + + int count; + +}; + +#endif
--- a/USBHost/USBHost.cpp Mon Jul 30 13:51:34 2012 +0000 +++ b/USBHost/USBHost.cpp Tue Jul 31 10:37:16 2012 +0000 @@ -88,7 +88,7 @@ } while(addr); //Now we can process the list - Endpoint * volatile iter = NULL; + USBEndpoint * volatile iter = NULL; while(tdList != NULL) { @@ -169,7 +169,7 @@ if (!controlEndpointAllocated) { control = newEndpoint(CONTROL_ENDPOINT, OUT, 0x08, 0x00); - addEndpoint(NULL, 0, (Endpoint*)control); + addEndpoint(NULL, 0, (USBEndpoint*)control); controlEndpointAllocated = true; } } @@ -202,7 +202,7 @@ } void USBHost::freeDevice(USBDeviceConnected * dev) { - Endpoint * ep = NULL; + USBEndpoint * ep = NULL; // HCTD * td = NULL; HCED * ed = NULL; @@ -210,10 +210,10 @@ DBG("FREE INTF %d, %p, nb_endpot: %d", j, (void *)dev->getInterface(j), dev->getInterface(j)->nb_endpoint); for (int i = 0; i < dev->getInterface(j)->nb_endpoint; i++) { if ((ep = dev->getEndpoint(j, i)) != NULL) { - DBG("Freeing endpoint"); + DBG("Freeing USBEndpoint"); ed = (HCED *)ep->getHCED(); ed->control |= (1 << 13); //sKip bit - DBG("Dequeueing endpoint"); + DBG("Dequeueing USBEndpoint"); unqueueEndpoint(ep); DBG("Freeing first transfer descriptor"); @@ -221,7 +221,7 @@ DBG("Freeing second transfer descriptor"); freeTD((volatile uint8_t*)ep->getTDList()[1]); - DBG("Freeing endpoint descriptor"); + DBG("Freeing USBEndpoint descriptor"); freeED((uint8_t *)ep->getHCED()); } //printBulk(); @@ -234,19 +234,19 @@ } -void USBHost::unqueueEndpoint(Endpoint * ep) { - Endpoint * prec = NULL; - Endpoint * current = NULL; +void USBHost::unqueueEndpoint(USBEndpoint * ep) { + USBEndpoint * prec = NULL; + USBEndpoint * current = NULL; bool found = false; DBG("want to unqueue ep: %p", (void *)ep->getHCED()); for (int i = 0; i < 2; i++) { if (found) { - DBG("endpoint unqueued: %p", (void *)ep->getHCED()); + DBG("USBEndpoint unqueued: %p", (void *)ep->getHCED()); break; } - current = (i == 0) ? (Endpoint*)headBulkEndpoint : (Endpoint*)headInterruptEndpoint; + current = (i == 0) ? (USBEndpoint*)headBulkEndpoint : (USBEndpoint*)headInterruptEndpoint; prec = current; while (current != NULL) { if (current == ep) { @@ -293,8 +293,8 @@ -// create an endpoint descriptor. the endpoint is not linked -Endpoint * USBHost::newEndpoint(ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t addr) { +// create an USBEndpoint descriptor. the USBEndpoint is not linked +USBEndpoint * USBHost::newEndpoint(ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t addr) { int i = 0; HCED * ed = (HCED *)getED(); HCTD* td_list[2] = { (HCTD*)getTD(), (HCTD*)getTD() }; @@ -302,13 +302,13 @@ memset((void *)td_list[0], 0x00, sizeof(HCTD)); memset((void *)td_list[1], 0x00, sizeof(HCTD)); - // search a free endpoint + // search a free USBEndpoint for (i = 0; i < MAX_ENDPOINT; i++) { if (endpoints[i].getState() == USB_TYPE_FREE) { DBG("Trying to create ep"); endpoints[i].init(ed, type, dir, size, addr, td_list); //endpoints[i].queueTransfer(nullTd); - DBG("Endpoint created (%p): type: %d, dir: %d, size: %d, addr: %d", &endpoints[i], type, dir, size, addr); + DBG("USBEndpoint created (%p): type: %d, dir: %d, size: %d, addr: %d", &endpoints[i], type, dir, size, addr); return &endpoints[i]; } } @@ -325,8 +325,8 @@ } } -// link the endpoint to the linked list and attach an endpoint to a device -bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, Endpoint * ep) { +// link the USBEndpoint to the linked list and attach an USBEndpoint to a device +bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint * ep) { if (ep == NULL) { return false; @@ -336,7 +336,7 @@ HCED * prevEd; - // set device address in the endpoint descriptor + // set device address in the USBEndpoint descriptor if (dev == NULL) { ep->setDeviceAddress(0); } else { @@ -344,18 +344,18 @@ } if (dev != NULL && dev->getSpeed()) { - DBG("add endpoint: set speed"); + DBG("add USBEndpoint: set speed"); ep->setSpeed(dev->getSpeed()); } - // queue the new endpoint on the ED list + // queue the new USBEndpoint on the ED list switch (ep->getType()) { case CONTROL_ENDPOINT: prevEd = ( HCED*) controlHeadED(); if (!prevEd) { updateControlHeadED((uint32_t) ep->getHCED()); - DBG("First control endpoint: %08X", (uint32_t) ep->getHCED()); + DBG("First control USBEndpoint: %08X", (uint32_t) ep->getHCED()); headControlEndpoint = ep; tailControlEndpoint = ep; return true; @@ -368,7 +368,7 @@ prevEd = ( HCED*) bulkHeadED(); if (!prevEd) { updateBulkHeadED((uint32_t) ep->getHCED()); - //DBG("First bulk endpoint: %08X\r\n", (uint32_t) ep->getHCED()); + //DBG("First bulk USBEndpoint: %08X\r\n", (uint32_t) ep->getHCED()); headBulkEndpoint = ep; tailBulkEndpoint = ep; break; @@ -381,7 +381,7 @@ prevEd = ( HCED*) interruptHeadED(); if (!prevEd) { updateInterruptHeadED((uint32_t) ep->getHCED()); - //DBG("First interrupt endpoint: %08X\r\n", (uint32_t) ep->getHCED()); + //DBG("First interrupt USBEndpoint: %08X\r\n", (uint32_t) ep->getHCED()); headInterruptEndpoint = ep; tailInterruptEndpoint = ep; break; @@ -446,7 +446,7 @@ // add a transfer on the TD linked list -USB_TYPE USBHost::addTransfer(Endpoint * ed, uint8_t * buf, uint32_t len) { +USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len) { // allocate a TD which will be freed in TDcompletion volatile HCTD * td = ed->getNextTD(); @@ -557,7 +557,7 @@ } -// enumerate a device with the control endpoint +// enumerate a device with the control USBEndpoint USB_TYPE USBHost::enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerator) { uint8_t data[384]; uint16_t total_conf_descr_length = 0; @@ -569,7 +569,7 @@ return USB_TYPE_OK; } - // first step: get the size of endpoint 0 + // first step: get the size of USBEndpoint 0 DBG("Get size of EP 0"); res = controlRead( dev, USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, @@ -584,7 +584,7 @@ return res; } dev->setSizeControlEndpoint(data[7]); - DBG("size control Endpoint: %d", dev->getSizeControlEndpoint()); + DBG("size control USBEndpoint: %d", dev->getSizeControlEndpoint()); DBG("Now set addr"); // second step: set an address to the device @@ -654,7 +654,7 @@ uint32_t len_desc = 0; uint8_t id = 0; int nb_endpoints_used = 0; - Endpoint * ep = NULL; + USBEndpoint * ep = NULL; uint8_t intf_nb = 0; bool parsing_intf = false; @@ -687,13 +687,13 @@ if (nb_endpoints_used < MAX_ENDPOINT_PER_INTERFACE) { if( pEnumerator->useEndpoint(intf_nb - 1, (ENDPOINT_TYPE)(conf_descr[index + 3] & 0x03), (ENDPOINT_DIRECTION)((conf_descr[index + 2] >> 7) + 1)) ) { - // if the endpoint is isochronous -> skip it (TODO: fix this) + // if the USBEndpoint is isochronous -> skip it (TODO: fix this) if ((conf_descr[index + 3] & 0x03) != ISOCHRONOUS_ENDPOINT) { ep = newEndpoint((ENDPOINT_TYPE)(conf_descr[index+3] & 0x03), (ENDPOINT_DIRECTION)((conf_descr[index + 2] >> 7) + 1), conf_descr[index + 4] | (conf_descr[index + 5] << 8), conf_descr[index + 2] & 0x0f); - DBG("ADD ENDPOINT %p, on interf %d on device %p", (void *)ep, intf_nb - 1, (void *)dev); + DBG("ADD USBEndpoint %p, on interf %d on device %p", (void *)ep, intf_nb - 1, (void *)dev); if (ep != NULL && dev != NULL) { addEndpoint(dev, intf_nb - 1, ep); } else { @@ -701,12 +701,12 @@ } nb_endpoints_used++; } else { - DBG("ISO ENDPOINT NOT SUPPORTED"); + DBG("ISO USBEndpoint NOT SUPPORTED"); } } } } - //DBG("ENDPOINT DESCR"); + //DBG("USBEndpoint DESCR"); break; case HID_DESCRIPTOR: lenReportDescr = conf_descr[index + 7] | (conf_descr[index + 8] << 8); @@ -719,7 +719,7 @@ } -USB_TYPE USBHost::bulkRead(USBDeviceConnected * dev, Endpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { +USB_TYPE USBHost::bulkRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { USB_TYPE res; if (dev == NULL || ep == NULL) { @@ -727,11 +727,11 @@ } if ((ep->getDir() != IN) || (ep->getType() != BULK_ENDPOINT)) { - DBG("wrong dir or bad endpoint type"); + DBG("wrong dir or bad USBEndpoint type"); return USB_TYPE_ERROR; } if (dev->getAddress() != ep->getDeviceAddress()) { - DBG("endpoint addr and device addr don't match"); + DBG("USBEndpoint addr and device addr don't match"); return USB_TYPE_ERROR; } addTransfer(ep, buf, len); @@ -747,7 +747,7 @@ return USB_TYPE_PROCESSING; } -USB_TYPE USBHost::bulkWrite(USBDeviceConnected * dev, Endpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { +USB_TYPE USBHost::bulkWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { USB_TYPE res; if (dev == NULL || ep == NULL) { @@ -755,11 +755,11 @@ } if ((ep->getDir() != OUT) || (ep->getType() != BULK_ENDPOINT)) { - DBG("wrong dir or bad endpoint type"); + DBG("wrong dir or bad USBEndpoint type"); return USB_TYPE_ERROR; } if (dev->getAddress() != ep->getDeviceAddress()) { - DBG("endpoint addr and device addr don't match"); + DBG("USBEndpoint addr and device addr don't match"); return USB_TYPE_ERROR; } addTransfer(ep, buf, len); @@ -780,7 +780,7 @@ return USB_TYPE_PROCESSING; } -USB_TYPE USBHost::interruptWrite(USBDeviceConnected * dev, Endpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { +USB_TYPE USBHost::interruptWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { USB_TYPE res; if (dev == NULL || ep == NULL) { @@ -792,11 +792,11 @@ } if ((ep->getDir() != OUT) || (ep->getType() != INTERRUPT_ENDPOINT)) { - ERR("wrong dir or bad endpoint type: %d, %d", ep->getDir(), ep->getType()); + ERR("wrong dir or bad USBEndpoint type: %d, %d", ep->getDir(), ep->getType()); return USB_TYPE_ERROR; } if (dev->getAddress() != ep->getDeviceAddress()) { - ERR("endpoint addr and device addr don't match"); + ERR("USBEndpoint addr and device addr don't match"); return USB_TYPE_ERROR; } addTransfer(ep, buf, len); @@ -810,7 +810,7 @@ return USB_TYPE_PROCESSING; } -USB_TYPE USBHost::interruptRead(USBDeviceConnected * dev, Endpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { +USB_TYPE USBHost::interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { USB_TYPE res; if (dev == NULL || ep == NULL) { @@ -822,12 +822,12 @@ } if ((ep->getDir() != IN) || (ep->getType() != INTERRUPT_ENDPOINT)) { - ERR("wrong dir or bad endpoint type"); + ERR("wrong dir or bad USBEndpoint type"); return USB_TYPE_ERROR; } if (dev->getAddress() != ep->getDeviceAddress()) { - ERR("endpoint addr and device addr don't match"); + ERR("USBEndpoint addr and device addr don't match"); return USB_TYPE_ERROR; } addTransfer(ep, buf, len);
--- a/USBHost/USBHost.h Mon Jul 30 13:51:34 2012 +0000 +++ b/USBHost/USBHost.h Tue Jul 31 10:37:16 2012 +0000 @@ -21,7 +21,7 @@ #include "USBHALHost.h" #include "USBDeviceConnected.h" -#include "Endpoint.h" +#include "USBEndpoint.h" #include "IUSBEnumerator.h" #define MAX_DEVICE_NB 1 @@ -75,53 +75,53 @@ * Bulk read * * @param dev the bulk transfer will be done for this device - * @param ep endpoint which will be used to read a packet + * @param ep USBEndpoint which will be used to read a packet * @param buf pointer on a buffer where will be store the data received * @param len length of the transfer * @param blocking if true, the read is blocking (wait for completion) * * @returns status of the bulk read */ - USB_TYPE bulkRead(USBDeviceConnected * dev, Endpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true) ; + USB_TYPE bulkRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true) ; /* * Bulk write * * @param dev the bulk transfer will be done for this device - * @param ep endpoint which will be used to write a packet + * @param ep USBEndpoint which will be used to write a packet * @param buf pointer on a buffer which will be written * @param len length of the transfer * @param blocking if true, the write is blocking (wait for completion) * * @returns status of the bulk write */ - USB_TYPE bulkWrite(USBDeviceConnected * dev, Endpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true) ; + USB_TYPE bulkWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true) ; /* * Interrupt read * * @param dev the bulk transfer will be done for this device - * @param ep endpoint which will be used to write a packet + * @param ep USBEndpoint which will be used to write a packet * @param buf pointer on a buffer which will be written * @param len length of the transfer * @param blocking if true, the read is blocking (wait for completion) * * @returns status of the interrupt read */ - USB_TYPE interruptRead(USBDeviceConnected * dev, Endpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true) ; + USB_TYPE interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true) ; /* * Interrupt write * * @param dev the bulk transfer will be done for this device - * @param ep endpoint which will be used to write a packet + * @param ep USBEndpoint which will be used to write a packet * @param buf pointer on a buffer which will be written * @param len length of the transfer * @param blocking if true, the write is blocking (wait for completion) * * @returns status of the interrupt write */ - USB_TYPE interruptWrite(USBDeviceConnected * dev, Endpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true) ; + USB_TYPE interruptWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true) ; /* * Enumerate a device. This method is responsible for: @@ -235,17 +235,17 @@ // endpoints - void unqueueEndpoint(Endpoint * ep) ; - Endpoint endpoints[MAX_ENDPOINT]; - Endpoint* volatile control; + void unqueueEndpoint(USBEndpoint * ep) ; + USBEndpoint endpoints[MAX_ENDPOINT]; + USBEndpoint* volatile control; - Endpoint* volatile headControlEndpoint; - Endpoint* volatile headBulkEndpoint; - Endpoint* volatile headInterruptEndpoint; + USBEndpoint* volatile headControlEndpoint; + USBEndpoint* volatile headBulkEndpoint; + USBEndpoint* volatile headInterruptEndpoint; - Endpoint* volatile tailControlEndpoint; - Endpoint* volatile tailBulkEndpoint; - Endpoint* volatile tailInterruptEndpoint; + USBEndpoint* volatile tailControlEndpoint; + USBEndpoint* volatile tailBulkEndpoint; + USBEndpoint* volatile tailInterruptEndpoint; bool controlEndpointAllocated; @@ -264,29 +264,29 @@ * * @return status of the transfer */ - USB_TYPE addTransfer(Endpoint * ed, uint8_t * buf, uint32_t len) ; + USB_TYPE addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len) ; /* - * Link the endpoint to the linked list and attach an endpoint this endpoint to a device + * Link the USBEndpoint to the linked list and attach an USBEndpoint this USBEndpoint to a device * * @param dev pointer on a USBDeviceConnected object - * @param ep pointer on the Endpoint which will be added + * @param ep pointer on the USBEndpoint which will be added * * return true if successful */ - bool addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, Endpoint * ep) ; + bool addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint * ep) ; /* - * Create an endpoint descriptor. Warning: the endpoint is not linked. + * Create an USBEndpoint descriptor. Warning: the USBEndpoint is not linked. * - * @param type endpoint type (CONTROL_ENDPOINT, BULK_ENDPOINT, INTERRUPT_ENDPOINT) - * @param dir endpoint direction (no meaning for CONTROL_ENDPOINT) - * @param size endpoint max packet size - * @param addr endpoint address + * @param type USBEndpoint type (CONTROL_ENDPOINT, BULK_ENDPOINT, INTERRUPT_ENDPOINT) + * @param dir USBEndpoint direction (no meaning for CONTROL_ENDPOINT) + * @param size USBEndpoint max packet size + * @param addr USBEndpoint address * - * @returns pointer on the Endpoint created + * @returns pointer on the USBEndpoint created */ - Endpoint * newEndpoint(ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t addr) ; + USBEndpoint * newEndpoint(ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t addr) ; // to store a setup packet