The beta version of the Vodafone K3770 dongle driver
This library is deprecated. Please use the newest production branch of the library from https://mbed.org/users/mbed_official/code/VodafoneUSBModem/
USBHostWANDongleLib/USB3GModule/WANDongle.h@0:0ac66acdfdc0, 2012-05-31 (annotated)
- Committer:
- donatien
- Date:
- Thu May 31 15:32:49 2012 +0000
- Revision:
- 0:0ac66acdfdc0
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:0ac66acdfdc0 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
donatien | 0:0ac66acdfdc0 | 2 | * |
donatien | 0:0ac66acdfdc0 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
donatien | 0:0ac66acdfdc0 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
donatien | 0:0ac66acdfdc0 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
donatien | 0:0ac66acdfdc0 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
donatien | 0:0ac66acdfdc0 | 7 | * Software is furnished to do so, subject to the following conditions: |
donatien | 0:0ac66acdfdc0 | 8 | * |
donatien | 0:0ac66acdfdc0 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
donatien | 0:0ac66acdfdc0 | 10 | * substantial portions of the Software. |
donatien | 0:0ac66acdfdc0 | 11 | * |
donatien | 0:0ac66acdfdc0 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
donatien | 0:0ac66acdfdc0 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
donatien | 0:0ac66acdfdc0 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
donatien | 0:0ac66acdfdc0 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
donatien | 0:0ac66acdfdc0 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
donatien | 0:0ac66acdfdc0 | 17 | */ |
donatien | 0:0ac66acdfdc0 | 18 | |
donatien | 0:0ac66acdfdc0 | 19 | #ifndef WANDONGLE_H |
donatien | 0:0ac66acdfdc0 | 20 | #define WANDONGLE_H |
donatien | 0:0ac66acdfdc0 | 21 | |
donatien | 0:0ac66acdfdc0 | 22 | #include "USBHost.h" |
donatien | 0:0ac66acdfdc0 | 23 | #include "IUSBHostSerial.h" |
donatien | 0:0ac66acdfdc0 | 24 | |
donatien | 0:0ac66acdfdc0 | 25 | #include "rtos.h" |
donatien | 0:0ac66acdfdc0 | 26 | |
donatien | 0:0ac66acdfdc0 | 27 | |
donatien | 0:0ac66acdfdc0 | 28 | #define WANDONGLE_MAX_OUTEP_SIZE 64 |
donatien | 0:0ac66acdfdc0 | 29 | #define WANDONGLE_MAX_INEP_SIZE 64 |
donatien | 0:0ac66acdfdc0 | 30 | |
donatien | 0:0ac66acdfdc0 | 31 | /** A class to use a WAN (3G/LTE) access dongle |
donatien | 0:0ac66acdfdc0 | 32 | * |
donatien | 0:0ac66acdfdc0 | 33 | */ |
donatien | 0:0ac66acdfdc0 | 34 | class WANDongle : public IUSBHostSerial { |
donatien | 0:0ac66acdfdc0 | 35 | public: |
donatien | 0:0ac66acdfdc0 | 36 | /* |
donatien | 0:0ac66acdfdc0 | 37 | * Constructor |
donatien | 0:0ac66acdfdc0 | 38 | * |
donatien | 0:0ac66acdfdc0 | 39 | * @param rootdir mount name |
donatien | 0:0ac66acdfdc0 | 40 | */ |
donatien | 0:0ac66acdfdc0 | 41 | WANDongle(); |
donatien | 0:0ac66acdfdc0 | 42 | |
donatien | 0:0ac66acdfdc0 | 43 | /* |
donatien | 0:0ac66acdfdc0 | 44 | * Check if a serial port device is connected |
donatien | 0:0ac66acdfdc0 | 45 | * |
donatien | 0:0ac66acdfdc0 | 46 | * @return true if a serial device is connected |
donatien | 0:0ac66acdfdc0 | 47 | */ |
donatien | 0:0ac66acdfdc0 | 48 | bool connected(); |
donatien | 0:0ac66acdfdc0 | 49 | |
donatien | 0:0ac66acdfdc0 | 50 | /* |
donatien | 0:0ac66acdfdc0 | 51 | * Try to connect device |
donatien | 0:0ac66acdfdc0 | 52 | * |
donatien | 0:0ac66acdfdc0 | 53 | * * @return true if connection was successful |
donatien | 0:0ac66acdfdc0 | 54 | */ |
donatien | 0:0ac66acdfdc0 | 55 | bool tryConnect(); |
donatien | 0:0ac66acdfdc0 | 56 | |
donatien | 0:0ac66acdfdc0 | 57 | /* |
donatien | 0:0ac66acdfdc0 | 58 | * Get a char from the dongle's serial interface |
donatien | 0:0ac66acdfdc0 | 59 | */ |
donatien | 0:0ac66acdfdc0 | 60 | virtual int getc(); |
donatien | 0:0ac66acdfdc0 | 61 | |
donatien | 0:0ac66acdfdc0 | 62 | /* |
donatien | 0:0ac66acdfdc0 | 63 | * Put a char to the dongle's serial interface |
donatien | 0:0ac66acdfdc0 | 64 | */ |
donatien | 0:0ac66acdfdc0 | 65 | virtual int putc(int c); |
donatien | 0:0ac66acdfdc0 | 66 | |
donatien | 0:0ac66acdfdc0 | 67 | //void test(); |
donatien | 0:0ac66acdfdc0 | 68 | |
donatien | 0:0ac66acdfdc0 | 69 | /* |
donatien | 0:0ac66acdfdc0 | 70 | * Read a packet from the dongle's serial interface, to be called after multiple getc() calls |
donatien | 0:0ac66acdfdc0 | 71 | */ |
donatien | 0:0ac66acdfdc0 | 72 | virtual int readPacket(); |
donatien | 0:0ac66acdfdc0 | 73 | |
donatien | 0:0ac66acdfdc0 | 74 | /* |
donatien | 0:0ac66acdfdc0 | 75 | * Write a packet to the dongle's serial interface, to be called after multiple putc() calls |
donatien | 0:0ac66acdfdc0 | 76 | */ |
donatien | 0:0ac66acdfdc0 | 77 | virtual int writePacket(); |
donatien | 0:0ac66acdfdc0 | 78 | |
donatien | 0:0ac66acdfdc0 | 79 | /** |
donatien | 0:0ac66acdfdc0 | 80 | * Check the number of bytes available. |
donatien | 0:0ac66acdfdc0 | 81 | * |
donatien | 0:0ac66acdfdc0 | 82 | * @returns the number of bytes available |
donatien | 0:0ac66acdfdc0 | 83 | */ |
donatien | 0:0ac66acdfdc0 | 84 | virtual int readable(); |
donatien | 0:0ac66acdfdc0 | 85 | |
donatien | 0:0ac66acdfdc0 | 86 | /** |
donatien | 0:0ac66acdfdc0 | 87 | * Check the free space in output. |
donatien | 0:0ac66acdfdc0 | 88 | * |
donatien | 0:0ac66acdfdc0 | 89 | * @returns the number of bytes available |
donatien | 0:0ac66acdfdc0 | 90 | */ |
donatien | 0:0ac66acdfdc0 | 91 | virtual int writeable(); |
donatien | 0:0ac66acdfdc0 | 92 | |
donatien | 0:0ac66acdfdc0 | 93 | /** |
donatien | 0:0ac66acdfdc0 | 94 | * Attach a handler to call when a packet is received / when a packet has been transmitted. |
donatien | 0:0ac66acdfdc0 | 95 | * |
donatien | 0:0ac66acdfdc0 | 96 | * @param pListener instance of the listener deriving from the IUSBHostSerialListener |
donatien | 0:0ac66acdfdc0 | 97 | */ |
donatien | 0:0ac66acdfdc0 | 98 | virtual void attach(IUSBHostSerialListener* pListener); |
donatien | 0:0ac66acdfdc0 | 99 | |
donatien | 0:0ac66acdfdc0 | 100 | /** |
donatien | 0:0ac66acdfdc0 | 101 | * Enable or disable readable/writeable callbacks |
donatien | 0:0ac66acdfdc0 | 102 | */ |
donatien | 0:0ac66acdfdc0 | 103 | virtual void setupIrq(bool en, IrqType irq = RxIrq); |
donatien | 0:0ac66acdfdc0 | 104 | |
donatien | 0:0ac66acdfdc0 | 105 | |
donatien | 0:0ac66acdfdc0 | 106 | protected: |
donatien | 0:0ac66acdfdc0 | 107 | Endpoint * bulk_in; |
donatien | 0:0ac66acdfdc0 | 108 | Endpoint * bulk_out; |
donatien | 0:0ac66acdfdc0 | 109 | USBHost * host; |
donatien | 0:0ac66acdfdc0 | 110 | USBDeviceConnected * dev; |
donatien | 0:0ac66acdfdc0 | 111 | bool dev_connected; |
donatien | 0:0ac66acdfdc0 | 112 | |
donatien | 0:0ac66acdfdc0 | 113 | uint8_t buf_out[WANDONGLE_MAX_OUTEP_SIZE]; |
donatien | 0:0ac66acdfdc0 | 114 | volatile uint32_t buf_out_len; |
donatien | 0:0ac66acdfdc0 | 115 | uint32_t max_out_size; |
donatien | 0:0ac66acdfdc0 | 116 | volatile bool lock_tx; |
donatien | 0:0ac66acdfdc0 | 117 | //Mutex lock_tx; |
donatien | 0:0ac66acdfdc0 | 118 | volatile bool cb_tx_en; |
donatien | 0:0ac66acdfdc0 | 119 | volatile bool cb_tx_pending; |
donatien | 0:0ac66acdfdc0 | 120 | Mutex tx_mtx; |
donatien | 0:0ac66acdfdc0 | 121 | |
donatien | 0:0ac66acdfdc0 | 122 | uint8_t buf_in[WANDONGLE_MAX_INEP_SIZE]; |
donatien | 0:0ac66acdfdc0 | 123 | volatile uint32_t buf_in_len; |
donatien | 0:0ac66acdfdc0 | 124 | volatile uint32_t buf_in_read_pos; |
donatien | 0:0ac66acdfdc0 | 125 | volatile bool lock_rx; |
donatien | 0:0ac66acdfdc0 | 126 | //Mutex lock_rx; |
donatien | 0:0ac66acdfdc0 | 127 | volatile bool cb_rx_en; |
donatien | 0:0ac66acdfdc0 | 128 | volatile bool cb_rx_pending; |
donatien | 0:0ac66acdfdc0 | 129 | Mutex rx_mtx; |
donatien | 0:0ac66acdfdc0 | 130 | |
donatien | 0:0ac66acdfdc0 | 131 | IUSBHostSerialListener* listener; |
donatien | 0:0ac66acdfdc0 | 132 | |
donatien | 0:0ac66acdfdc0 | 133 | void init(); |
donatien | 0:0ac66acdfdc0 | 134 | void rxHandler(); |
donatien | 0:0ac66acdfdc0 | 135 | void txHandler(); |
donatien | 0:0ac66acdfdc0 | 136 | bool fetchEndpoints(); |
donatien | 0:0ac66acdfdc0 | 137 | |
donatien | 0:0ac66acdfdc0 | 138 | }; |
donatien | 0:0ac66acdfdc0 | 139 | |
donatien | 0:0ac66acdfdc0 | 140 | #endif |