modified u-blox modem driver

Dependencies:   CellularModem USBHost

Fork of CellularUSBModem by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBSerialStream.h Source File

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 "USBHost3GModule/IUSBHostSerial.h"
00027 #include "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 
00036 class USBSerialStream : public IOStream, IUSBHostSerialListener
00037 {
00038 public:
00039   enum { CIRCBUF_SIZE = 127 };
00040   USBSerialStream(IUSBHostSerial& serial);
00041   /*virtual*/ ~USBSerialStream();
00042 
00043   //0 for non-blocking (returns immediately), osWaitForever for infinite blocking
00044   virtual int read(uint8_t* buf, size_t* pLength, size_t maxLength, uint32_t timeout=osWaitForever);
00045   virtual size_t available();
00046   virtual int waitAvailable(uint32_t timeout=osWaitForever); //Wait for data to be available
00047   virtual int abortRead(); //Abort current reading (or waiting) operation
00048 
00049 
00050   //0 for non-blocking (returns immediately), osWaitForever for infinite blocking
00051   virtual int write(uint8_t* buf, size_t length, uint32_t timeout=osWaitForever);
00052   virtual size_t space();
00053   virtual int waitSpace(uint32_t timeout=osWaitForever); //Wait for space to be available
00054   virtual int abortWrite(); //Abort current writing (or waiting) operation
00055 
00056 private:
00057   IUSBHostSerial& m_serial;
00058   volatile bool m_serialTxFifoEmpty;
00059 
00060   void setupReadableISR(bool en);
00061   virtual void readable(); //Callback from m_serial when new data is available
00062 
00063   Semaphore m_availableSphre; //Used for signalling
00064 
00065   void setupWriteableISR(bool en);
00066   virtual void writeable(); //Callback from m_serial when new space is available
00067 
00068   Semaphore m_spaceSphre; //Used for signalling
00069 
00070   MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_inBuf;
00071   MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_outBuf;
00072 };
00073 
00074 #endif /* USBSERIALSTREAM_H_ */