Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-os by
IOSerialStream.h
00001 /* IOSerialStream.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 #ifndef IOSERIALSTREAM_H_ 00020 #define IOSERIALSTREAM_H_ 00021 00022 #include "core/fwk.h" 00023 00024 #include "RawSerial.h" 00025 00026 #include "rtos.h" 00027 #include "core/MtxCircBuffer.h" 00028 00029 /** Input Serial Stream for physical serial interfaces (UART...) 00030 This class is not thread-safe, except for the *Abort() methods that can be called by any thread/ISR 00031 */ 00032 class IOSerialStream : public IOStream 00033 { 00034 public: 00035 enum { CIRCBUF_SIZE = 255 }; 00036 IOSerialStream(mbed::RawSerial& serial); 00037 /*virtual*/ ~IOSerialStream(); 00038 00039 //0 for non-blocking (returns immediately), osWaitForever for infinite blocking 00040 virtual int read(uint8_t* buf, size_t* pLength, size_t maxLength, uint32_t timeout=osWaitForever); 00041 virtual size_t available(); 00042 virtual int waitAvailable(uint32_t timeout=osWaitForever); //Wait for data to be available 00043 virtual int abortRead(); //Abort current reading (or waiting) operation 00044 00045 00046 //0 for non-blocking (returns immediately), osWaitForever for infinite blocking 00047 virtual int write(uint8_t* buf, size_t length, uint32_t timeout=osWaitForever); 00048 virtual size_t space(); 00049 virtual int waitSpace(uint32_t timeout=osWaitForever); //Wait for space to be available 00050 virtual int abortWrite(); //Abort current writing (or waiting) operation 00051 00052 private: 00053 00054 mbed::RawSerial& m_serial; 00055 volatile bool m_serialTxFifoEmpty; 00056 00057 void setupReadableISR(bool en); 00058 void readable(); //Callback from m_serial when new data is available 00059 00060 Semaphore m_availableSphre; //Used for signalling 00061 00062 void setupWriteableISR(bool en); 00063 void writeable(); //Callback from m_serial when new space is available 00064 00065 Semaphore m_spaceSphre; //Used for signalling 00066 00067 MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_inBuf; 00068 MtxCircBuffer<uint8_t, CIRCBUF_SIZE + 1> m_outBuf; 00069 00070 }; 00071 00072 #endif /* IOSERIALSTREAM_H_ */
Generated on Tue Jul 12 2022 13:15:51 by
