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