PHS module APM-002 library. see: https://developer.mbed.org/users/phsfan/notebook/abitusbmodem/

Dependencies:   Socket lwip-sys lwip

Fork of AbitUSBModem by phs fan

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IOSerialStream.h Source File

IOSerialStream.h

00001 /* IOSerialStream.h */
00002 /* Modified by 2015 phsfan
00003  *  for ABIT SMA-01
00004  */
00005 /* Copyright (C) 2012 mbed.org, MIT License
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00008  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00009  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00010  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be included in all copies or
00014  * substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00017  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00018  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00021  */
00022 #ifndef IOSERIALSTREAM_H_
00023 #define IOSERIALSTREAM_H_
00024 
00025 #include "core/fwk.h"
00026 
00027 #include "RawSerial.h"
00028 
00029 #include "rtos.h"
00030 #include "MtxCircBuffer.h"
00031 
00032 /** Input Serial Stream for physical serial interfaces (UART...)
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 255
00036 class IOSerialStream : public IOStream
00037 {
00038 public:
00039   IOSerialStream(mbed::RawSerial& serial);
00040   /*virtual*/ ~IOSerialStream();
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 
00057   mbed::RawSerial& m_serial;
00058   volatile bool m_serialTxFifoEmpty;
00059 
00060 #if defined(TARGET_LPC176X) || defined(TARGET_LPC408X) || defined(TARGET_LPC2368)
00061     LPC_UART1_TypeDef *_uart;
00062 #elif defined(TARGET_LPC11UXX)
00063     LPC_USART_Type *_uart;
00064 #endif
00065 
00066   void setupReadableISR(bool en);
00067   void readable(); //Callback from m_serial when new data is available
00068 
00069   Semaphore m_availableSphre; //Used for signalling
00070 
00071   void setupWriteableISR(bool en);
00072   void writeable(); //Callback from m_serial when new space is available
00073 
00074   Semaphore m_spaceSphre; //Used for signalling
00075 
00076   MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_inBuf;
00077   MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_outBuf;
00078 
00079 };
00080 
00081 #endif /* IOSERIALSTREAM_H_ */