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