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