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