fork of VodafoneUSBModem with updated USBHost library
Dependencies: Socket USBHost lwip-sys lwip
Dependents: VodafoneUSBModemSMSTest
USBSerialStream.h
00001 /* USBSerialStream.h */ 00002 /* Copyright (C) 2012 mbed.org, MIT License 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00005 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00006 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00007 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00008 * furnished to do so, subject to the following conditions: 00009 * 00010 * The above copyright notice and this permission notice shall be included in all copies or 00011 * substantial portions of the Software. 00012 * 00013 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00014 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00015 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00016 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00017 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00018 */ 00019 00020 #ifndef USBSERIALSTREAM_H_ 00021 #define USBSERIALSTREAM_H_ 00022 00023 00024 #include "core/fwk.h" 00025 00026 #include "USBHost/USBHost3GModule/IUSBHostSerial.h" 00027 #include "USBHost/USBHost3GModule/IUSBHostSerialListener.h" 00028 00029 #include "rtos.h" 00030 #include "core/MtxCircBuffer.h" 00031 00032 /* Input Serial Stream for USB virtual serial ports interfaces 00033 This class is not thread-safe, except for the *Abort() methods that can be called by any thread/ISR 00034 */ 00035 #define CIRCBUF_SIZE 127 00036 class USBSerialStream : public IOStream, IUSBHostSerialListener 00037 { 00038 public: 00039 USBSerialStream(IUSBHostSerial& serial); 00040 /*virtual*/ ~USBSerialStream(); 00041 00042 //0 for non-blocking (returns immediately), osWaitForever for infinite blocking 00043 virtual int read(uint8_t* buf, size_t* pLength, size_t maxLength, uint32_t timeout=osWaitForever); 00044 virtual size_t available(); 00045 virtual int waitAvailable(uint32_t timeout=osWaitForever); //Wait for data to be available 00046 virtual int abortRead(); //Abort current reading (or waiting) operation 00047 00048 00049 //0 for non-blocking (returns immediately), osWaitForever for infinite blocking 00050 virtual int write(uint8_t* buf, size_t length, uint32_t timeout=osWaitForever); 00051 virtual size_t space(); 00052 virtual int waitSpace(uint32_t timeout=osWaitForever); //Wait for space to be available 00053 virtual int abortWrite(); //Abort current writing (or waiting) operation 00054 00055 private: 00056 IUSBHostSerial& m_serial; 00057 volatile bool m_serialTxFifoEmpty; 00058 00059 void setupReadableISR(bool en); 00060 virtual void readable(); //Callback from m_serial when new data is available 00061 00062 Semaphore m_availableSphre; //Used for signalling 00063 00064 void setupWriteableISR(bool en); 00065 virtual void writeable(); //Callback from m_serial when new space is available 00066 00067 Semaphore m_spaceSphre; //Used for signalling 00068 00069 MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_inBuf; 00070 MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_outBuf; 00071 }; 00072 00073 #endif /* USBSERIALSTREAM_H_ */
Generated on Wed Jul 13 2022 19:57:21 by 1.7.2