USB Host Library for Sprint Dongles
Dependencies: Socket USBHostWANDongleSprint lwip-sys lwip
Dependents: SprintUSBModemWebsocketTest SprintUSBModemHTTPClientTest SprintUSBModemNTPClientTest SprintUSBModemSMSTest ... more
Fork of SprintUSBModem_bleedingedge by
serial/usb/USBSerialStream.h@14:f6f17843e5ef, 2012-12-10 (annotated)
- Committer:
- donatien
- Date:
- Mon Dec 10 18:23:49 2012 +0000
- Revision:
- 14:f6f17843e5ef
- Parent:
- 0:8f57713b2147
Separate USB/Sprint dev flows, fix regression in mbed rev. 41+ lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:8f57713b2147 | 1 | /* USBSerialStream.h */ |
donatien | 0:8f57713b2147 | 2 | /* Copyright (C) 2012 mbed.org, MIT License |
donatien | 0:8f57713b2147 | 3 | * |
donatien | 0:8f57713b2147 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
donatien | 0:8f57713b2147 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
donatien | 0:8f57713b2147 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
donatien | 0:8f57713b2147 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
donatien | 0:8f57713b2147 | 8 | * furnished to do so, subject to the following conditions: |
donatien | 0:8f57713b2147 | 9 | * |
donatien | 0:8f57713b2147 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
donatien | 0:8f57713b2147 | 11 | * substantial portions of the Software. |
donatien | 0:8f57713b2147 | 12 | * |
donatien | 0:8f57713b2147 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
donatien | 0:8f57713b2147 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
donatien | 0:8f57713b2147 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
donatien | 0:8f57713b2147 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
donatien | 0:8f57713b2147 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
donatien | 0:8f57713b2147 | 18 | */ |
donatien | 0:8f57713b2147 | 19 | |
donatien | 0:8f57713b2147 | 20 | #ifndef USBSERIALSTREAM_H_ |
donatien | 0:8f57713b2147 | 21 | #define USBSERIALSTREAM_H_ |
donatien | 0:8f57713b2147 | 22 | |
donatien | 0:8f57713b2147 | 23 | |
donatien | 0:8f57713b2147 | 24 | #include "core/fwk.h" |
donatien | 0:8f57713b2147 | 25 | |
donatien | 0:8f57713b2147 | 26 | #include "USB3GModule/IUSBHostSerial.h" |
donatien | 0:8f57713b2147 | 27 | #include "USB3GModule/IUSBHostSerialListener.h" |
donatien | 0:8f57713b2147 | 28 | |
donatien | 0:8f57713b2147 | 29 | #include "rtos.h" |
donatien | 0:8f57713b2147 | 30 | #include "core/MtxCircBuffer.h" |
donatien | 0:8f57713b2147 | 31 | |
donatien | 0:8f57713b2147 | 32 | /* Input Serial Stream for USB virtual serial ports interfaces |
donatien | 0:8f57713b2147 | 33 | This class is not thread-safe, except for the *Abort() methods that can be called by any thread/ISR |
donatien | 0:8f57713b2147 | 34 | */ |
donatien | 0:8f57713b2147 | 35 | #define CIRCBUF_SIZE 127 |
donatien | 0:8f57713b2147 | 36 | class USBSerialStream : public IOStream, IUSBHostSerialListener |
donatien | 0:8f57713b2147 | 37 | { |
donatien | 0:8f57713b2147 | 38 | public: |
donatien | 0:8f57713b2147 | 39 | USBSerialStream(IUSBHostSerial& serial); |
donatien | 0:8f57713b2147 | 40 | /*virtual*/ ~USBSerialStream(); |
donatien | 0:8f57713b2147 | 41 | |
donatien | 0:8f57713b2147 | 42 | //0 for non-blocking (returns immediately), osWaitForever for infinite blocking |
donatien | 0:8f57713b2147 | 43 | virtual int read(uint8_t* buf, size_t* pLength, size_t maxLength, uint32_t timeout=osWaitForever); |
donatien | 0:8f57713b2147 | 44 | virtual size_t available(); |
donatien | 0:8f57713b2147 | 45 | virtual int waitAvailable(uint32_t timeout=osWaitForever); //Wait for data to be available |
donatien | 0:8f57713b2147 | 46 | virtual int abortRead(); //Abort current reading (or waiting) operation |
donatien | 0:8f57713b2147 | 47 | |
donatien | 0:8f57713b2147 | 48 | |
donatien | 0:8f57713b2147 | 49 | //0 for non-blocking (returns immediately), osWaitForever for infinite blocking |
donatien | 0:8f57713b2147 | 50 | virtual int write(uint8_t* buf, size_t length, uint32_t timeout=osWaitForever); |
donatien | 0:8f57713b2147 | 51 | virtual size_t space(); |
donatien | 0:8f57713b2147 | 52 | virtual int waitSpace(uint32_t timeout=osWaitForever); //Wait for space to be available |
donatien | 0:8f57713b2147 | 53 | virtual int abortWrite(); //Abort current writing (or waiting) operation |
donatien | 0:8f57713b2147 | 54 | |
donatien | 0:8f57713b2147 | 55 | private: |
donatien | 0:8f57713b2147 | 56 | IUSBHostSerial& m_serial; |
donatien | 0:8f57713b2147 | 57 | volatile bool m_serialTxFifoEmpty; |
donatien | 0:8f57713b2147 | 58 | |
donatien | 0:8f57713b2147 | 59 | void setupReadableISR(bool en); |
donatien | 0:8f57713b2147 | 60 | virtual void readable(); //Callback from m_serial when new data is available |
donatien | 0:8f57713b2147 | 61 | |
donatien | 0:8f57713b2147 | 62 | Semaphore m_availableSphre; //Used for signalling |
donatien | 0:8f57713b2147 | 63 | |
donatien | 0:8f57713b2147 | 64 | void setupWriteableISR(bool en); |
donatien | 0:8f57713b2147 | 65 | virtual void writeable(); //Callback from m_serial when new space is available |
donatien | 0:8f57713b2147 | 66 | |
donatien | 0:8f57713b2147 | 67 | Semaphore m_spaceSphre; //Used for signalling |
donatien | 0:8f57713b2147 | 68 | |
donatien | 0:8f57713b2147 | 69 | MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_inBuf; |
donatien | 0:8f57713b2147 | 70 | MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_outBuf; |
donatien | 0:8f57713b2147 | 71 | }; |
donatien | 0:8f57713b2147 | 72 | |
donatien | 0:8f57713b2147 | 73 | #endif /* USBSERIALSTREAM_H_ */ |