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