Vincent Wochnik / CellularUSBModem

Dependencies:   CellularModem USBHost

Fork of CellularUSBModem by mbed official

Committer:
mbed_official
Date:
Mon Dec 16 09:00:30 2013 +0000
Revision:
3:be33ff78d8c7
Parent:
1:6547cd17fdb6
Synchronized with git revision 170ac6562b7b2b5bb43f8ecf82b2af18b37eeb9c

Full URL: https://github.com/mbedmicro/mbed/commit/170ac6562b7b2b5bb43f8ecf82b2af18b37eeb9c/

improve USB host library and cellular modem stack

Who changed what in which revision?

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